Renaming SecurityContext in SystemEnvironment which is more clear
This commit is contained in:
parent
2360949ad3
commit
ae2ec3ca5d
|
@ -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<UUID,SecurityContext> contexts;
|
||||
private Map<UUID,InstanceEnvironment> 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) {
|
||||
|
|
|
@ -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<Context, EntityTy
|
|||
public ContextManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
getWorkingEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,11 +117,11 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if (workingContext == null) {
|
||||
workingContext = ContextSecurityContext.getInstance();
|
||||
protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException {
|
||||
if (workingEnvironment == null) {
|
||||
workingEnvironment = ContextEnvironment.getInstance();
|
||||
}
|
||||
return workingContext;
|
||||
return workingEnvironment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,12 +267,8 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
// return true;
|
||||
// }
|
||||
|
||||
/*
|
||||
* The Context-Manager is allowed to operate in a context
|
||||
* only if he is the Context-Manager of the context
|
||||
*/
|
||||
|
||||
// TODO in subclass
|
||||
|
||||
|
||||
/*
|
||||
* The Context-Manager is allowed to delete a context
|
||||
|
@ -281,34 +278,34 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
|
||||
@Override
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
SecurityContext securityContext = null;
|
||||
SecurityContext parentSecurityContext = null;
|
||||
InstanceEnvironment newInstanceEnvironment = null;
|
||||
SystemEnvironment parentInstanceEnvironment = null;
|
||||
|
||||
try {
|
||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||
|
||||
SystemEnvironment requestEnvironment = ContextUtility.getCurrentRequestEnvironment();
|
||||
|
||||
if (isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||
|
||||
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||
ContextManagement parentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
parentContextManagement.setJsonNode(parentJsonNode);
|
||||
UUID parentUUID = parentContextManagement.uuid;
|
||||
parentSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(parentUUID);
|
||||
parentInstanceEnvironment = ContextUtility.getInstance().getEnvironmentByUUID(parentUUID);
|
||||
|
||||
SecurityContext requestSecurityContext = ContextUtility.getCurrentSecurityContext();
|
||||
if(requestSecurityContext.getUUID().compareTo(parentContextManagement.getUUID())==0) {
|
||||
Set<String> 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<String> 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<String> 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<String> 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<Context, EntityTy
|
|||
isParentOfManagement.internalCreate();
|
||||
|
||||
} else {
|
||||
SecurityContext.isUserAllowed(SecurityContext.getAllOperationsAllowedRoles());
|
||||
// We are creating the root
|
||||
Set<String> 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<Context, EntityTy
|
|||
|
||||
this.element.setProperty(Context.STATE, ContextState.CREATED.getState());
|
||||
|
||||
securityContext = new SecurityContext(uuid);
|
||||
securityContext.setParentSecurityContext(parentSecurityContext);
|
||||
securityContext.create(oDatabaseDocument);
|
||||
|
||||
ContextUtility.getInstance().addSecurityContext(securityContext);
|
||||
newInstanceEnvironment = new InstanceEnvironment(uuid);
|
||||
newInstanceEnvironment.setParentSecurityContext(parentInstanceEnvironment);
|
||||
newInstanceEnvironment.create(oDatabaseDocument);
|
||||
|
||||
ContextUtility.getInstance().addSecurityContext(newInstanceEnvironment);
|
||||
|
||||
return getElement();
|
||||
} catch (Exception e) {
|
||||
oDatabaseDocument.rollback();
|
||||
if (securityContext != null) {
|
||||
securityContext.delete(oDatabaseDocument);
|
||||
if (parentSecurityContext != null && securityContext != null) {
|
||||
parentSecurityContext.getChildren().remove(securityContext);
|
||||
if (newInstanceEnvironment != null) {
|
||||
newInstanceEnvironment.delete(oDatabaseDocument);
|
||||
if (parentInstanceEnvironment != null && newInstanceEnvironment != null) {
|
||||
parentInstanceEnvironment.getChildren().remove(newInstanceEnvironment);
|
||||
}
|
||||
ServerContextCache.getInstance().cleanCache();
|
||||
}
|
||||
|
@ -458,7 +460,7 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
checkContext(newParentContextManagement);
|
||||
}
|
||||
|
||||
SecurityContext newParentSecurityContext = null;
|
||||
SystemEnvironment newParentSecurityContext = null;
|
||||
|
||||
// Removing the old parent relationship if any
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME);
|
||||
|
@ -483,17 +485,18 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
isParentOfManagement.setTargetEntityManagement(this);
|
||||
isParentOfManagement.internalCreate();
|
||||
newParentSecurityContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(newParentContextManagement.uuid);
|
||||
.getEnvironmentByUUID(newParentContextManagement.uuid);
|
||||
}
|
||||
|
||||
SecurityContext thisSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
||||
SystemEnvironment thisSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(uuid);
|
||||
thisSecurityContext.changeParentSecurityContext(newParentSecurityContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
if(workingContext.isUserAllowed()) {
|
||||
throw new ForbiddenException("You are not allowed to delete the Contexts. Allowed roles are " + SecurityContext.getAllOperationsAllowedRoles());
|
||||
|
||||
if(workingEnvironment.isUserAllowed(Operation.CREATE)) {
|
||||
throw new ForbiddenException("You are not allowed to delete the Contexts. Allowed roles are " + SystemEnvironment.getAllOperationsAllowedRoles());
|
||||
}
|
||||
|
||||
Iterable<OEdge> iterable = getElement().getEdges(ODirection.OUT);
|
||||
|
@ -506,7 +509,7 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
element.delete();
|
||||
|
||||
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||
SecurityContext securityContext = contextUtility.getSecurityContextByUUID(uuid);
|
||||
SystemEnvironment securityContext = contextUtility.getEnvironmentByUUID(uuid);
|
||||
securityContext.delete(oDatabaseDocument);
|
||||
|
||||
ServerContextCache.getInstance().cleanCache();
|
||||
|
@ -635,10 +638,10 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
|
||||
@Override
|
||||
public String createOrUpdate() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
if(workingContext.isUserAllowed()) {
|
||||
if(workingEnvironment.isUserAllowed(Operation.CREATE)) {
|
||||
return super.createOrUpdate();
|
||||
}
|
||||
throw new ForbiddenException("You are not allowed to manipulate Contexts. Allowed roles are " + SecurityContext.getAllOperationsAllowedRoles());
|
||||
throw new ForbiddenException("You are not allowed to manipulate Contexts. Allowed roles are " + SystemEnvironment.getAllOperationsAllowedRoles());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,8 +15,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isp
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isparentof.IsParentOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
||||
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.SystemEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.RelationElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||
|
@ -37,7 +37,7 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
|||
public IsParentOfManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
getWorkingEnvironment();
|
||||
this.includeSource = false;
|
||||
this.includeTarget = true;
|
||||
this.forceIncludeMeta = true;
|
||||
|
@ -50,11 +50,11 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if (workingContext == null) {
|
||||
workingContext = ContextSecurityContext.getInstance();
|
||||
protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException {
|
||||
if (workingEnvironment == null) {
|
||||
workingEnvironment = ContextEnvironment.getInstance();
|
||||
}
|
||||
return workingContext;
|
||||
return workingEnvironment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,11 +23,11 @@ import org.gcube.informationsystem.model.reference.properties.Metadata;
|
|||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ServerContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.TypeSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.AdminEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.ContextEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.QueryTemplateEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.TypeEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.TypeManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTypeDefinitionManagement;
|
||||
|
@ -178,14 +178,14 @@ public class DatabaseEnvironment {
|
|||
ODatabasePool pool = new ODatabasePool(DatabaseEnvironment.DB_URI, CHANGED_ADMIN_USERNAME,
|
||||
CHANGED_ADMIN_PASSWORD);
|
||||
ODatabaseDocument oDatabaseDocument = pool.acquire();
|
||||
AdminSecurityContext.getInstance().create(oDatabaseDocument);
|
||||
AdminEnvironment.getInstance().create(oDatabaseDocument);
|
||||
oDatabaseDocument.commit();
|
||||
oDatabaseDocument.close();
|
||||
pool.close();
|
||||
|
||||
QueryTemplatesSecurityContext.getInstance().create();
|
||||
TypeSecurityContext.getInstance().create();
|
||||
ContextSecurityContext.getInstance().create();
|
||||
QueryTemplateEnvironment.getInstance().create();
|
||||
TypeEnvironment.getInstance().create();
|
||||
ContextEnvironment.getInstance().create();
|
||||
|
||||
/* We must create only OrientDB types */
|
||||
List<Class<? extends Element>> definitionToBeCreated = new ArrayList<>();
|
||||
|
|
|
@ -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() {
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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<Boolean,Map<PermissionMode,ODatabasePool>> poolMap;
|
||||
|
||||
protected SecurityContext parentSecurityContext;
|
||||
protected SystemEnvironment parentSecurityContext;
|
||||
|
||||
protected Set<SecurityContext> children;
|
||||
protected Set<SystemEnvironment> children;
|
||||
|
||||
/**
|
||||
* Roles allowed to operate on the security context
|
||||
*/
|
||||
protected static Set<String> allOperationAllowedRoles;
|
||||
//protected static Set<String> allowedRoles;
|
||||
protected Set<String> 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<String> getAllOperationsAllowedRoles() {
|
||||
return new HashSet<>(allOperationAllowedRoles);
|
||||
}
|
||||
|
||||
// public static Set<String> getAllowedRoles() {
|
||||
// return new HashSet<>(allowedRoles);
|
||||
// }
|
||||
public Set<String> 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.
|
||||
|
@ -146,18 +146,13 @@ public class SecurityContext {
|
|||
|
||||
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<SecurityContext> getChildren(){
|
||||
public Set<SystemEnvironment> getChildren(){
|
||||
return this.children;
|
||||
}
|
||||
|
||||
|
@ -188,10 +183,10 @@ public class SecurityContext {
|
|||
* @return a set containing all children and recursively
|
||||
* all children.
|
||||
*/
|
||||
private Set<SecurityContext> getAllChildren(){
|
||||
Set<SecurityContext> allChildren = new HashSet<>();
|
||||
private Set<SystemEnvironment> getAllChildren(){
|
||||
Set<SystemEnvironment> 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<SecurityContext> getAllParents(){
|
||||
Set<SecurityContext> allParents = new HashSet<>();
|
||||
SecurityContext parent = getParentSecurityContext();
|
||||
private Set<SystemEnvironment> getAllParents(){
|
||||
Set<SystemEnvironment> 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<SecurityContext> allChildren = getAllChildren();
|
||||
Set<SystemEnvironment> allChildren = getAllChildren();
|
||||
|
||||
Set<SecurityContext> oldParents = getAllParents();
|
||||
Set<SystemEnvironment> oldParents = getAllParents();
|
||||
|
||||
Set<SecurityContext> newParents = new HashSet<>();
|
||||
Set<SystemEnvironment> 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<ORole> 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<PermissionMode,ODatabasePool> pools = poolMap.get(h);
|
||||
if(pools == null) {
|
||||
|
@ -504,7 +499,7 @@ public class SecurityContext {
|
|||
}
|
||||
|
||||
|
||||
public boolean isUserAllowed() {
|
||||
public boolean isUserAllowed(Collection<String> 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<SecurityContext> parents = getAllParents();
|
||||
Set<SecurityContext> allChildren = getAllChildren();
|
||||
Set<SystemEnvironment> parents = getAllParents();
|
||||
Set<SystemEnvironment> allChildren = getAllChildren();
|
||||
removeChildrenHRolesFromParents(oSecurity, parents, allChildren);
|
||||
}
|
||||
|
||||
protected void removeChildrenHRolesFromParents(OSecurity oSecurity, Set<SecurityContext> parents, Set<SecurityContext> children) {
|
||||
for(SecurityContext parent : parents) {
|
||||
protected void removeChildrenHRolesFromParents(OSecurity oSecurity, Set<SystemEnvironment> parents, Set<SystemEnvironment> children) {
|
||||
for(SystemEnvironment parent : parents) {
|
||||
parent.removeChildrenHRolesFromMyHUsers(oSecurity, children);
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeChildrenHRolesFromMyHUsers(OSecurity oSecurity, Set<SecurityContext> children) {
|
||||
protected void removeChildrenHRolesFromMyHUsers(OSecurity oSecurity, Set<SystemEnvironment> 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);
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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<El extends OElement, T extends Type> {
|
|||
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<String> 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<El extends OElement, T extends Type> {
|
|||
|
||||
MetadataUtility.addMetadata(element);
|
||||
|
||||
getWorkingContext().addElement(element, oDatabaseDocument);
|
||||
getWorkingEnvironment().addElement(element, oDatabaseDocument);
|
||||
|
||||
element.save();
|
||||
|
||||
|
@ -684,7 +685,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
|
||||
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<El extends OElement, T extends Type> {
|
|||
|
||||
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<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
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<String> contexts = SecurityContext.getContexts(getElement());
|
||||
Set<String> 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<El extends OElement, T extends Type> {
|
|||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||
User user = secretManager.getUser();
|
||||
Collection<String> 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<E extends EntityElement, ET extend
|
|||
|
||||
}
|
||||
|
||||
protected EntityElementManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument oDatabaseDocument) {
|
||||
protected EntityElementManagement(AccessType accessType, SystemEnvironment workingContext, ODatabaseDocument oDatabaseDocument) {
|
||||
this(accessType);
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
setWorkingContext(workingContext);
|
||||
setWorkingEnvironment(workingContext);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -68,7 +68,7 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
|
|||
String id = edge.getIdentity().toString();
|
||||
RelationElementManagement<?,?,?,?> 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;
|
||||
|
|
|
@ -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<SEM extends EntityElementManagem
|
|||
this.includeTarget = includeTarget;
|
||||
}
|
||||
|
||||
protected RelationElementManagement(AccessType accessType, Class<? extends EntityElement> sourceEntityClass, Class<? extends EntityElement> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
protected RelationElementManagement(AccessType accessType, Class<? extends EntityElement> sourceEntityClass, Class<? extends EntityElement> targetEntityClass, SystemEnvironment workingContext, ODatabaseDocument orientGraph) {
|
||||
this(accessType, sourceEntityClass, targetEntityClass);
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
setWorkingEnvironment(workingContext);
|
||||
}
|
||||
|
||||
public SEM getSourceEntityManagement() throws ResourceRegistryException {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<UUID, JsonNode> 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<UUID, JsonNode> 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);
|
||||
|
|
|
@ -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<E extends Entity, ET extends EntityType>
|
|||
/**
|
||||
* 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<E extends Entity, ET extends EntityType>
|
|||
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<E extends Entity, ET extends EntityType>
|
|||
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<E extends Entity, ET extends EntityType>
|
|||
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<E extends Entity, ET extends EntityType>
|
|||
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<E extends Entity, ET extends EntityType>
|
|||
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<E extends Entity, ET extends EntityType>
|
|||
|
||||
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<E extends Entity, ET extends EntityType>
|
|||
|
||||
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);
|
||||
|
|
|
@ -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<Facet, FacetType> {
|
|||
}
|
||||
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<Facet, FacetType> {
|
|||
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;
|
||||
|
|
|
@ -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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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<Resource, ResourceType>
|
|||
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
|
||||
|
|
|
@ -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<FacetManagement, Fa
|
|||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
facetManagement.setWorkingEnvironment(getWorkingEnvironment());
|
||||
return facetManagement;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
|
|||
resourceManagement.setSourceSecurityContext(sourceSecurityContext);
|
||||
}
|
||||
resourceManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
resourceManagement.setWorkingContext(targetSecurityContext);
|
||||
resourceManagement.setWorkingEnvironment(targetSecurityContext);
|
||||
targetSecurityContextODatabaseDocument = targetSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
resourceManagement.setODatabaseDocument(targetSecurityContextODatabaseDocument);
|
||||
break;
|
||||
|
|
|
@ -60,7 +60,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
@Override
|
||||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setWorkingEnvironment(getWorkingEnvironment());
|
||||
resourceManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.Rel
|
|||
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.relations.RelationElementManagement;
|
||||
|
@ -66,12 +66,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
/**
|
||||
* 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
|
||||
|
@ -106,22 +106,22 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
public final PropagationConstraint defaultPropagationConstraint;
|
||||
|
||||
public boolean isAvailableOnContext(SecurityContext securityContext) {
|
||||
public boolean isAvailableOnContext(SystemEnvironment securityContext) {
|
||||
try {
|
||||
return securityContext.isElementInContext(element);
|
||||
} catch (ResourceRegistryException e) {
|
||||
|
@ -210,7 +210,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
ResourceManagement resourceManagement = null;
|
||||
|
||||
if(sourceResource == null) {
|
||||
resourceManagement = (ResourceManagement) ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
resourceManagement = (ResourceManagement) ElementManagementUtility.getEntityManagement(getWorkingEnvironment(),
|
||||
oDatabaseDocument, source);
|
||||
if(this instanceof IsRelatedToManagement) {
|
||||
sourceResource = resourceManagement.createCompleteJsonNode();
|
||||
|
@ -324,7 +324,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
@Override
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setWorkingEnvironment(getWorkingEnvironment());
|
||||
resourceManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
facetManagement.setWorkingEnvironment(getWorkingEnvironment());
|
||||
facetManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setJsonNode(target);
|
||||
facetManagement.internalUpdate();
|
||||
|
@ -516,12 +516,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
logger.debug("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);
|
||||
setAsEntryPoint();
|
||||
|
||||
sourceSecurityContext = ContextUtility.getCurrentSecurityContext();
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
sourceSecurityContext = ContextUtility.getCurrentRequestEnvironment();
|
||||
targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID);
|
||||
|
||||
forcedAddToContext();
|
||||
|
||||
|
@ -669,14 +669,14 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
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);
|
||||
// Not needed sourceSecurityContext = ContextUtility.getCurrentRequestEnvironment();
|
||||
targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID);
|
||||
|
||||
internalRemoveFromContext();
|
||||
|
||||
|
@ -802,7 +802,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
continue;
|
||||
}
|
||||
|
||||
RelationManagement<?, ?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
||||
RelationManagement<?, ?> relationManagement = ElementManagementUtility.getRelationManagement(getWorkingEnvironment(),
|
||||
oDatabaseDocument, edge);
|
||||
// visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
||||
serilizedEdges.add(relationManagement.serializeAsJsonNode());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<QueryTempla
|
|||
public QueryTemplateManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
getWorkingEnvironment();
|
||||
}
|
||||
|
||||
protected void checkERMatch() throws ResourceRegistryException {
|
||||
|
@ -103,11 +103,11 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if (workingContext == null) {
|
||||
workingContext = QueryTemplatesSecurityContext.getInstance();
|
||||
protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException {
|
||||
if (workingEnvironment == null) {
|
||||
workingEnvironment = QueryTemplateEnvironment.getInstance();
|
||||
}
|
||||
return workingContext;
|
||||
return workingEnvironment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -225,7 +225,7 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
|
|||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument = getWorkingEnvironment().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
boolean update = false;
|
||||
setAsEntryPoint();
|
||||
|
|
|
@ -109,7 +109,7 @@ public class Access extends BaseRest {
|
|||
public String getContext(@PathParam(InstancesManager.UUID_PATH_PARAMETER) String uuid)
|
||||
throws ContextNotFoundException, ResourceRegistryException {
|
||||
if(uuid.compareTo(ContextPath.CURRENT_CONTEXT_PATH_PART)==0){
|
||||
uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString();
|
||||
uuid = ContextUtility.getCurrentRequestEnvironment().getUUID().toString();
|
||||
}
|
||||
logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.contexts.reference.entities.Context.NAME, uuid);
|
||||
setAccountingMethod(Method.READ, org.gcube.informationsystem.contexts.reference.entities.Context.NAME);
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ContextManager extends BaseRest {
|
|||
public String read(@PathParam(ContextManager.CONTEXT_UUID_PATH_PARAMETER) String uuid)
|
||||
throws ContextNotFoundException, ResourceRegistryException {
|
||||
if(uuid.compareTo(ContextPath.CURRENT_CONTEXT_PATH_PART)==0){
|
||||
uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString();
|
||||
uuid = ContextUtility.getCurrentRequestEnvironment().getUUID().toString();
|
||||
}
|
||||
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
|
||||
setAccountingMethod(Method.READ, Context.NAME);
|
||||
|
|
|
@ -11,9 +11,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
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.dbinitialization.DatabaseEnvironment;
|
||||
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.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
|
@ -67,7 +67,7 @@ public class CachedType<T extends Type> {
|
|||
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();
|
||||
|
|
|
@ -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<Type> 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();
|
||||
|
|
|
@ -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<E extends EntityType> 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) {
|
||||
|
|
|
@ -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<OElement
|
|||
this.typeName = PropertyType.NAME;
|
||||
}
|
||||
|
||||
public PropertyTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
public PropertyTypeDefinitionManagement(SystemEnvironment securityContext, ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
setWorkingContext(securityContext);
|
||||
setWorkingEnvironment(securityContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,11 +54,11 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
|||
}
|
||||
|
||||
@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) {
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.gcube.informationsystem.resourceregistry.types.relations;
|
|||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
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.types.entities.FacetTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
|
||||
|
@ -20,7 +20,7 @@ public class ConsistsOfTypeDefinitionManagement
|
|||
this.typeName = ConsistsOfType.NAME;
|
||||
}
|
||||
|
||||
public ConsistsOfTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
public ConsistsOfTypeDefinitionManagement(SystemEnvironment securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, FacetType.class);
|
||||
this.typeName = ConsistsOfType.NAME;
|
||||
|
@ -29,7 +29,7 @@ public class ConsistsOfTypeDefinitionManagement
|
|||
@Override
|
||||
protected FacetTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
FacetTypeDefinitionManagement ftdm = new FacetTypeDefinitionManagement();
|
||||
ftdm.setWorkingContext(getWorkingContext());
|
||||
ftdm.setWorkingEnvironment(getWorkingEnvironment());
|
||||
ftdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return ftdm;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.gcube.informationsystem.resourceregistry.types.relations;
|
|||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
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.types.entities.ResourceTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
|
||||
|
@ -20,7 +20,7 @@ public class IsRelatedToTypeDefinitionManagement
|
|||
this.typeName = IsRelatedToType.NAME;
|
||||
}
|
||||
|
||||
public IsRelatedToTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
public IsRelatedToTypeDefinitionManagement(SystemEnvironment securityContext, ODatabaseDocument oDatabaseDocument)
|
||||
throws ResourceRegistryException {
|
||||
super(securityContext, oDatabaseDocument, ResourceType.class);
|
||||
this.typeName = IsRelatedToType.NAME;
|
||||
|
@ -29,7 +29,7 @@ public class IsRelatedToTypeDefinitionManagement
|
|||
@Override
|
||||
protected ResourceTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
ResourceTypeDefinitionManagement rtdm = new ResourceTypeDefinitionManagement();
|
||||
rtdm.setWorkingContext(getWorkingContext());
|
||||
rtdm.setWorkingEnvironment(getWorkingEnvironment());
|
||||
rtdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return rtdm;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.Rel
|
|||
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.relations.RelationElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.entities.EntityTypeDefinitionManagement;
|
||||
|
@ -46,11 +46,11 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
this.forceIncludeAllMeta = true;
|
||||
}
|
||||
|
||||
public RelationTypeDefinitionManagement(SecurityContext securityContext, ODatabaseDocument oDatabaseDocument,
|
||||
public RelationTypeDefinitionManagement(SystemEnvironment securityContext, ODatabaseDocument oDatabaseDocument,
|
||||
Class<TT> clz) throws ResourceRegistryException {
|
||||
this(clz);
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
setWorkingContext(securityContext);
|
||||
setWorkingEnvironment(securityContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,11 +59,11 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if (workingContext == null) {
|
||||
this.workingContext = TypeSecurityContext.getInstance();
|
||||
protected SystemEnvironment getWorkingEnvironment() throws ResourceRegistryException {
|
||||
if (workingEnvironment == null) {
|
||||
this.workingEnvironment = TypeEnvironment.getInstance();
|
||||
}
|
||||
return workingContext;
|
||||
return workingEnvironment;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
|
@ -212,7 +212,7 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
@Override
|
||||
protected ResourceTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
ResourceTypeDefinitionManagement rtdm = new ResourceTypeDefinitionManagement();
|
||||
rtdm.setWorkingContext(getWorkingContext());
|
||||
rtdm.setWorkingEnvironment(getWorkingEnvironment());
|
||||
rtdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return rtdm;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ 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.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.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -93,7 +93,7 @@ public class OrientDBUtility {
|
|||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
adminDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
return OrientDBUtility.getElementByUUID(adminDatabaseDocument, elementType, uuid, clz);
|
||||
} finally {
|
||||
|
|
|
@ -18,10 +18,11 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.SecurityType;
|
||||
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.environments.SystemEnvironment.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.SecurityType;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.junit.Assert;
|
||||
|
@ -84,26 +85,26 @@ public class ContextManagementTest extends ContextTest {
|
|||
}
|
||||
|
||||
protected void roleUserAssertions(UUID uuid, UUID oldParentUUID, boolean deleted) throws ResourceRegistryException {
|
||||
ContextSecurityContext contextSecurityContext = ContextSecurityContext.getInstance();
|
||||
ContextEnvironment contextSecurityContext = ContextEnvironment.getInstance();
|
||||
|
||||
ODatabaseDocument oDatabaseDocument = contextSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
OSecurity oSecurity = oDatabaseDocument.getMetadata().getSecurity();
|
||||
|
||||
SecurityContext securityContext = null;
|
||||
InstanceEnvironment instanceEnvironment = null;
|
||||
if(deleted) {
|
||||
securityContext = new SecurityContext(uuid);
|
||||
instanceEnvironment = new InstanceEnvironment(uuid);
|
||||
} else {
|
||||
securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
||||
instanceEnvironment = ContextUtility.getInstance().getEnvironmentByUUID(uuid);
|
||||
}
|
||||
|
||||
boolean[] booleanArray = new boolean[] {false, true};
|
||||
for(boolean hierarchic : booleanArray) {
|
||||
for(PermissionMode permissionMode : PermissionMode.values()) {
|
||||
String role = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic);
|
||||
String role = instanceEnvironment.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic);
|
||||
ORole oRole = oSecurity.getRole(role);
|
||||
Assert.assertEquals(oRole == null, deleted);
|
||||
|
||||
String user = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
|
||||
String user = instanceEnvironment.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
|
||||
OUser oUser = oSecurity.getUser(user);
|
||||
Assert.assertEquals(oUser == null, deleted);
|
||||
if(oUser != null) {
|
||||
|
@ -111,13 +112,13 @@ public class ContextManagementTest extends ContextTest {
|
|||
}
|
||||
|
||||
if(hierarchic) {
|
||||
SecurityContext parent = null;
|
||||
SystemEnvironment parent = null;
|
||||
if(deleted) {
|
||||
if(oldParentUUID != null) {
|
||||
parent = ContextUtility.getInstance().getSecurityContextByUUID(oldParentUUID);
|
||||
parent = ContextUtility.getInstance().getEnvironmentByUUID(oldParentUUID);
|
||||
}
|
||||
}
|
||||
parent = securityContext.getParentSecurityContext();
|
||||
parent = instanceEnvironment.getParentSecurityContext();
|
||||
while(parent != null) {
|
||||
String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER,
|
||||
hierarchic);
|
||||
|
@ -167,7 +168,7 @@ public class ContextManagementTest extends ContextTest {
|
|||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setUUID(uuid);
|
||||
|
||||
SecurityContext securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
||||
SystemEnvironment securityContext = ContextUtility.getInstance().getEnvironmentByUUID(uuid);
|
||||
|
||||
UUID oldParentUUID = null;
|
||||
if(securityContext.getParentSecurityContext() != null) {
|
||||
|
@ -534,7 +535,7 @@ public class ContextManagementTest extends ContextTest {
|
|||
}
|
||||
}
|
||||
|
||||
Context currentContext = read(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
Context currentContext = read(ContextUtility.getCurrentRequestEnvironment().getUUID());
|
||||
logger.debug("Current context : {}", currentContext);
|
||||
|
||||
for(Context c : contexts) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
|||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
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.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class AddToContextTest extends MultiContextTest {
|
|||
consistsOfManagement.setUUID(isIdentifiedBy.getID());
|
||||
|
||||
try {
|
||||
consistsOfManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
consistsOfManagement.removeFromContext(ContextUtility.getCurrentRequestEnvironment().getUUID());
|
||||
throw new Exception("You should not be able to delete a mandatory ConsistsOf");
|
||||
}catch (SchemaViolationException e) {
|
||||
// As expected
|
||||
|
@ -76,7 +76,7 @@ public class AddToContextTest extends MultiContextTest {
|
|||
facetManagement.setUUID(softwareFacet.getID());
|
||||
|
||||
try {
|
||||
facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
facetManagement.removeFromContext(ContextUtility.getCurrentRequestEnvironment().getUUID());
|
||||
throw new Exception("You should not be able to delete a mandatory Facet");
|
||||
}catch (SchemaViolationException e) {
|
||||
// As expected
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MultiContextTest extends ERManagementTest {
|
|||
|
||||
ResourceManagement resourceManagement = getResourceManagement(r);
|
||||
resourceManagement.setDryRun(dryRun);
|
||||
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
|
||||
UUID contextUUID = ContextUtility.getCurrentRequestEnvironment().getUUID();
|
||||
resourceManagement.removeFromContext(contextUUID);
|
||||
// Map<UUID, JsonNode> 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<UUID, JsonNode> 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<UUID, JsonNode> affectedInstances = isRelatedToManagement.getAffectedInstances();
|
||||
|
||||
|
|
Loading…
Reference in New Issue