improved classes

This commit is contained in:
Luca Frosini 2021-12-02 15:43:58 +01:00
parent 41b83c7c69
commit 6da43964b5
2 changed files with 21 additions and 21 deletions

View File

@ -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;
}

View File

@ -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();
}