2015-05-18 19:15:11 +02:00
|
|
|
package org.gcube.common.authorization.library.provider;
|
|
|
|
|
2015-05-29 18:32:49 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2015-05-18 19:15:11 +02:00
|
|
|
public class AuthorizationProvider {
|
|
|
|
|
|
|
|
public static AuthorizationProvider instance = new AuthorizationProvider();
|
|
|
|
|
2015-05-29 18:32:49 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(AuthorizationProvider.class);
|
|
|
|
|
2015-05-18 19:15:11 +02:00
|
|
|
// Thread local variable containing each thread's ID
|
2015-11-24 19:26:46 +01:00
|
|
|
private static final InheritableThreadLocal<ClientInfo> threadAuth =
|
|
|
|
new InheritableThreadLocal<ClientInfo>() {
|
2015-05-18 19:15:11 +02:00
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
@Override protected ClientInfo initialValue() {
|
2015-05-18 19:15:11 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private AuthorizationProvider(){}
|
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
public ClientInfo get(){
|
|
|
|
ClientInfo info = threadAuth.get();
|
2015-07-13 12:56:31 +02:00
|
|
|
logger.trace("getting "+info+" in thread "+Thread.currentThread().getId() );
|
2015-05-29 18:32:49 +02:00
|
|
|
return info;
|
2015-05-18 19:15:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
public void set(ClientInfo authorizationToken){
|
2015-05-18 19:15:11 +02:00
|
|
|
threadAuth.set(authorizationToken);
|
2015-07-13 12:56:31 +02:00
|
|
|
logger.trace("setting "+authorizationToken+" in thread "+Thread.currentThread().getId() );
|
2015-05-29 18:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void reset(){
|
|
|
|
threadAuth.remove();
|
2015-05-18 19:15:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|