Improving library

This commit is contained in:
Luca Frosini 2021-12-02 13:16:03 +01:00
parent 98669b25a3
commit 41b83c7c69
6 changed files with 47 additions and 6 deletions

View File

@ -22,11 +22,6 @@ public class ClienIDSecret extends Secret {
this.clientID = clientID;
}
@Override
public void set() throws Exception {
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, token, ScopeProvider.instance.get(), null);
}
@Override
public String getContext() throws Exception {
return null;
@ -70,9 +65,16 @@ public class ClienIDSecret extends Secret {
@Override
public void setToken() throws Exception {
// TODO
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, token, ScopeProvider.instance.get(), null);
logger.trace("{}", tr);
}
@Override
public void resetToken() throws Exception {
// TODO Auto-generated method stub
}
@Override
public ClientInfo getClientInfo() throws Exception {
// TODO Auto-generated method stub
@ -84,4 +86,5 @@ public class ClienIDSecret extends Secret {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -64,5 +64,15 @@ public class SecretHolder {
}
return ScopeProvider.instance.get();
}
public void reset() {
for(Secret secret : secrets) {
try {
secret.reset();
}catch (Exception e) {
// trying the next one
}
}
}
}

View File

@ -16,6 +16,8 @@ public class SecretManager {
public static final InheritableThreadLocal<SecretManager> instance = new InheritableThreadLocal<SecretManager>() {
@Override
protected SecretManager initialValue() {
return new SecretManager();
@ -108,4 +110,11 @@ public class SecretManager {
return currentSecretHolder.getContext();
}
public void reset() {
initialSecretHolder.reset();
if(initialSecretHolder!=currentSecretHolder) {
currentSecretHolder.reset();
}
instance.remove();
}
}

View File

@ -39,10 +39,16 @@ public class GCubeSecret extends Secret {
return authorizationEntry;
}
@Override
public void setToken() throws Exception {
SecurityTokenProvider.instance.set(token);
}
@Override
public void resetToken() throws Exception {
SecurityTokenProvider.instance.reset();
}
@Override
public ClientInfo getClientInfo() throws Exception {
return getAuthorizationEntry().getClientInfo();

View File

@ -32,6 +32,11 @@ public class JWTSecret extends Secret {
AccessTokenProvider.instance.set(token);
}
@Override
public void resetToken() throws Exception {
AccessTokenProvider.instance.reset();
}
protected JWToken getJWToken() throws Exception {
if(jwt==null) {
String realUmaTokenEncoded = token.split("\\.")[1];

View File

@ -52,6 +52,8 @@ public abstract class Secret implements Comparable<Secret> {
public abstract void setToken() throws Exception;
public abstract void resetToken() throws Exception;
public abstract ClientInfo getClientInfo() throws Exception;
public abstract Caller getCaller() throws Exception;
@ -104,6 +106,12 @@ public abstract class Secret implements Comparable<Secret> {
return token.compareTo(obj.token);
}
public void reset() throws Exception {
resetToken();
AuthorizationProvider.instance.reset();
ScopeProvider.instance.reset();
}