Lucio Lelii 2016-09-08 10:54:49 +00:00
parent 39089fb2ae
commit e97e7585c3
3 changed files with 36 additions and 9 deletions

View File

@ -3,8 +3,8 @@ package org.gcube.common.authorization.library;
import java.util.concurrent.Callable;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
public class AuthorizedTasks {
@ -17,7 +17,7 @@ public class AuthorizedTasks {
static public <V> Callable<V> bind(final Callable<V> task) {
final ClientInfo userCall = AuthorizationProvider.instance.get();
final Caller userCall = AuthorizationProvider.instance.get();
final String token = SecurityTokenProvider.instance.get();
@ -47,7 +47,7 @@ public class AuthorizedTasks {
static public <V> Runnable bind(final Runnable task) {
final ClientInfo userCall = AuthorizationProvider.instance.get();
final Caller userCall = AuthorizationProvider.instance.get();
final String token = SecurityTokenProvider.instance.get();

View File

@ -1,14 +1,16 @@
package org.gcube.common.authorization.library.provider;
import org.gcube.common.authorization.library.utils.Caller;
public class AuthorizationProvider {
public static AuthorizationProvider instance = new AuthorizationProvider();
// Thread local variable containing each thread's ID
private static final InheritableThreadLocal<ClientInfo> threadAuth =
new InheritableThreadLocal<ClientInfo>() {
private static final InheritableThreadLocal<Caller> threadAuth =
new InheritableThreadLocal<Caller>() {
@Override protected UserInfo initialValue() {
@Override protected Caller initialValue() {
return null;
}
@ -16,12 +18,12 @@ public class AuthorizationProvider {
private AuthorizationProvider(){}
public ClientInfo get(){
ClientInfo info = threadAuth.get();
public Caller get(){
Caller info = threadAuth.get();
return info;
}
public void set(ClientInfo info){
public void set(Caller info){
threadAuth.set(info);
}

View File

@ -0,0 +1,25 @@
package org.gcube.common.authorization.library.utils;
import org.gcube.common.authorization.library.provider.ClientInfo;
public class Caller {
private ClientInfo client;
private String qualifier;
public Caller(ClientInfo client, String qualifier) {
super();
this.client = client;
this.qualifier = qualifier;
}
public ClientInfo getClient() {
return client;
}
public String getTokenQualifier() {
return qualifier;
}
}