diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/utils/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/utils/ContextUtility.java index c91325c..2b90367 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/resources/utils/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/resources/utils/ContextUtility.java @@ -6,6 +6,9 @@ package org.gcube.informationsystem.resourceregistry.resources.utils; import java.util.Iterator; import java.util.UUID; +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.informationsystem.model.entity.Context; @@ -68,10 +71,25 @@ public class ContextUtility { .field(org.gcube.informationsystem.model.embedded.Header.UUID_PROPERTY); return UUID.fromString(contextID); } + + private static String getCurrentScope(){ + String token = SecurityTokenProvider.instance.get(); + AuthorizationEntry authorizationEntry = null; + try { + authorizationEntry = Constants.authorizationService().get(token); + } catch (Exception e) { + return ScopeProvider.instance.get(); + } + return authorizationEntry.getContext(); + } public static UUID getActualContextUUID() throws ContextException { try { - String scope = ScopeProvider.instance.get(); + String scope = getCurrentScope(); + if(scope==null){ + throw new ContextException("Null Token and Scope. Please set your token first."); + } + logger.trace("Trying to get context UUID for scope {}", scope); OrientGraphFactory factory = SecurityContextMapper .getSecurityContextFactory( SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, @@ -79,9 +97,11 @@ public class ContextUtility { Vertex context = ContextUtility.getContextVertexByFullName( factory.getTx(), scope); return getContextUUIDFromContextVertex(context); + } catch (ContextException e) { + throw e; } catch (Exception e) { throw new ContextException( - "Unable to restrive Context UUID from current Context"); + "Unable to restrive Context UUID from current Context", e); } } @@ -145,6 +165,8 @@ public class ContextUtility { public static Vertex getContextVertexByFullName(OrientGraph orientGraph, String fullName) throws ContextNotFoundException { + logger.trace("Going to get {} {} from full name '{}'", Context.NAME, Vertex.class.getSimpleName(), fullName); + ScopeBean scopeBean = new ScopeBean(fullName); String name = scopeBean.name(); diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 19999fd..b630562 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -12,6 +12,7 @@ +