mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
change using syncronizedMap.
This commit is contained in:
parent
9b2c1c98db
commit
26433f2945
2 changed files with 12 additions and 22 deletions
|
|
@ -24,6 +24,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ public class Credentials {
|
|||
if (credentialsPath != null) {
|
||||
credentialsFile = new File(credentialsPath);
|
||||
}
|
||||
credentialsMap = new HashMap<>();
|
||||
credentialsMap = Collections.synchronizedMap(new HashMap<String, UserCredentials>());
|
||||
if (credentialsPersist) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.setPrettyPrinting();
|
||||
|
|
@ -61,17 +62,13 @@ public class Credentials {
|
|||
}
|
||||
|
||||
public void putUserCredentials(String username, UserCredentials uc) throws IOException {
|
||||
synchronized (credentialsMap) {
|
||||
credentialsMap.put(username, uc);
|
||||
}
|
||||
credentialsMap.put(username, uc);
|
||||
saveCredentials();
|
||||
}
|
||||
|
||||
public UserCredentials removeUserCredentials(String username) throws IOException {
|
||||
UserCredentials uc;
|
||||
synchronized (credentialsMap) {
|
||||
uc = credentialsMap.remove(username);
|
||||
}
|
||||
uc = credentialsMap.remove(username);
|
||||
saveCredentials();
|
||||
return uc;
|
||||
}
|
||||
|
|
@ -124,11 +121,9 @@ public class Credentials {
|
|||
private void saveToFile() throws IOException {
|
||||
String jsonString;
|
||||
|
||||
synchronized (credentialsMap) {
|
||||
CredentialsInfoSaving info = new CredentialsInfoSaving();
|
||||
info.credentialsMap = credentialsMap;
|
||||
jsonString = gson.toJson(info);
|
||||
}
|
||||
CredentialsInfoSaving info = new CredentialsInfoSaving();
|
||||
info.credentialsMap = credentialsMap;
|
||||
jsonString = gson.toJson(info);
|
||||
|
||||
try {
|
||||
if (!credentialsFile.exists()) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.zeppelin.user;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ public class UserCredentials {
|
|||
private Map<String, UsernamePassword> userCredentials;
|
||||
|
||||
public UserCredentials() {
|
||||
this.userCredentials = new HashMap<>();
|
||||
userCredentials = Collections.synchronizedMap(new HashMap<String, UsernamePassword>());
|
||||
}
|
||||
|
||||
public UsernamePassword getUsernamePassword(String entity) {
|
||||
|
|
@ -35,21 +36,15 @@ public class UserCredentials {
|
|||
}
|
||||
|
||||
public void putUsernamePassword(String entity, UsernamePassword up) {
|
||||
synchronized (userCredentials) {
|
||||
userCredentials.put(entity, up);
|
||||
}
|
||||
userCredentials.put(entity, up);
|
||||
}
|
||||
|
||||
public void removeUsernamePassword(String entity) {
|
||||
synchronized (userCredentials) {
|
||||
userCredentials.remove(entity);
|
||||
}
|
||||
userCredentials.remove(entity);
|
||||
}
|
||||
|
||||
public boolean existUsernamePassword(String entity) {
|
||||
synchronized (userCredentials) {
|
||||
return userCredentials.containsKey(entity);
|
||||
}
|
||||
return userCredentials.containsKey(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue