41 lines
1.0 KiB
Java
41 lines
1.0 KiB
Java
package org.gcube.common.authorization.library.provider;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
public class AuthorizationProvider {
|
|
|
|
public static AuthorizationProvider instance = new AuthorizationProvider();
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AuthorizationProvider.class);
|
|
|
|
// Thread local variable containing each thread's ID
|
|
private static final InheritableThreadLocal<ClientInfo> threadAuth =
|
|
new InheritableThreadLocal<ClientInfo>() {
|
|
|
|
@Override protected ClientInfo initialValue() {
|
|
return null;
|
|
}
|
|
|
|
};
|
|
|
|
private AuthorizationProvider(){}
|
|
|
|
public ClientInfo get(){
|
|
ClientInfo info = threadAuth.get();
|
|
logger.trace("getting "+info+" in thread "+Thread.currentThread().getId() );
|
|
return info;
|
|
}
|
|
|
|
public void set(ClientInfo authorizationToken){
|
|
threadAuth.set(authorizationToken);
|
|
logger.trace("setting "+authorizationToken+" in thread "+Thread.currentThread().getId() );
|
|
}
|
|
|
|
public void reset(){
|
|
threadAuth.remove();
|
|
}
|
|
|
|
}
|