diff --git a/.classpath b/.classpath
index 11def0e..ceec4b7 100644
--- a/.classpath
+++ b/.classpath
@@ -27,7 +27,6 @@
-
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 4e4a3ad..cac0df4 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
diff --git a/pom.xml b/pom.xml
index 3f5c669..d383998 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,7 +61,6 @@
org.gcube.core
common-scope-maps
-
org.gcube.core
common-scope
diff --git a/src/main/java/org/gcube/common/authorizationservice/TokenManager.java b/src/main/java/org/gcube/common/authorizationservice/TokenManager.java
index 42887f8..5ab1096 100644
--- a/src/main/java/org/gcube/common/authorizationservice/TokenManager.java
+++ b/src/main/java/org/gcube/common/authorizationservice/TokenManager.java
@@ -36,6 +36,7 @@ import org.gcube.common.authorizationservice.util.Constants;
import org.gcube.common.authorizationservice.util.TokenPersistence;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.api.ServiceMap;
+import org.gcube.common.scope.impl.ScopedServiceMap;
import lombok.extern.slf4j.Slf4j;
@@ -62,8 +63,15 @@ public class TokenManager {
CalledMethodProvider.instance.set("retrieve");
log.info("token retreiver called with token {}",token);
- AuthorizationEntry info = persistence.getAuthorizationEntry(token);
+ AuthorizationEntry info = null;
+ try {
+ info = persistence.getAuthorizationEntry(token);
+ } catch ( Throwable t) {
+ log.error("erorr on authorization", t);
+ throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity("error on authorization").type(MediaType.TEXT_PLAIN).build());
+ }
log.info("info retrieved {}",info);
if (info == null){
@@ -71,21 +79,23 @@ public class TokenManager {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("token "+token+" not found").type(MediaType.TEXT_PLAIN).build());
}
-
+
try{
ScopeProvider.instance.set(info.getContext());
- ServiceMap map = ServiceMap.instance;
+ log.info("current context is {}", info.getContext());
+ ServiceMap map = ((ScopedServiceMap)ServiceMap.instance).currentMap();
+ log.info("map is {}", map);
ScopeProvider.instance.reset();
info.setMap(map);
- }catch(Exception e){
+ log.info("map set");
+ }catch(Throwable e){
log.error("error retrieving map for {}", info.getContext(), e);
}
-
log.debug("returning info {}", info);
return info;
}
-
+
/**
*
* retrieves the AuthorzationEntry connected to the specified token
@@ -104,16 +114,19 @@ public class TokenManager {
for (String token : tokens ) {
try {
AuthorizationEntry info = persistence.getAuthorizationEntry(token);
+
try{
ScopeProvider.instance.set(info.getContext());
- ServiceMap map = ServiceMap.instance;
+ ServiceMap map = ((ScopedServiceMap)ServiceMap.instance).currentMap();
ScopeProvider.instance.reset();
info.setMap(map);
- }catch(Exception e){
+ }catch(Throwable e){
log.error("error retrieving map for {}", info.getContext(), e);
}
toReturn.add(info);
- }catch(Exception e) {}
+ }catch(Exception t) {
+ log.error("erorr on authorization", t);
+ }
}
log.info("info retrieved {}",toReturn);
@@ -122,13 +135,13 @@ public class TokenManager {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("no tokens poassed have been found ").type(MediaType.TEXT_PLAIN).build());
}
-
+
return new AuthorizationEntryList(toReturn);
}
-
-
+
+
/**
*
* retrieves the AuthorzationEntry connected to the specified token
@@ -141,16 +154,16 @@ public class TokenManager {
public String getTokenByUserAndContext(@NotNull @PathParam("user") String user, @QueryParam("context") String context ) {
CalledMethodProvider.instance.set("retrieve");
log.info("resolving token for user {} in context {}",user, context);
-
+
if (context==null){
log.error("null context found");
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("null context found").type(MediaType.TEXT_PLAIN).build());
}
-
+
String token = persistence.getExistingToken(user, context, Constants.DEFAULT_TOKEN_QUALIFIER);
-
+
if (token == null){
log.error("token {} not found ", token);
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
@@ -171,7 +184,7 @@ public class TokenManager {
return token;
}
-
+
/**
*
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
@@ -206,7 +219,7 @@ public class TokenManager {
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
}
}
-
+
/**
*
* Generates a token for a user (saving the passed roles) if it doesn't exist yet.
@@ -234,8 +247,8 @@ public class TokenManager {
.entity("Error setting roles to token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
}
}
-
-
+
+
/**
*
* REmoves a token for a user.
@@ -257,14 +270,14 @@ public class TokenManager {
if (clientId.split(":").length>1) throw new Exception("invalid user id: "+clientId);
persistence.removeAllAuthorizationsEntryForClientId(context, clientId);
-
+
}catch(Exception e){
log.error("error generating token ",e);
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity("Error removing Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
}
}
-
+
/**
*
* Generates a token for a service if it doesn't exist yet.
@@ -308,25 +321,25 @@ public class TokenManager {
CalledMethodProvider.instance.set("generate");
log.info("calling generate service token bunch");
try{
-
+
AuthorizationEntry callerInfo = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
-
+
List tokensToReturn = new ArrayList();
-
+
for (String token: entity.getContainerTokens()) {
AuthorizationEntry authInfo = this.retrieveToken(token);
-
+
if (authInfo==null) continue;
-
+
if (!authInfo.getClientInfo().getId().equals(callerInfo.getClientInfo().getId()))
log.warn("a token with a different ContainerInfo of the caller used, skipping it");
else {
String genToken = generateTokenForServiceInfo(entity.getInfo(), authInfo);
tokensToReturn.add(genToken);
}
-
+
}
-
+
return new ListMapper(tokensToReturn);
}catch(Exception e){
log.error("error generating tokens ",e);
@@ -391,7 +404,7 @@ public class TokenManager {
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
}
}
-
+
@Path("node")
@PUT
@Consumes(MediaType.APPLICATION_XML)
@@ -399,16 +412,16 @@ public class TokenManager {
@Context HttpServletRequest req) {
CalledMethodProvider.instance.set("generate");
try{
-
+
AuthorizationEntry info = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
-
+
if (context!=null)
return generateTokenForContainerInfo(containerInfo, context);
else if (info!=null){
log.info("generator called for node {} in context {} ",containerInfo.getId(), info.getContext());
return generateTokenForContainerInfo(containerInfo, info);
}
-
+
throw new Exception("error trying to activate node (token and context are empty)");
}catch(Exception e){
log.error("error generating token ",e);
@@ -429,7 +442,7 @@ public class TokenManager {
}
return token;
}
-
+
private String generateTokenForContainerInfo(ContainerInfo containerInfo, AuthorizationEntry authInfo) throws Exception{
if (containerInfo.getId().split(":").length!=2) throw new Exception("invalid container id: "+containerInfo.getId());
@@ -442,7 +455,7 @@ public class TokenManager {
}
return token;
}
-
+
private String generateTokenForServiceInfo(ServiceInfo serviceInfo, AuthorizationEntry authInfo) throws Exception{
if (serviceInfo.getId().split(":").length!=3) throw new Exception("invalid service id: "+serviceInfo.getId());