diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index de565d5..bb197a2 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -239,6 +239,7 @@ public abstract class EntityManagement return sourceResource; } + @Override protected OVertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException { logger.trace("Going to create {} for {} ({}) using {}", OVertex.class.getSimpleName(), accessType.getName(), @@ -301,6 +302,12 @@ public abstract class EntityManagement protected void reallyAddToContext() throws ContextException, ResourceRegistryException { + if(!sourceSecurityContext.isElementInContext(getElement())) { + // The element in not in the source security context. It will be skipped + return; + } + + targetSecurityContext.addElement(getElement(), oDatabaseDocument); /* @@ -316,6 +323,7 @@ public abstract class EntityManagement RelationManagement relationManagement = getRelationManagement(edge); relationManagement.setDryRun(dryRun); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); + relationManagement.setSourceSecurityContext(sourceSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.internalAddToContext(); affectedInstances.putAll(relationManagement.getAffectedInstances()); @@ -341,6 +349,7 @@ public abstract class EntityManagement } } + @Override public void addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException { logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); @@ -405,6 +414,11 @@ public abstract class EntityManagement protected void reallyRemoveFromContext() throws ContextException, ResourceRegistryException { + if(!targetSecurityContext.isElementInContext(getElement())) { + // The element in not in the source security context. It will be skipped + return; + } + if(honourPropagationConstraintsInContextSharing) { Iterable edges = getElement().getEdges(ODirection.OUT); @@ -412,6 +426,7 @@ public abstract class EntityManagement RelationManagement relationManagement = getRelationManagement(edge); relationManagement.setDryRun(dryRun); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); + // Not needed relationManagement.setSourceSecurityContext(sourceSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.internalRemoveFromContext(); addToRelationManagements(relationManagement); @@ -429,6 +444,7 @@ public abstract class EntityManagement */ } + @Override public void removeFromContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException { @@ -440,6 +456,7 @@ public abstract class EntityManagement oDatabaseDocument.begin(); setAsEntryPoint(); + // Not needed sourceSecurityContext = ContextUtility.getCurrentSecurityContext(); targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); internalRemoveFromContext(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java index 591e96e..ed1394a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java @@ -74,11 +74,17 @@ public class FacetManagement extends EntityManagement { consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setElement(oEdge); consistsOfManagement.setTargetEntityManagement(this); + // Not needed consistsOfManagement.setSourceSecurityContext(sourceSecurityContext); + consistsOfManagement.setTargetSecurityContext(targetSecurityContext); + + affectedInstances.put(uuid, consistsOfManagement.serializeAsAffectedInstance()); OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next(); resourceManagement = new ResourceManagement(); resourceManagement.setElement(oVertex); + // Not needed resourceManagement.setSourceSecurityContext(sourceSecurityContext); + resourceManagement.setTargetSecurityContext(targetSecurityContext); resourceManagement.addToRelationManagements(consistsOfManagement); } super.reallyRemoveFromContext(); @@ -134,12 +140,16 @@ public class FacetManagement extends EntityManagement { break; case ADD_TO_CONTEXT: + resourceManagement.setSourceSecurityContext(sourceSecurityContext); + resourceManagement.setTargetSecurityContext(targetSecurityContext); resourceManagement.setWorkingContext(targetSecurityContext); targetSecurityContextODatabaseDocument = targetSecurityContext.getDatabaseDocument(PermissionMode.READER); resourceManagement.setODatabaseDocument(targetSecurityContextODatabaseDocument); break; case REMOVE_FROM_CONTEXT: + // Not needed resourceManagement.setSourceSecurityContext(sourceSecurityContext); + resourceManagement.setTargetSecurityContext(targetSecurityContext); resourceManagement.setWorkingContext(targetSecurityContext); targetSecurityContextODatabaseDocument = targetSecurityContext.getDatabaseDocument(PermissionMode.READER); resourceManagement.setODatabaseDocument(targetSecurityContextODatabaseDocument); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java index 20e9650..ed7743f 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java @@ -278,6 +278,7 @@ public class ResourceManagement extends EntityManagement RelationManagement relationManagement = getRelationManagement(edge); relationManagement.setDryRun(dryRun); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); + relationManagement.setSourceSecurityContext(sourceSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.internalAddToContext(); affectedInstances.putAll(relationManagement.getAffectedInstances()); @@ -432,6 +433,7 @@ public class ResourceManagement extends EntityManagement if(relationManagement == null) { try { relationManagement = ElementManagementUtility.getRelationManagement(targetSecurityContext, oDatabaseDocument, edge); + relationManagement.setSourceSecurityContext(sourceSecurityContext); relationManagements.put(id, relationManagement); }catch (AvailableInAnotherContextException e) { continue; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java index f9776c1..595c4f0 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java @@ -119,6 +119,10 @@ public class ConsistsOfManagement extends RelationManagement reallyRemoveFromContext() throws ContextException, ResourceRegistryException { - getElement(); + if(!targetSecurityContext.isElementInContext(getElement())) { + // The element in not in the source security context. It will be skipped + return affectedInstances; + } getSourceEntityManagement().getElement(); @@ -556,6 +564,7 @@ public abstract class RelationManagement