removed all providers

This commit is contained in:
Lucio Lelii 2022-05-30 18:55:04 +02:00
parent e68d49fc64
commit d3e0062060
6 changed files with 1 additions and 235 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<version>2.5.0</version>
<version>3.0.0-SNAPSHOT</version>
<name>authorization service common library</name>
<parent>

View File

@ -1,96 +0,0 @@
package org.gcube.common.authorization.library;
import java.util.concurrent.Callable;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AuthorizedTasks {
private static Logger logger= LoggerFactory.getLogger(AuthorizedTasks.class);
/**
* Binds a {@link Callable} task to the current scope and user.
* @param task the task
* @return an equivalent {@link Callable} task bound to the current scope and user
*/
static public <V> Callable<V> bind(final Callable<V> task) {
final Caller userCall = AuthorizationProvider.instance.get();
final String token = SecurityTokenProvider.instance.get();
final String scope = ScopeProvider.instance.get();
final String accessToken = AccessTokenProvider.instance.get();
return new Callable<V>() {
@Override
public V call() throws Exception {
AuthorizationProvider.instance.set(userCall);
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(scope);
AccessTokenProvider.instance.set(accessToken);
try {
logger.info("setting on authorized task scope {} and token {}", scope, token);
return task.call();
}
finally {
AuthorizationProvider.instance.reset();
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
}
};
}
/**
* Binds a {@link Runnable} task to the current scope and user.
* @param task the task
* @return an equivalent {@link Runnable} task bound to the current scope and user
*/
static public <V> Runnable bind(final Runnable task) {
final Caller userCall = AuthorizationProvider.instance.get();
final String token = SecurityTokenProvider.instance.get();
final String scope = ScopeProvider.instance.get();
final String accessToken = AccessTokenProvider.instance.get();
return new Runnable() {
@Override
public void run() {
AuthorizationProvider.instance.set(userCall);
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(scope);
AccessTokenProvider.instance.set(accessToken);
try {
logger.info("setting on authorized task scope {} and token {}", scope, token);
task.run();
}
finally {
AuthorizationProvider.instance.reset();
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
}
};
}
}

View File

@ -1,31 +0,0 @@
package org.gcube.common.authorization.library.provider;
@Deprecated
public class AccessTokenProvider {
public static AccessTokenProvider instance = new AccessTokenProvider();
private static final InheritableThreadLocal<String> threadToken = new InheritableThreadLocal<String>() {
@Override
protected String initialValue() {
return null;
}
};
private AccessTokenProvider() {
}
public String get() {
return threadToken.get();
}
public void set(String jwt) {
threadToken.set(jwt);
}
public void reset() {
threadToken.remove();
}
}

View File

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

View File

@ -1,39 +0,0 @@
package org.gcube.common.authorization.library.provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CalledMethodProvider {
public static CalledMethodProvider instance = new CalledMethodProvider();
private static Logger logger = LoggerFactory.getLogger(CalledMethodProvider.class);
// Thread local variable containing each thread's ID
private static final InheritableThreadLocal<String> threadMethod =
new InheritableThreadLocal<String>() {
@Override protected String initialValue() {
return "UNKNOWN";
}
};
private CalledMethodProvider(){}
public String get(){
String calledMethod = threadMethod.get();
logger.trace("getting calledMethod as "+calledMethod+" in thread "+Thread.currentThread().getId() );
return calledMethod;
}
public void set(String calledMethod){
if (calledMethod==null) return;
threadMethod.set(calledMethod);
logger.trace("setting calledMethod as "+calledMethod+" in thread "+Thread.currentThread().getId() );
}
public void reset(){
threadMethod.remove();
}
}

View File

@ -1,33 +0,0 @@
package org.gcube.common.authorization.library.provider;
@Deprecated
public class SecurityTokenProvider {
public static SecurityTokenProvider instance = new SecurityTokenProvider();
//private static Logger logger = LoggerFactory.getLogger(SecurityTokenProvider.class);
// Thread local variable containing each thread's ID
private static final InheritableThreadLocal<String> threadToken =
new InheritableThreadLocal<String>() {
@Override protected String initialValue() {
return null;
}
};
private SecurityTokenProvider(){}
public String get(){
return threadToken.get();
}
public void set(String authorizationToken){
threadToken.set(authorizationToken);
}
public void reset(){
threadToken.remove();
}
}