Skip to content

Commit 1ac5031

Browse files
committed
Fixed JMX CredentialsProvider
1 parent 4a43812 commit 1ac5031

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package org.graalvm.visualvm.jmx;
2727

28+
import java.util.Arrays;
2829
import org.graalvm.visualvm.application.Application;
2930
import org.graalvm.visualvm.core.datasource.Storage;
3031
import org.graalvm.visualvm.core.datasupport.Utils;
@@ -110,7 +111,7 @@ public Custom(String username, char[] password, boolean persistent) {
110111

111112

112113
public Map<String, ?> getEnvironment(Application application, Storage storage) {
113-
return createMap(user, pword);
114+
return createMap(user, pword == null ? null : Arrays.copyOf(pword, pword.length));
114115
}
115116

116117
public String getEnvironmentId(Storage storage) {
@@ -145,7 +146,8 @@ public static class Persistent extends CredentialsProvider {
145146

146147
public Map<String, ?> getEnvironment(Application application, Storage storage) {
147148
String user = storage.getCustomProperty(PROPERTY_USER);
148-
char[] pword = storage.getCustomProperty(PROPERTY_PWORD).toCharArray();
149+
char[] pword = storage.getCustomProperty(PROPERTY_PWORD) == null ?
150+
null : storage.getCustomProperty(PROPERTY_PWORD).toCharArray();
149151
return createMap(user, pword);
150152
}
151153

@@ -162,8 +164,8 @@ String getUsername(Storage storage) { return storage.getCustomProperty(
162164
PROPERTY_USER); }
163165

164166
boolean hasPassword(Storage storage) {
165-
String pword = storage.getCustomProperty(PROPERTY_PWORD);
166-
return pword != null && pword.length() > 0;
167+
if (storage.getCustomProperty(PROPERTY_PWORD) == null) return false;
168+
return storage.getCustomProperty(PROPERTY_PWORD).length() > 0;
167169
}
168170

169171
boolean isPersistent(Storage storage) {
@@ -175,19 +177,25 @@ boolean isPersistent(Storage storage) {
175177

176178
// --- Private implementation ----------------------------------------------
177179

180+
// NOTE: clears the pword parameter!
178181
private static Map<String, ?> createMap(String username, char[] pword) {
179182
Map map = new HashMap();
180183

181-
if (username != null && !username.isEmpty())
182-
map.put(JMXConnector.CREDENTIALS, new String[] { username, new String(decodePassword(pword)) });
184+
if (username != null && !username.isEmpty()) {
185+
map.put(JMXConnector.CREDENTIALS, new String[] { username, pword == null ? null : new String(decodePassword(pword)) });
186+
} else {
187+
if (pword != null) Arrays.fill(pword, (char)0);
188+
}
183189

184190
return map;
185191
}
186192

193+
// NOTE: clears the pword parameter!
187194
private static char[] encodePassword(char[] pword) {
188195
return pword == null ? null : Utils.encodePassword(pword);
189196
}
190197

198+
// NOTE: clears the pword parameter!
191199
private static char[] decodePassword(char[] pword) {
192200
return pword == null ? null : Utils.decodePassword(pword);
193201
}

0 commit comments

Comments
 (0)