51
51
*/
52
52
public abstract class CredentialsProvider extends EnvironmentProvider {
53
53
54
- private static final String PROPERTY_USERNAME = "prop_credentials_username " ; // NOI18N
55
- private static final String PROPERTY_PASSWORD = "prop_credentials_password " ; // NOI18N
54
+ private static final String PROPERTY_USER = "prop_credentials_user " ; // NOI18N
55
+ private static final String PROPERTY_PWORD = "prop_credentials_pword " ; // NOI18N
56
56
57
57
private static Persistent PERSISTENT_PROVIDER ;
58
58
@@ -90,8 +90,8 @@ public String getId() {
90
90
*/
91
91
public static class Custom extends CredentialsProvider {
92
92
93
- private final String username ;
94
- private final char [] password ;
93
+ private final String user ;
94
+ private final char [] pword ;
95
95
private final boolean persistent ;
96
96
97
97
@@ -103,32 +103,32 @@ public static class Custom extends CredentialsProvider {
103
103
* @param persistent true if the credentials should be persisted for another VisualVM sessions, false otherwise
104
104
*/
105
105
public Custom (String username , char [] password , boolean persistent ) {
106
- this .username = username ;
107
- this .password = encodePassword (password );
106
+ this .user = username ;
107
+ this .pword = encodePassword (password );
108
108
this .persistent = persistent ;
109
109
}
110
110
111
111
112
112
public Map <String , ?> getEnvironment (Application application , Storage storage ) {
113
- return createMap (username , password != null ? new String ( password ) : null );
113
+ return createMap (user , pword );
114
114
}
115
115
116
116
public String getEnvironmentId (Storage storage ) {
117
- if (username != null ) return username ;
117
+ if (user != null ) return user ;
118
118
return super .getEnvironmentId (storage );
119
119
}
120
120
121
121
public void saveEnvironment (Storage storage ) {
122
122
if (!persistent ) return ;
123
- storage .setCustomProperty (PROPERTY_USERNAME , username );
124
- storage .setCustomProperty (PROPERTY_PASSWORD , new String (password ));
123
+ storage .setCustomProperty (PROPERTY_USER , user );
124
+ storage .setCustomProperty (PROPERTY_PWORD , new String (pword ));
125
125
}
126
126
127
127
128
- String getUsername (Storage storage ) { return username ; }
128
+ String getUsername (Storage storage ) { return user ; }
129
129
130
- boolean hasPassword (Storage storage ) { return password != null &&
131
- password .length > 0 ; }
130
+ boolean hasPassword (Storage storage ) { return pword != null &&
131
+ pword .length > 0 ; }
132
132
133
133
boolean isPersistent (Storage storage ) { return persistent ; }
134
134
@@ -144,26 +144,26 @@ boolean hasPassword(Storage storage) { return password != null &&
144
144
public static class Persistent extends CredentialsProvider {
145
145
146
146
public Map <String , ?> getEnvironment (Application application , Storage storage ) {
147
- String username = storage .getCustomProperty (PROPERTY_USERNAME );
148
- String password = storage .getCustomProperty (PROPERTY_PASSWORD );
149
- return createMap (username , password );
147
+ String user = storage .getCustomProperty (PROPERTY_USER );
148
+ char [] pword = storage .getCustomProperty (PROPERTY_PWORD ). toCharArray ( );
149
+ return createMap (user , pword );
150
150
}
151
151
152
152
public String getEnvironmentId (Storage storage ) {
153
153
if (storage != null ) {
154
- String username = storage .getCustomProperty (PROPERTY_USERNAME );
155
- if (username != null ) return username ;
154
+ String user = storage .getCustomProperty (PROPERTY_USER );
155
+ if (user != null ) return user ;
156
156
}
157
157
return super .getEnvironmentId (storage );
158
158
}
159
159
160
160
161
161
String getUsername (Storage storage ) { return storage .getCustomProperty (
162
- PROPERTY_USERNAME ); }
162
+ PROPERTY_USER ); }
163
163
164
164
boolean hasPassword (Storage storage ) {
165
- String password = storage .getCustomProperty (PROPERTY_PASSWORD );
166
- return password != null && password .length () > 0 ;
165
+ String pword = storage .getCustomProperty (PROPERTY_PWORD );
166
+ return pword != null && pword .length () > 0 ;
167
167
}
168
168
169
169
boolean isPersistent (Storage storage ) {
@@ -175,24 +175,21 @@ boolean isPersistent(Storage storage) {
175
175
176
176
// --- Private implementation ----------------------------------------------
177
177
178
- private static Map <String , ?> createMap (String username , String password ) {
178
+ private static Map <String , ?> createMap (String username , char [] pword ) {
179
179
Map map = new HashMap ();
180
180
181
181
if (username != null && !username .isEmpty ())
182
- map .put (JMXConnector .CREDENTIALS ,
183
- new String [] { username , decodePassword (password ) });
182
+ map .put (JMXConnector .CREDENTIALS , new String [] { username , new String (decodePassword (pword )) });
184
183
185
184
return map ;
186
185
}
187
186
188
- private static char [] encodePassword (char [] password ) {
189
- if (password == null ) return null ;
190
- return Utils .encodePassword (new String (password )).toCharArray ();
187
+ private static char [] encodePassword (char [] pword ) {
188
+ return pword == null ? null : Utils .encodePassword (pword );
191
189
}
192
190
193
- private static String decodePassword (String password ) {
194
- if (password == null ) return null ;
195
- return Utils .decodePassword (password );
191
+ private static char [] decodePassword (char [] pword ) {
192
+ return pword == null ? null : Utils .decodePassword (pword );
196
193
}
197
194
198
195
}
0 commit comments