git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@144376 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
58c25be50f
commit
5aa5300cc0
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<name>authorization service common library</name>
|
||||
|
||||
<parent>
|
||||
|
|
|
@ -5,10 +5,15 @@ import java.util.concurrent.Callable;
|
|||
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
|
||||
|
@ -21,18 +26,24 @@ public class AuthorizedTasks {
|
|||
|
||||
final String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
final String scope = ScopeProvider.instance.get();
|
||||
|
||||
return new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
|
||||
AuthorizationProvider.instance.set(userCall);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,17 +62,22 @@ public class AuthorizedTasks {
|
|||
|
||||
final String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
final String scope = ScopeProvider.instance.get();
|
||||
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AuthorizationProvider.instance.set(userCall);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
try {
|
||||
logger.info("setting on authorized task scope {} and token {}", scope, token);
|
||||
task.run();
|
||||
}
|
||||
finally {
|
||||
AuthorizationProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue