diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java index 8983a78..07e91b2 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java @@ -13,9 +13,10 @@ import org.gcube.informationsystem.contexts.reference.relations.IsParentOf; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException; -import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.AdminEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.InstanceEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility; @@ -36,7 +37,7 @@ public class ContextUtility { private static final Logger logger = LoggerFactory.getLogger(ContextUtility.class); - private Map contexts; + private Map contexts; private static ContextUtility contextUtility; @@ -55,12 +56,12 @@ public class ContextUtility { return SecretManagerProvider.instance.get().getContext(); } - public static SecurityContext getCurrentSecurityContext() throws ResourceRegistryException { + public static SystemEnvironment getCurrentRequestEnvironment() throws ResourceRegistryException { String fullName = getCurrentContextFullName(); if(fullName == null) { throw new ContextException("Null Token and Scope. Please set your token first."); } - return ContextUtility.getInstance().getSecurityContextByFullName(fullName); + return ContextUtility.getInstance().getRequestEnvironmentByContextFullName(fullName); } public static String getCurrentUserUsername() { @@ -68,26 +69,26 @@ public class ContextUtility { return sm.getUser().getUsername(); } - public static AdminSecurityContext getAdminSecurityContext() throws ResourceRegistryException { - AdminSecurityContext adminSecurityContext = AdminSecurityContext.getInstance(); + public static AdminEnvironment getAdminSecurityContext() throws ResourceRegistryException { + AdminEnvironment adminSecurityContext = AdminEnvironment.getInstance(); return adminSecurityContext; } - public synchronized void addSecurityContext(SecurityContext securityContext) { + public synchronized void addSecurityContext(InstanceEnvironment securityContext) { contexts.put(securityContext.getUUID(), securityContext); } - public synchronized void addSecurityContext(String fullname, SecurityContext securityContext) { + public synchronized void addSecurityContext(String fullname, InstanceEnvironment securityContext) { contexts.put(securityContext.getUUID(), securityContext); } - public synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException { + public synchronized InstanceEnvironment getRequestEnvironmentByContextFullName(String fullName) throws ContextException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - SecurityContext securityContext = null; + InstanceEnvironment securityContext = null; - logger.trace("Trying to get {} for {}", SecurityContext.class.getSimpleName(), fullName); + logger.trace("Trying to get {} for {}", SystemEnvironment.class.getSimpleName(), fullName); UUID uuid = ServerContextCache.getInstance().getUUIDByFullName(fullName); if(uuid != null) { @@ -95,7 +96,7 @@ public class ContextUtility { } if(securityContext==null) { - logger.trace("{} for {} is not in cache. Going to get it", SecurityContext.class.getSimpleName(), + logger.trace("{} for {} is not in cache. Going to get it", SystemEnvironment.class.getSimpleName(), fullName); oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER); @@ -103,7 +104,7 @@ public class ContextUtility { uuid = UUIDUtility.getUUID(contextVertex); - securityContext = getSecurityContextByUUID(uuid, contextVertex); + securityContext = getEnvironmentByUUID(uuid, contextVertex); addSecurityContext(fullName, securityContext); @@ -126,8 +127,8 @@ public class ContextUtility { } } - public SecurityContext getSecurityContextByUUID(UUID uuid) throws ResourceRegistryException { - return getSecurityContextByUUID(uuid, null); + public InstanceEnvironment getEnvironmentByUUID(UUID uuid) throws ResourceRegistryException { + return getEnvironmentByUUID(uuid, null); } public static ODatabaseDocument getCurrentODatabaseDocumentFromThreadLocal() { @@ -140,24 +141,24 @@ public class ContextUtility { return current; } - private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException { - ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); - ODatabaseDocument oDatabaseDocument = null; - try { - oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER); - OVertex oVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid, - OVertex.class); - return oVertex; - } finally { - if(oDatabaseDocument!=null) { - oDatabaseDocument.close(); - } - - if(current!=null) { - current.activateOnCurrentThread(); - } - } - } +// private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException { +// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); +// ODatabaseDocument oDatabaseDocument = null; +// try { +// oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER); +// OVertex oVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid, +// OVertex.class); +// return oVertex; +// } finally { +// if(oDatabaseDocument!=null) { +// oDatabaseDocument.close(); +// } +// +// if(current!=null) { +// current.activateOnCurrentThread(); +// } +// } +// } // private OVertex getParentOfContextVertexByUUID(UUID uuid) throws ResourceRegistryException { // ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); @@ -179,11 +180,11 @@ public class ContextUtility { // } - private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException { - SecurityContext securityContext = contexts.get(uuid); + private InstanceEnvironment getEnvironmentByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException { + InstanceEnvironment securityContext = contexts.get(uuid); if(securityContext == null) { - securityContext = new SecurityContext(uuid); + securityContext = new InstanceEnvironment(uuid); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; @@ -198,7 +199,7 @@ public class ContextUtility { if(parentVertex != null) { UUID parentUUID = UUIDUtility.getUUID(parentVertex); - securityContext.setParentSecurityContext(getSecurityContextByUUID(parentUUID, parentVertex)); + securityContext.setParentSecurityContext(getEnvironmentByUUID(parentUUID, parentVertex)); } } catch(NoSuchElementException e) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java index 88fb42d..a5e1101 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import javax.ws.rs.BadRequestException; import javax.ws.rs.ForbiddenException; import javax.ws.rs.NotAuthorizedException; @@ -35,9 +34,11 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaV import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ServerContextCache; import org.gcube.informationsystem.resourceregistry.contexts.relations.IsParentOfManagement; -import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.ContextEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.InstanceEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; +import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.queries.operators.ComparisonOperator; import org.gcube.informationsystem.resourceregistry.queries.operators.LogicalOperator; import org.gcube.informationsystem.resourceregistry.requests.RequestUtility; @@ -94,7 +95,7 @@ public class ContextManagement extends EntityElementManagement allowedRoles = SecurityContext.getAllowedRoles(); - if(!SecurityContext.isUserAllowed(allowedRoles)) { - throw new NotAuthorizedException("Only user with one of the following role " + allowedRoles + " can create a child Context."); + if(requestEnvironment.getUUID().compareTo(parentContextManagement.getUUID())==0) { + Set allowedRoles = requestEnvironment.getAllowedRoles(); + if(!parentInstanceEnvironment.isUserAllowed(allowedRoles)) { + throw new NotAuthorizedException("Only user with one of the following roles " + allowedRoles + " can create a child Context."); } }else { - Set allowedRoles = SecurityContext.getAllOperationsAllowedRoles(); - if(!SecurityContext.isUserAllowed(allowedRoles)) { - throw new NotAuthorizedException("Only user with one of the following role " + allowedRoles + " can create a child Context requesting the operation from a Context which is not the parent."); + Set allowedRoles = SystemEnvironment.getAllOperationsAllowedRoles(); + if(!requestEnvironment.isUserAllowed(allowedRoles)) { + throw new NotAuthorizedException("Only user with one of the following roles " + allowedRoles + " can create a child Context requesting the operation from a Context which is not the parent."); } } - checkContext(parentContextManagement); if (uuid == null) { uuid = UUIDManager.getInstance().generateValidUUID(); @@ -325,7 +322,11 @@ public class ContextManagement extends EntityElementManagement allowedRoles = SystemEnvironment.getAllOperationsAllowedRoles(); + if(!requestEnvironment.isUserAllowed(allowedRoles)) { + throw new NotAuthorizedException("Only user with one of the following roles " + allowedRoles + " can create a root Context."); + } checkContext(null); logFullPath(); createVertex(); @@ -333,19 +334,20 @@ public class ContextManagement extends EntityElementManagement edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME); @@ -483,17 +485,18 @@ public class ContextManagement extends EntityElementManagement iterable = getElement().getEdges(ODirection.OUT); @@ -506,7 +509,7 @@ public class ContextManagement extends EntityElementManagement> definitionToBeCreated = new ArrayList<>(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/AdminSecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/AdminEnvironment.java similarity index 68% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/AdminSecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/AdminEnvironment.java index 421d280..593fab1 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/AdminSecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/AdminEnvironment.java @@ -1,9 +1,8 @@ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,9 +14,9 @@ import com.orientechnologies.orient.core.metadata.security.OSecurity; /** * @author Luca Frosini (ISTI - CNR) */ -public class AdminSecurityContext extends SecurityContext { +public class AdminEnvironment extends SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); private static final String ADMIN_SECURITY_CONTEXT; private static final UUID ADMIN_SECURITY_CONTEXT_UUID; @@ -27,25 +26,23 @@ public class AdminSecurityContext extends SecurityContext { ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT); } - private static AdminSecurityContext instance; + private static AdminEnvironment instance; - public static AdminSecurityContext getInstance() throws ResourceRegistryException { + public static AdminEnvironment getInstance() throws ResourceRegistryException { if(instance==null) { - instance = new AdminSecurityContext(); - ContextUtility contextUtility = ContextUtility.getInstance(); - contextUtility.addSecurityContext(ADMIN_SECURITY_CONTEXT, instance); + instance = new AdminEnvironment(); } return instance; } - private AdminSecurityContext() throws ResourceRegistryException { + private AdminEnvironment() throws ResourceRegistryException { super(ADMIN_SECURITY_CONTEXT_UUID, false); } - @Override - protected boolean isHierarchicalMode() { - return false; - } +// @Override +// protected boolean isHierarchicalMode() { +// return false; +// } @Override public void create() { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ContextSecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/ContextEnvironment.java similarity index 69% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ContextSecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/ContextEnvironment.java index 7396d35..ade03cb 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ContextSecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/ContextEnvironment.java @@ -1,9 +1,8 @@ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,9 +12,9 @@ import com.orientechnologies.orient.core.metadata.security.ORule; /** * @author Luca Frosini (ISTI - CNR) */ -public class ContextSecurityContext extends SecurityContext { +public class ContextEnvironment extends SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); private static final String CONTEXT_SECURITY_CONTEXT; private static final UUID CONTEXT_SECURITY_CONTEXT_UUID; @@ -25,18 +24,16 @@ public class ContextSecurityContext extends SecurityContext { CONTEXT_SECURITY_CONTEXT_UUID = UUID.fromString(CONTEXT_SECURITY_CONTEXT); } - private static ContextSecurityContext instance; + private static ContextEnvironment instance; - public static ContextSecurityContext getInstance() throws ResourceRegistryException { + public static ContextEnvironment getInstance() throws ResourceRegistryException { if(instance==null) { - instance = new ContextSecurityContext(); - ContextUtility contextUtility = ContextUtility.getInstance(); - contextUtility.addSecurityContext(CONTEXT_SECURITY_CONTEXT, instance); + instance = new ContextEnvironment(); } return instance; } - private ContextSecurityContext() throws ResourceRegistryException { + private ContextEnvironment() throws ResourceRegistryException { super(CONTEXT_SECURITY_CONTEXT_UUID, false); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/environments/InstanceEnvironment.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/InstanceEnvironment.java new file mode 100644 index 0000000..01c9d92 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/InstanceEnvironment.java @@ -0,0 +1,20 @@ +package org.gcube.informationsystem.resourceregistry.environments; + +import java.util.UUID; + +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class InstanceEnvironment extends SystemEnvironment { + + private static Logger logger = LoggerFactory.getLogger(InstanceEnvironment.class); + + public InstanceEnvironment(UUID uuid) throws ResourceRegistryException { + super(uuid, true); + } + +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/QueryTemplatesSecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/QueryTemplateEnvironment.java similarity index 69% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/QueryTemplatesSecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/QueryTemplateEnvironment.java index 31cc45a..4087cf0 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/QueryTemplatesSecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/QueryTemplateEnvironment.java @@ -1,9 +1,8 @@ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,9 +12,9 @@ import com.orientechnologies.orient.core.metadata.security.ORule; /** * @author Luca Frosini (ISTI - CNR) */ -public class QueryTemplatesSecurityContext extends SecurityContext { +public class QueryTemplateEnvironment extends SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); private static final String QUERY_TEMPLATES_SECURITY_CONTEXT; private static final UUID QUERY_TEMPLATES_SECURITY_CONTEXT_UUID; @@ -25,18 +24,16 @@ public class QueryTemplatesSecurityContext extends SecurityContext { QUERY_TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(QUERY_TEMPLATES_SECURITY_CONTEXT); } - private static QueryTemplatesSecurityContext instance; + private static QueryTemplateEnvironment instance; - public static QueryTemplatesSecurityContext getInstance() throws ResourceRegistryException { + public static QueryTemplateEnvironment getInstance() throws ResourceRegistryException { if(instance==null) { - instance = new QueryTemplatesSecurityContext(); - ContextUtility contextUtility = ContextUtility.getInstance(); - contextUtility.addSecurityContext(QUERY_TEMPLATES_SECURITY_CONTEXT, instance); + instance = new QueryTemplateEnvironment(); } return instance; } - private QueryTemplatesSecurityContext() throws ResourceRegistryException { + private QueryTemplateEnvironment() throws ResourceRegistryException { super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ShadowContextSecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/ShadowContextEnvironment.java similarity index 69% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ShadowContextSecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/ShadowContextEnvironment.java index c5b9203..198af39 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/ShadowContextSecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/ShadowContextEnvironment.java @@ -1,9 +1,8 @@ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,9 +13,9 @@ import com.orientechnologies.orient.core.metadata.security.ORule; * @author Luca Frosini (ISTI - CNR) * Added for feature #19428 */ -public class ShadowContextSecurityContext extends SecurityContext { +public class ShadowContextEnvironment extends SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); private static final String SHADOW_CONTEXT_SECURITY_CONTEXT; private static final UUID SHADOW_CONTEXT_SECURITY_CONTEXT_UUID; @@ -28,18 +27,16 @@ public class ShadowContextSecurityContext extends SecurityContext { } - private static ShadowContextSecurityContext instance; + private static ShadowContextEnvironment instance; - public static ShadowContextSecurityContext getInstance() throws ResourceRegistryException { + public static ShadowContextEnvironment getInstance() throws ResourceRegistryException { if(instance==null) { - instance = new ShadowContextSecurityContext(); - ContextUtility contextUtility = ContextUtility.getInstance(); - contextUtility.addSecurityContext(SHADOW_CONTEXT_SECURITY_CONTEXT, instance); + instance = new ShadowContextEnvironment(); } return instance; } - private ShadowContextSecurityContext() throws ResourceRegistryException { + private ShadowContextEnvironment() throws ResourceRegistryException { super(SHADOW_CONTEXT_SECURITY_CONTEXT_UUID, false); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/SecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java similarity index 89% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/SecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java index 4676b1d..9040b5a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/SecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.ArrayList; import java.util.Collection; @@ -45,9 +45,9 @@ import com.orientechnologies.orient.core.record.impl.ODocument; /** * @author Luca Frosini (ISTI - CNR) */ -public class SecurityContext { +public abstract class SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); protected static final String DEFAULT_WRITER_ROLE = "writer"; protected static final String DEFAULT_READER_ROLE = "reader"; @@ -91,15 +91,15 @@ public class SecurityContext { protected final Map> poolMap; - protected SecurityContext parentSecurityContext; + protected SystemEnvironment parentSecurityContext; - protected Set children; + protected Set children; /** * Roles allowed to operate on the security context */ protected static Set allOperationAllowedRoles; - //protected static Set allowedRoles; + protected Set allowedRoles; public final static String INFRASTRUCTURE_MANAGER = "Infrastructure-Manager"; public final static String IS_MANAGER = "IS-Manager"; @@ -107,27 +107,27 @@ public class SecurityContext { public final static String CONTEXT_MANAGER = "Context-Manager"; static { - allOperationAllowedRoles = new HashSet<>(); - allOperationAllowedRoles.add(INFRASTRUCTURE_MANAGER); - allOperationAllowedRoles.add(IS_MANAGER); - -// allowedRoles = new HashSet<>(); -// allowedRoles.add(CONTEXT_MANAGER); + SystemEnvironment.allOperationAllowedRoles = new HashSet<>(); + SystemEnvironment.allOperationAllowedRoles.add(INFRASTRUCTURE_MANAGER); + SystemEnvironment.allOperationAllowedRoles.add(IS_MANAGER); } public static Set getAllOperationsAllowedRoles() { return new HashSet<>(allOperationAllowedRoles); } -// public static Set getAllowedRoles() { -// return new HashSet<>(allowedRoles); -// } + public Set getAllowedRoles() { + return new HashSet<>(allowedRoles); + } - protected SecurityContext(UUID context, boolean hierarchical) throws ResourceRegistryException { + protected SystemEnvironment(UUID context, boolean hierarchical) throws ResourceRegistryException { this.context = context; this.poolMap = new HashMap<>(); - boolean hierarchicalAllowed = SecurityContext.isUserAllowed(allOperationAllowedRoles); + this.allowedRoles = new HashSet<>(SystemEnvironment.allOperationAllowedRoles); + this.allowedRoles.add(CONTEXT_MANAGER); + + boolean hierarchicalAllowed = SystemEnvironment.isUserAllowed(allOperationAllowedRoles); /* * Only the Infrastructure Manager and IS Manager are entitled to use hierarchical mode. @@ -144,20 +144,15 @@ public class SecurityContext { } this.hierarchical = hierarchical && hierarchicalAllowed; - this.children = new HashSet<>(); - + this.children = new HashSet<>(); } - public SecurityContext(UUID context) throws ResourceRegistryException { - this(context, true); - } - protected boolean isHierarchicalMode() { return hierarchical || RequestUtility.getRequestInfo().get().isHierarchicalMode(); } - public void setParentSecurityContext(SecurityContext parentSecurityContext) { + public void setParentSecurityContext(SystemEnvironment parentSecurityContext) { if(this.parentSecurityContext!=null) { this.parentSecurityContext.getChildren().remove(this); } @@ -168,15 +163,15 @@ public class SecurityContext { } } - public SecurityContext getParentSecurityContext() { + public SystemEnvironment getParentSecurityContext() { return parentSecurityContext; } - private void addChild(SecurityContext child) { + private void addChild(SystemEnvironment child) { this.children.add(child); } - public Set getChildren(){ + public Set getChildren(){ return this.children; } @@ -188,10 +183,10 @@ public class SecurityContext { * @return a set containing all children and recursively * all children. */ - private Set getAllChildren(){ - Set allChildren = new HashSet<>(); + private Set getAllChildren(){ + Set allChildren = new HashSet<>(); allChildren.add(this); - for(SecurityContext securityContext : getChildren()) { + for(SystemEnvironment securityContext : getChildren()) { allChildren.addAll(securityContext.getAllChildren()); } return allChildren; @@ -200,9 +195,9 @@ public class SecurityContext { /** * @return */ - private Set getAllParents(){ - Set allParents = new HashSet<>(); - SecurityContext parent = getParentSecurityContext(); + private Set getAllParents(){ + Set allParents = new HashSet<>(); + SystemEnvironment parent = getParentSecurityContext(); while(parent!=null) { allParents.add(parent); parent = parent.getParentSecurityContext(); @@ -218,13 +213,13 @@ public class SecurityContext { * @param orientGraph * @throws ResourceRegistryException */ - public void changeParentSecurityContext(SecurityContext newParentSecurityContext, ODatabaseDocument orientGraph) throws ResourceRegistryException { + public void changeParentSecurityContext(SystemEnvironment newParentSecurityContext, ODatabaseDocument orientGraph) throws ResourceRegistryException { if(!hierarchical) { StringBuilder errorMessage = new StringBuilder(); errorMessage.append("Cannot change parent "); - errorMessage.append(SecurityContext.class.getSimpleName()); + errorMessage.append(SystemEnvironment.class.getSimpleName()); errorMessage.append(" to non hierarchic "); - errorMessage.append(SecurityContext.class.getSimpleName()); + errorMessage.append(SystemEnvironment.class.getSimpleName()); errorMessage.append(". "); errorMessage.append(OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); final String error = errorMessage.toString(); @@ -234,11 +229,11 @@ public class SecurityContext { OSecurity oSecurity = getOSecurity(orientGraph); - Set allChildren = getAllChildren(); + Set allChildren = getAllChildren(); - Set oldParents = getAllParents(); + Set oldParents = getAllParents(); - Set newParents = new HashSet<>(); + Set newParents = new HashSet<>(); if(newParentSecurityContext!=null) { newParents = newParentSecurityContext.getAllParents(); } @@ -258,7 +253,7 @@ public class SecurityContext { if(newParentSecurityContext!=null){ for(PermissionMode permissionMode : PermissionMode.values()) { List roles = new ArrayList<>(); - for(SecurityContext child : allChildren) { + for(SystemEnvironment child : allChildren) { String roleName = child.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, true); ORole role = oSecurity.getRole(roleName); roles.add(role); @@ -272,7 +267,7 @@ public class SecurityContext { private synchronized ODatabasePool getPool(PermissionMode permissionMode, boolean recreate) { ODatabasePool pool = null; - Boolean h = isHierarchicalMode(); + Boolean h = hierarchical || RequestUtility.getRequestInfo().get().isHierarchicalMode(); Map pools = poolMap.get(h); if(pools == null) { @@ -504,7 +499,7 @@ public class SecurityContext { } - public boolean isUserAllowed() { + public boolean isUserAllowed(Collection allowedRoles) { boolean allowed = false; SecretManager secretManager = SecretManagerProvider.instance.get(); User user = secretManager.getUser(); @@ -675,22 +670,22 @@ public class SecurityContext { } protected void removeChildrenHRolesFromParents(OSecurity oSecurity) { - Set parents = getAllParents(); - Set allChildren = getAllChildren(); + Set parents = getAllParents(); + Set allChildren = getAllChildren(); removeChildrenHRolesFromParents(oSecurity, parents, allChildren); } - protected void removeChildrenHRolesFromParents(OSecurity oSecurity, Set parents, Set children) { - for(SecurityContext parent : parents) { + protected void removeChildrenHRolesFromParents(OSecurity oSecurity, Set parents, Set children) { + for(SystemEnvironment parent : parents) { parent.removeChildrenHRolesFromMyHUsers(oSecurity, children); } } - protected void removeChildrenHRolesFromMyHUsers(OSecurity oSecurity, Set children) { + protected void removeChildrenHRolesFromMyHUsers(OSecurity oSecurity, Set children) { for(PermissionMode permissionMode : PermissionMode.values()) { String userName = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, true); OUser user = oSecurity.getUser(userName); - for(SecurityContext child : children) { + for(SystemEnvironment child : children) { String roleName = child.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, true); logger.debug("Going to remove {} from {}", roleName, userName); boolean removed = user.removeRole(roleName); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/TypeSecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/TypeEnvironment.java similarity index 70% rename from src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/TypeSecurityContext.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/environments/TypeEnvironment.java index fda982c..083faa2 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/security/TypeSecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/TypeEnvironment.java @@ -1,9 +1,8 @@ -package org.gcube.informationsystem.resourceregistry.contexts.security; +package org.gcube.informationsystem.resourceregistry.environments; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,9 +12,9 @@ import com.orientechnologies.orient.core.metadata.security.ORule; /** * @author Luca Frosini (ISTI - CNR) */ -public class TypeSecurityContext extends SecurityContext { +public class TypeEnvironment extends SystemEnvironment { - private static Logger logger = LoggerFactory.getLogger(SecurityContext.class); + private static Logger logger = LoggerFactory.getLogger(SystemEnvironment.class); private static final String SCHEMA_SECURITY_CONTEXT; private static final UUID SCHEMA_SECURITY_CONTEXT_UUID; @@ -25,18 +24,16 @@ public class TypeSecurityContext extends SecurityContext { SCHEMA_SECURITY_CONTEXT_UUID = UUID.fromString(SCHEMA_SECURITY_CONTEXT); } - private static TypeSecurityContext instance; + private static TypeEnvironment instance; - public static TypeSecurityContext getInstance() throws ResourceRegistryException { + public static TypeEnvironment getInstance() throws ResourceRegistryException { if(instance==null) { - instance = new TypeSecurityContext(); - ContextUtility contextUtility = ContextUtility.getInstance(); - contextUtility.addSecurityContext(SCHEMA_SECURITY_CONTEXT, instance); + instance = new TypeEnvironment(); } return instance; } - private TypeSecurityContext() throws ResourceRegistryException { + private TypeEnvironment() throws ResourceRegistryException { super(SCHEMA_SECURITY_CONTEXT_UUID, false); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index a049dfb..c750f4b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -47,9 +47,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaE import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ServerContextCache; -import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.AdminEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.properties.PropertyElementManagement; import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.requests.RequestUtility; @@ -254,23 +254,24 @@ public abstract class ElementManagement { return accessType; } - protected SecurityContext workingContext; + protected SystemEnvironment workingEnvironment; - protected SecurityContext getWorkingContext() throws ResourceRegistryException { - if(workingContext == null) { - workingContext = ContextUtility.getCurrentSecurityContext(); - Context context = ServerContextCache.getInstance().getContextByUUID(workingContext.getUUID()); + protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException { + if(workingEnvironment == null) { + workingEnvironment = ContextUtility.getCurrentRequestEnvironment(); + Context context = ServerContextCache.getInstance().getContextByUUID(workingEnvironment.getUUID()); if(context.getState().compareTo(ContextState.ACTIVE.getState())!=0) { - if(!workingContext.isUserAllowed()) { - throw new ForbiddenException("You are not allowed to operate in non " + ContextState.ACTIVE.getState() + " Contexts. Allowed roles are " + SecurityContext.getAllOperationsAllowedRoles()); + Set allowedRoles = workingEnvironment.getAllowedRoles(); + if(!workingEnvironment.isUserAllowed(allowedRoles)) { + throw new ForbiddenException("You are not allowed to operate in non " + ContextState.ACTIVE.getState() + " Contexts. Allowed roles are " + SystemEnvironment.getAllOperationsAllowedRoles()); } } } - return workingContext; + return workingEnvironment; } - public void setWorkingContext(SecurityContext workingContext) { - this.workingContext = workingContext; + public void setWorkingEnvironment(SystemEnvironment workingContext) { + this.workingEnvironment = workingContext; } public void setUUID(UUID uuid) throws ResourceRegistryException { @@ -564,7 +565,7 @@ public abstract class ElementManagement { MetadataUtility.addMetadata(element); - getWorkingContext().addElement(element, oDatabaseDocument); + getWorkingEnvironment().addElement(element, oDatabaseDocument); element.save(); @@ -684,7 +685,7 @@ public abstract class ElementManagement { public String all(boolean polymorphic) throws ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument = getWorkingEnvironment().getDatabaseDocument(PermissionMode.READER); setAsEntryPoint(); setOperation(Operation.QUERY); return reallyGetAll(polymorphic); @@ -706,7 +707,7 @@ public abstract class ElementManagement { public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument = getWorkingEnvironment().getDatabaseDocument(PermissionMode.READER); setAsEntryPoint(); setOperation(Operation.EXISTS); @@ -734,7 +735,7 @@ public abstract class ElementManagement { throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - SecurityContext securityContext = getWorkingContext(); + SystemEnvironment securityContext = getWorkingEnvironment(); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); boolean update = false; @@ -791,7 +792,7 @@ public abstract class ElementManagement { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - SecurityContext securityContext = getWorkingContext(); + SystemEnvironment securityContext = getWorkingEnvironment(); securityContext.isUserAllowed(Operation.CREATE); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); @@ -832,7 +833,7 @@ public abstract class ElementManagement { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - SecurityContext securityContext = getWorkingContext(); + SystemEnvironment securityContext = getWorkingEnvironment(); setOperation(Operation.READ); securityContext.isUserAllowed(operation); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER); @@ -862,7 +863,7 @@ public abstract class ElementManagement { public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - SecurityContext securityContext = getWorkingContext(); + SystemEnvironment securityContext = getWorkingEnvironment(); securityContext.isUserAllowed(Operation.UPDATE); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); @@ -906,7 +907,7 @@ public abstract class ElementManagement { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { // oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER); - SecurityContext securityContext = getWorkingContext(); + SystemEnvironment securityContext = getWorkingEnvironment(); setOperation(Operation.DELETE); securityContext.isUserAllowed(operation); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.WRITER); @@ -949,14 +950,14 @@ public abstract class ElementManagement { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument instanceDB = this.oDatabaseDocument; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); setOperation(Operation.GET_METADATA); adminSecurityContext.isUserAllowed(operation); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); setAsEntryPoint(); - Set contexts = SecurityContext.getContexts(getElement()); + Set contexts = SystemEnvironment.getContexts(getElement()); return contexts; } catch(ResourceRegistryException e) { logger.error("Unable to get contexts for {} with UUID {}", typeName, uuid, e); @@ -1258,10 +1259,10 @@ public abstract class ElementManagement { SecretManager secretManager = SecretManagerProvider.instance.get(); User user = secretManager.getUser(); Collection roles = new HashSet<>(user.getRoles()); - if(roles.contains(SecurityContext.CONTEXT_MANAGER)) { + if(roles.contains(SystemEnvironment.CONTEXT_MANAGER)) { return true; } - roles.retainAll(SecurityContext.getAllOperationsAllowedRoles()); + roles.retainAll(SystemEnvironment.getAllOperationsAllowedRoles()); if(roles.size()>0) { allowed = true; } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java index c3d227c..3ec9208 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java @@ -12,7 +12,7 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; @@ -68,7 +68,7 @@ public class ElementManagementUtility { return erManagement; } - public static ElementManagement getERManagement(SecurityContext workingContext, ODatabaseDocument orientGraph, + public static ElementManagement getERManagement(SystemEnvironment workingContext, ODatabaseDocument orientGraph, OElement element) throws ResourceRegistryException { if(element instanceof OVertex) { return getEntityManagement(workingContext, orientGraph, (OVertex) element); @@ -104,7 +104,7 @@ public class ElementManagementUtility { } } - public static ElementManagement getERManagementFromUUID(SecurityContext workingContext, ODatabaseDocument orientGraph, + public static ElementManagement getERManagementFromUUID(SystemEnvironment workingContext, ODatabaseDocument orientGraph, UUID uuid) throws ResourceRegistryException { OElement element; try { @@ -116,7 +116,7 @@ public class ElementManagementUtility { } } - public static EntityManagement getEntityManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument, + public static EntityManagement getEntityManagement(SystemEnvironment workingContext, ODatabaseDocument oDatabaseDocument, OVertex vertex) throws ResourceRegistryException { if(oDatabaseDocument == null) { @@ -150,12 +150,12 @@ public class ElementManagementUtility { throw new ResourceRegistryException(error); } entityManagement.setODatabaseDocument(oDatabaseDocument); - entityManagement.setWorkingContext(workingContext); + entityManagement.setWorkingEnvironment(workingContext); entityManagement.setElement(vertex); return entityManagement; } - public static RelationManagement getRelationManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument, + public static RelationManagement getRelationManagement(SystemEnvironment workingContext, ODatabaseDocument oDatabaseDocument, OEdge edge) throws ResourceRegistryException { if(oDatabaseDocument == null) { @@ -183,7 +183,7 @@ public class ElementManagementUtility { relationManagement.setODatabaseDocument(oDatabaseDocument); - relationManagement.setWorkingContext(workingContext); + relationManagement.setWorkingEnvironment(workingContext); relationManagement.setElement(edge); return relationManagement; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/EntityElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/EntityElementManagement.java index 0af2d67..6fa1c40 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/EntityElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/entities/EntityElementManagement.java @@ -14,7 +14,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAn import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.EntityAlreadyPresentException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.relations.RelationElementManagement; @@ -52,10 +52,10 @@ public abstract class EntityElementManagement relationManagement = relationManagements.get(id); if(relationManagement == null) { - relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge); + relationManagement = ElementManagementUtility.getRelationManagement(getWorkingEnvironment(), oDatabaseDocument, edge); relationManagements.put(id, relationManagement); } return relationManagement; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java index a8a3d9e..07cbe52 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java @@ -13,7 +13,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.RelationNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; @@ -73,10 +73,10 @@ public abstract class RelationElementManagement sourceEntityClass, Class targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph) { + protected RelationElementManagement(AccessType accessType, Class sourceEntityClass, Class targetEntityClass, SystemEnvironment workingContext, ODatabaseDocument orientGraph) { this(accessType, sourceEntityClass, targetEntityClass); this.oDatabaseDocument = orientGraph; - setWorkingContext(workingContext); + setWorkingEnvironment(workingContext); } public SEM getSourceEntityManagement() throws ResourceRegistryException { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java index 61de029..9eda106 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java @@ -9,7 +9,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; public interface ERManagement { @@ -23,9 +23,9 @@ public interface ERManagement { * Set source security context to evaluate addToContext * @param sourceSecurityContext the source security context */ - public void setSourceSecurityContext(SecurityContext sourceSecurityContext); + public void setSourceSecurityContext(SystemEnvironment sourceSecurityContext); - public SecurityContext getSourceSecurityContext(); + public SystemEnvironment getSourceSecurityContext(); public void internalAddToContext() throws ContextException, ResourceRegistryException; @@ -37,9 +37,9 @@ public interface ERManagement { * Set target security context of addToContext/removeFromContext * @param targetSecurityContext */ - public void setTargetSecurityContext(SecurityContext targetSecurityContext); + public void setTargetSecurityContext(SystemEnvironment targetSecurityContext); - public SecurityContext getTargetSecurityContext(); + public SystemEnvironment getTargetSecurityContext(); public void internalRemoveFromContext() throws ContextException, ResourceRegistryException; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java index fdbdaeb..2e2f6af 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java @@ -10,9 +10,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.AdminEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.utils.TypeUtility; @@ -32,11 +32,11 @@ public class ERManagementUtility { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); - SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + SystemEnvironment targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); // Map enforcedInstances = new HashMap<>(); @@ -45,7 +45,7 @@ public class ERManagementUtility { for(UUID uuid : uuids) { String type = TypeUtility.getTypeName(expectedInstances.get(uuid)); ElementManagement elementManagement = ElementManagementUtility.getERManagement(type); - elementManagement.setWorkingContext(adminSecurityContext); + elementManagement.setWorkingEnvironment(adminSecurityContext); elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); elementManagement.setElementType(type); @@ -113,11 +113,11 @@ public class ERManagementUtility { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); - SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + SystemEnvironment targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); //Map enforcedInstances = new HashMap<>(); @@ -125,7 +125,7 @@ public class ERManagementUtility { for(UUID uuid : expectedInstances.keySet()) { String type = TypeUtility.getTypeName(expectedInstances.get(uuid)); ElementManagement elementManagement = ElementManagementUtility.getERManagement(type); - elementManagement.setWorkingContext(adminSecurityContext); + elementManagement.setWorkingEnvironment(adminSecurityContext); elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); ((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index afee33d..220dc65 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -25,8 +25,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.Inval import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ServerContextCache; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; @@ -57,12 +57,12 @@ public abstract class EntityManagement /** * The source context of an addToContex */ - protected SecurityContext sourceSecurityContext; + protected SystemEnvironment sourceSecurityContext; /** * The target context of an addToContex/RemoveFromContext */ - protected SecurityContext targetSecurityContext; + protected SystemEnvironment targetSecurityContext; /** * By the default the system honour the propagation constraints @@ -97,22 +97,22 @@ public abstract class EntityManagement protected boolean honourPropagationConstraintsInContextSharing; @Override - public void setSourceSecurityContext(SecurityContext sourceSecurityContext) { + public void setSourceSecurityContext(SystemEnvironment sourceSecurityContext) { this.sourceSecurityContext = sourceSecurityContext; } @Override - public SecurityContext getSourceSecurityContext() { + public SystemEnvironment getSourceSecurityContext() { return sourceSecurityContext; } @Override - public void setTargetSecurityContext(SecurityContext targetSecurityContext) { + public void setTargetSecurityContext(SystemEnvironment targetSecurityContext) { this.targetSecurityContext = targetSecurityContext; } @Override - public SecurityContext getTargetSecurityContext() { + public SystemEnvironment getTargetSecurityContext() { return sourceSecurityContext; } @@ -190,7 +190,7 @@ public abstract class EntityManagement String id = edge.getIdentity().toString(); RelationManagement relationManagement = relationManagements.get(id); if(relationManagement == null) { - relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge); + relationManagement = ElementManagementUtility.getRelationManagement(getWorkingEnvironment(), oDatabaseDocument, edge); relationManagements.put(id, relationManagement); } return relationManagement; @@ -349,13 +349,13 @@ public abstract class EntityManagement logger.info("Going to add {} with UUID {} to Context with UUID {} (i.e. {})", accessType.getName(), uuid, contextUUID, contextFullName); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER); + workingEnvironment = ContextUtility.getAdminSecurityContext(); + oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); setAsEntryPoint(); - sourceSecurityContext = ContextUtility.getCurrentSecurityContext(); - targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + sourceSecurityContext = ContextUtility.getCurrentRequestEnvironment(); + targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); internalAddToContext(); @@ -446,13 +446,13 @@ public abstract class EntityManagement logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER); + workingEnvironment = ContextUtility.getAdminSecurityContext(); + oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); setAsEntryPoint(); // Not needed sourceSecurityContext = ContextUtility.getCurrentSecurityContext(); - targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); internalRemoveFromContext(); @@ -504,7 +504,7 @@ public abstract class EntityManagement continue; } - EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(), + EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingEnvironment(), oDatabaseDocument, (OVertex) vertex); try { entityManagement.setAsEntryPoint(); @@ -620,7 +620,7 @@ public abstract class EntityManagement OVertex vertex = (OVertex) element; - EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(), + EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingEnvironment(), oDatabaseDocument, vertex); try { if(constraint.containsKey(Entity.ID_PROPERTY)) { @@ -650,8 +650,8 @@ public abstract class EntityManagement ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.READER); + workingEnvironment = ContextUtility.getAdminSecurityContext(); + oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.READER); setAsEntryPoint(); setOperation(Operation.QUERY); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java index 74bf2ba..eb230d7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java @@ -11,7 +11,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.face import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; import org.gcube.informationsystem.types.reference.entities.FacetType; @@ -134,14 +134,14 @@ public class FacetManagement extends EntityManagement { } switch (operation) { case CREATE: case DELETE: - resourceManagement.setWorkingContext(getWorkingContext()); + resourceManagement.setWorkingEnvironment(getWorkingEnvironment()); resourceManagement.setODatabaseDocument(oDatabaseDocument); break; case ADD_TO_CONTEXT: resourceManagement.setSourceSecurityContext(sourceSecurityContext); resourceManagement.setTargetSecurityContext(targetSecurityContext); - resourceManagement.setWorkingContext(targetSecurityContext); + resourceManagement.setWorkingEnvironment(targetSecurityContext); targetSecurityContextODatabaseDocument = targetSecurityContext.getDatabaseDocument(PermissionMode.READER); resourceManagement.setODatabaseDocument(targetSecurityContextODatabaseDocument); break; @@ -149,7 +149,7 @@ public class FacetManagement extends EntityManagement { case REMOVE_FROM_CONTEXT: // Not needed resourceManagement.setSourceSecurityContext(sourceSecurityContext); resourceManagement.setTargetSecurityContext(targetSecurityContext); - resourceManagement.setWorkingContext(targetSecurityContext); + resourceManagement.setWorkingEnvironment(targetSecurityContext); targetSecurityContextODatabaseDocument = targetSecurityContext.getDatabaseDocument(PermissionMode.READER); resourceManagement.setODatabaseDocument(targetSecurityContextODatabaseDocument); break; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java index dc565f7..ad4c085 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java @@ -24,7 +24,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.reso import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; @@ -155,7 +155,7 @@ public class ResourceManagement extends EntityManagement JsonNode jsonNodeArray = jsonNode.get(property); for(JsonNode consistOfJsonNode : jsonNodeArray) { ConsistsOfManagement com = new ConsistsOfManagement(); - com.setWorkingContext(getWorkingContext()); + com.setWorkingEnvironment(getWorkingEnvironment()); com.setODatabaseDocument(oDatabaseDocument); com.setJsonNode(consistOfJsonNode); com.setSourceEntityManagement(this); @@ -169,7 +169,7 @@ public class ResourceManagement extends EntityManagement JsonNode jsonNodeArray = jsonNode.get(property); for(JsonNode relationJsonNode : jsonNodeArray) { IsRelatedToManagement irtm = new IsRelatedToManagement(); - irtm.setWorkingContext(getWorkingContext()); + irtm.setWorkingEnvironment(getWorkingEnvironment()); irtm.setODatabaseDocument(oDatabaseDocument); irtm.setJsonNode(relationJsonNode); irtm.setSourceEntityManagement(this); @@ -191,7 +191,7 @@ public class ResourceManagement extends EntityManagement JsonNode jsonNodeArray = jsonNode.get(property); for(JsonNode relationJsonNode : jsonNodeArray) { ConsistsOfManagement com = new ConsistsOfManagement(); - com.setWorkingContext(getWorkingContext()); + com.setWorkingEnvironment(getWorkingEnvironment()); com.setODatabaseDocument(oDatabaseDocument); com.setJsonNode(relationJsonNode); com.internalCreateOrUdate(); @@ -204,7 +204,7 @@ public class ResourceManagement extends EntityManagement JsonNode jsonNodeArray = jsonNode.get(property); for(JsonNode relationJsonNode : jsonNodeArray) { IsRelatedToManagement irtm = new IsRelatedToManagement(); - irtm.setWorkingContext(getWorkingContext()); + irtm.setWorkingEnvironment(getWorkingEnvironment()); irtm.setODatabaseDocument(oDatabaseDocument); irtm.setJsonNode(relationJsonNode); irtm.internalUpdate(); @@ -238,7 +238,7 @@ public class ResourceManagement extends EntityManagement ConsistsOf.NAME, OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); } if(relationManagement != null) { - relationManagement.setWorkingContext(getWorkingContext()); + relationManagement.setWorkingEnvironment(getWorkingEnvironment()); relationManagement.setODatabaseDocument(oDatabaseDocument); relationManagement.setElement(edge); relationManagement.internalDelete(); @@ -317,7 +317,7 @@ public class ResourceManagement extends EntityManagement public String all(boolean polymorphic) throws ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument = getWorkingEnvironment().getDatabaseDocument(PermissionMode.READER); return reallyGetAll(polymorphic); } catch(ResourceRegistryException e) { throw e; @@ -483,7 +483,7 @@ public class ResourceManagement extends EntityManagement case CREATE: case UPDATE: if(relationManagement == null) { - relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge); + relationManagement = ElementManagementUtility.getRelationManagement(getWorkingEnvironment(), oDatabaseDocument, edge); relationManagements.put(id, relationManagement); /* * Here the AvailableInAnotherContextException should not occur because the connection to the DB is with the diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java index 8e0443a..eb1bf3e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java @@ -16,7 +16,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.con import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.model.Operation; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; @@ -65,7 +65,7 @@ public class ConsistsOfManagement extends RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), + RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingEnvironment(), oDatabaseDocument, edge); // visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources); serilizedEdges.add(relationManagement.serializeAsJsonNode()); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java index c1f6409..3a5e122 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/QueryImpl.java @@ -6,8 +6,8 @@ import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; @@ -32,7 +32,7 @@ public class QueryImpl implements Query { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - SecurityContext securityContext = ContextUtility.getCurrentSecurityContext(); + SystemEnvironment securityContext = ContextUtility.getCurrentRequestEnvironment(); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER); oDatabaseDocument.begin(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java index dacdb3a..a7e9993 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java @@ -17,8 +17,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.Inval import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.queries.json.base.JsonQueryERElement; @@ -117,7 +117,7 @@ public class JsonQuery { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); oDatabaseDocument = null; try { - SecurityContext securityContext = ContextUtility.getCurrentSecurityContext(); + SystemEnvironment securityContext = ContextUtility.getCurrentRequestEnvironment(); oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER); oDatabaseDocument.begin(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/templates/QueryTemplateManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/templates/QueryTemplateManagement.java index 59ae54b..47f3526 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/templates/QueryTemplateManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/templates/QueryTemplateManagement.java @@ -21,9 +21,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.QueryTemplateEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; import org.gcube.informationsystem.resourceregistry.instances.model.Operation; @@ -60,7 +60,7 @@ public class QueryTemplateManagement extends EntityElementManagement { ODatabaseDocument oDatabaseDocument = null; try { logger.debug("GettingType {} schema", typeName); - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java index e100bfe..f69d485 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java @@ -32,8 +32,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaC import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; -import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.environments.AdminEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.types.entities.FacetTypeDefinitionManagement; import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement; @@ -292,7 +292,7 @@ public class TypeManagement { throw new SchemaCreationException(error); } - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); @@ -469,7 +469,7 @@ public class TypeManagement { ODatabaseDocument oDatabaseDocument = null; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); @@ -648,7 +648,7 @@ public class TypeManagement { protected List getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { ODatabaseDocument oDatabaseDocument = null; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); @@ -789,7 +789,7 @@ public class TypeManagement { protected boolean delete(AccessType accessType) throws SchemaException, SchemaNotFoundException{ ODatabaseDocument oDatabaseDocument = null; try { - AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java index a13096a..45bc79d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java @@ -13,8 +13,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.Enti import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.TypeSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.TypeEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; @@ -48,11 +48,11 @@ public abstract class EntityTypeDefinitionManagement exten } @Override - protected SecurityContext getWorkingContext() throws ResourceRegistryException { - if (workingContext == null) { - workingContext = TypeSecurityContext.getInstance(); + protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException { + if (workingEnvironment == null) { + workingEnvironment = TypeEnvironment.getInstance(); } - return workingContext; + return workingEnvironment; } public void setName(String name) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java index 50c1096..4ccdb64 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java @@ -12,8 +12,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; -import org.gcube.informationsystem.resourceregistry.contexts.security.TypeSecurityContext; -import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; +import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment; +import org.gcube.informationsystem.resourceregistry.environments.TypeEnvironment; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility; @@ -42,10 +42,10 @@ public class PropertyTypeDefinitionManagement extends ElementManagement clz) throws ResourceRegistryException { this(clz); this.oDatabaseDocument = oDatabaseDocument; - setWorkingContext(securityContext); + setWorkingEnvironment(securityContext); } @Override @@ -59,11 +59,11 @@ public abstract class RelationTypeDefinitionManagement affectedInstances = resourceManagement.getAffectedInstances(); @@ -220,7 +220,7 @@ public class MultiContextTest extends ERManagementTest { ResourceManagement resourceManagement = getResourceManagement(r); resourceManagement.setDryRun(dryRun); - UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID(); + UUID contextUUID = ContextUtility.getInstance().getRequestEnvironmentByContextFullName(targetContextFullName).getUUID(); resourceManagement.addToContext(contextUUID); // Map affectedInstances = resourceManagement.getAffectedInstances(); // @@ -279,7 +279,7 @@ public class MultiContextTest extends ERManagementTest { IsRelatedToManagement isRelatedToManagement = getIsRelatedToManagement(isRelatedTo); isRelatedToManagement.setDryRun(dryRun); - UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID(); + UUID contextUUID = ContextUtility.getInstance().getRequestEnvironmentByContextFullName(targetContextFullName).getUUID(); isRelatedToManagement.addToContext(contextUUID); // Map affectedInstances = isRelatedToManagement.getAffectedInstances();