improved classes
This commit is contained in:
parent
41b83c7c69
commit
6da43964b5
|
@ -39,6 +39,24 @@ public class SecretHolder {
|
|||
}
|
||||
}
|
||||
|
||||
public void set() throws Exception {
|
||||
boolean first = true;
|
||||
for(Secret secret : secrets) {
|
||||
/*
|
||||
* Only the most important Secret must set
|
||||
* AuthorizationProvider and ScopeProvider
|
||||
* the others just need to set their token
|
||||
* in the correspondent provider
|
||||
*/
|
||||
if(first) {
|
||||
secret.set();
|
||||
first = false;
|
||||
}else {
|
||||
secret.setToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SortedSet<Secret> getSecrets() {
|
||||
return secrets;
|
||||
}
|
||||
|
|
|
@ -69,39 +69,21 @@ public class SecretManager {
|
|||
throw new Exception("You are already in a session. You must terminate the session first.");
|
||||
}
|
||||
currentSecretHolder = new SecretHolder(secret);
|
||||
secret.set();
|
||||
currentSecretHolder.set();
|
||||
}
|
||||
|
||||
public synchronized void startSession(SortedSet<Secret> secrets) throws Exception {
|
||||
currentSecretHolder = new SecretHolder(secrets);
|
||||
setAll(secrets);
|
||||
currentSecretHolder.set();
|
||||
}
|
||||
|
||||
public synchronized void endSession() throws Exception {
|
||||
if(currentSecretHolder!=initialSecretHolder) {
|
||||
setAll(initialSecretHolder.getSecrets());
|
||||
initialSecretHolder.set();
|
||||
currentSecretHolder = initialSecretHolder;
|
||||
}
|
||||
}
|
||||
|
||||
private void setAll(SortedSet<Secret> secrets) throws Exception {
|
||||
boolean first = true;
|
||||
for(Secret secret : secrets) {
|
||||
/*
|
||||
* Only the most important Secret must set
|
||||
* AuthorizationProvider and ScopeProvider
|
||||
* the others just need to set their token
|
||||
* in the correspondent provider
|
||||
*/
|
||||
if(first) {
|
||||
secret.set();
|
||||
first = false;
|
||||
}else {
|
||||
secret.setToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return currentSecretHolder.getUsername();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue