Changed the way to retrieve current context. Token has now priority
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@133848 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
58dfb2cdda
commit
b1d39fd0cc
|
@ -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();
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<logger name="org.gcube" level="INFO" />
|
||||
<logger name="org.gcube.informationsystem" level="INFO" />
|
||||
<logger name="org.gcube.informationsystem.resourceregistry.context" level="TRACE" />
|
||||
<logger name="org.gcube.informationsystem.resourceregistry.resources.utils" level="TRACE" />
|
||||
<logger name="org.gcube.informationsystem.impl.utils.discovery" level="ERROR" />
|
||||
|
||||
<root level="WARN">
|
||||
|
|
Loading…
Reference in New Issue