2022-02-25 18:08:51 +01:00
|
|
|
package org.gcube.common.authorization.utils.manager;
|
|
|
|
|
2022-02-28 18:04:49 +01:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2022-02-25 18:08:51 +01:00
|
|
|
public class SecretManagerProvider {
|
|
|
|
|
|
|
|
public static SecretManagerProvider instance = new SecretManagerProvider();
|
|
|
|
|
|
|
|
// Thread local variable containing each thread's ID
|
|
|
|
private static final InheritableThreadLocal<SecretManager> thread = new InheritableThreadLocal<SecretManager>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SecretManager initialValue() {
|
2022-02-28 17:07:46 +01:00
|
|
|
return null;
|
2022-02-25 18:08:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private SecretManagerProvider(){}
|
|
|
|
|
|
|
|
public SecretManager get(){
|
|
|
|
SecretManager secretManager = thread.get();
|
|
|
|
return secretManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set(SecretManager secretManager){
|
|
|
|
thread.set(secretManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset(){
|
|
|
|
SecretManager secretManager = thread.get();
|
2022-03-01 11:36:00 +01:00
|
|
|
if(secretManager!=null) {
|
|
|
|
secretManager.reset();
|
|
|
|
}
|
2022-02-25 18:08:51 +01:00
|
|
|
thread.remove();
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:12:27 +01:00
|
|
|
public void remove(){
|
|
|
|
thread.remove();
|
|
|
|
}
|
2022-02-25 18:08:51 +01:00
|
|
|
}
|