diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java index 07e91b2..f0ecea0 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java @@ -69,11 +69,6 @@ public class ContextUtility { return sm.getUser().getUsername(); } - public static AdminEnvironment getAdminSecurityContext() throws ResourceRegistryException { - AdminEnvironment adminSecurityContext = AdminEnvironment.getInstance(); - return adminSecurityContext; - } - public synchronized void addSecurityContext(InstanceEnvironment securityContext) { contexts.put(securityContext.getUUID(), securityContext); } @@ -98,7 +93,7 @@ public class ContextUtility { if(securityContext==null) { logger.trace("{} for {} is not in cache. Going to get it", SystemEnvironment.class.getSimpleName(), fullName); - oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument = AdminEnvironment.getInstance().getDatabaseDocument(PermissionMode.READER); OVertex contextVertex = getContextVertexByFullName(oDatabaseDocument, fullName); @@ -191,7 +186,7 @@ public class ContextUtility { try { if(contextVertex == null) { - oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER); + oDatabaseDocument = AdminEnvironment.getInstance().getDatabaseDocument(PermissionMode.READER); contextVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid, OVertex.class); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java index 9040b5a..e55069e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/environments/SystemEnvironment.java @@ -87,7 +87,7 @@ public abstract class SystemEnvironment { } } - protected final UUID context; + protected final UUID environmentId; protected final Map> poolMap; @@ -121,7 +121,7 @@ public abstract class SystemEnvironment { } protected SystemEnvironment(UUID context, boolean hierarchical) throws ResourceRegistryException { - this.context = context; + this.environmentId = context; this.poolMap = new HashMap<>(); this.allowedRoles = new HashSet<>(SystemEnvironment.allOperationAllowedRoles); @@ -176,7 +176,7 @@ public abstract class SystemEnvironment { } protected ODatabaseDocument getAdminDatabaseDocument() throws ResourceRegistryException { - return ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER); + return AdminEnvironment.getInstance().getDatabaseDocument(PermissionMode.WRITER); } /** @@ -299,7 +299,7 @@ public abstract class SystemEnvironment { } public UUID getUUID() { - return context; + return environmentId; } public static String getRoleOrUserName(PermissionMode permissionMode, SecurityType securityType) { @@ -322,7 +322,7 @@ public abstract class SystemEnvironment { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getRoleOrUserName(permissionMode, securityType, hierarchic)); stringBuilder.append("_"); - stringBuilder.append(context.toString()); + stringBuilder.append(environmentId.toString()); return stringBuilder.toString(); } @@ -624,7 +624,7 @@ public abstract class SystemEnvironment { public void create(ODatabaseDocument oDatabaseDocument) { OSecurity oSecurity = getOSecurity(oDatabaseDocument); createRolesAndUsers(oSecurity); - logger.trace("Security Context (roles and users) with UUID {} successfully created", context.toString()); + logger.trace("Security Context (roles and users) with UUID {} successfully created", environmentId.toString()); } private void drop(OSecurity oSecurity, String name, SecurityType securityType) { @@ -731,9 +731,9 @@ public abstract class SystemEnvironment { } private void delete(OSecurity oSecurity) { - logger.trace("Going to remove Security Context (roles and users) with UUID {}", context.toString()); + logger.trace("Going to remove Security Context (roles and users) with UUID {}", environmentId.toString()); deleteRolesAndUsers(oSecurity); - logger.trace("Security Context (roles and users) with UUID {} successfully removed", context.toString()); + logger.trace("Security Context (roles and users) with UUID {} successfully removed", environmentId.toString()); } public ODatabaseDocument getDatabaseDocument(PermissionMode permissionMode) throws ResourceRegistryException { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index c750f4b..5a1a09b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -950,7 +950,7 @@ public abstract class ElementManagement { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument instanceDB = this.oDatabaseDocument; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = AdminEnvironment.getInstance(); setOperation(Operation.GET_METADATA); adminSecurityContext.isUserAllowed(operation); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java index 2e2f6af..0e96c64 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java @@ -32,8 +32,8 @@ public class ERManagementUtility { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); SystemEnvironment targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); @@ -45,7 +45,7 @@ public class ERManagementUtility { for(UUID uuid : uuids) { String type = TypeUtility.getTypeName(expectedInstances.get(uuid)); ElementManagement elementManagement = ElementManagementUtility.getERManagement(type); - elementManagement.setWorkingEnvironment(adminSecurityContext); + elementManagement.setWorkingEnvironment(adminEnvironment); elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); elementManagement.setElementType(type); @@ -113,8 +113,8 @@ public class ERManagementUtility { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); SystemEnvironment targetSecurityContext = ContextUtility.getInstance().getEnvironmentByUUID(contextUUID); @@ -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.setWorkingEnvironment(adminSecurityContext); + elementManagement.setWorkingEnvironment(adminEnvironment); elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); ((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index 220dc65..ad2b776 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -25,6 +25,7 @@ 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.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; @@ -349,7 +350,7 @@ public abstract class EntityManagement logger.info("Going to add {} with UUID {} to Context with UUID {} (i.e. {})", accessType.getName(), uuid, contextUUID, contextFullName); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingEnvironment = ContextUtility.getAdminSecurityContext(); + workingEnvironment = AdminEnvironment.getInstance(); oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); setAsEntryPoint(); @@ -446,7 +447,7 @@ public abstract class EntityManagement logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingEnvironment = ContextUtility.getAdminSecurityContext(); + workingEnvironment = AdminEnvironment.getInstance(); oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.WRITER); oDatabaseDocument.begin(); setAsEntryPoint(); @@ -650,7 +651,7 @@ public abstract class EntityManagement ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { - workingEnvironment = ContextUtility.getAdminSecurityContext(); + workingEnvironment = AdminEnvironment.getInstance(); oDatabaseDocument = workingEnvironment.getDatabaseDocument(PermissionMode.READER); setAsEntryPoint(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java index 6ee4ace..2de025f 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java @@ -29,6 +29,7 @@ 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.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; @@ -516,7 +517,7 @@ public abstract class RelationManagement { ODatabaseDocument oDatabaseDocument = null; try { logger.debug("GettingType {} schema", typeName); - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); + AdminEnvironment adminSecurityContext = AdminEnvironment.getInstance(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java index f69d485..de84b86 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypeManagement.java @@ -31,7 +31,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaA import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaCreationException; 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.environments.AdminEnvironment; import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; @@ -292,8 +291,8 @@ public class TypeManagement { throw new SchemaCreationException(error); } - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.WRITER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); @@ -469,8 +468,8 @@ public class TypeManagement { ODatabaseDocument oDatabaseDocument = null; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.WRITER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); @@ -648,8 +647,8 @@ public class TypeManagement { protected List getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { ODatabaseDocument oDatabaseDocument = null; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); @@ -789,8 +788,8 @@ public class TypeManagement { protected boolean delete(AccessType accessType) throws SchemaException, SchemaNotFoundException{ ODatabaseDocument oDatabaseDocument = null; try { - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + oDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); OSchema oSchema = oMetadata.getSchema(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java index 44eac58..c3ad09e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/OrientDBUtility.java @@ -93,8 +93,8 @@ public class OrientDBUtility { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); - AdminEnvironment adminSecurityContext = ContextUtility.getAdminSecurityContext(); - adminDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); + AdminEnvironment adminEnvironment = AdminEnvironment.getInstance(); + adminDatabaseDocument = adminEnvironment.getDatabaseDocument(PermissionMode.READER); return OrientDBUtility.getElementByUUID(adminDatabaseDocument, elementType, uuid, clz); } finally { if(adminDatabaseDocument != null) { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java index 282c529..a892f23 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironmentTest.java @@ -2,7 +2,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.environments.AdminEnvironment; import org.gcube.informationsystem.resourceregistry.environments.SystemEnvironment.PermissionMode; import org.junit.Assert; import org.junit.Test; @@ -27,7 +27,7 @@ public class DatabaseEnvironmentTest { @Test public void testDateTimeFormat() throws ResourceRegistryException { - ODatabaseDocument oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER); + ODatabaseDocument oDatabaseDocument = AdminEnvironment.getInstance().getDatabaseDocument(PermissionMode.WRITER); String dateTime = oDatabaseDocument.get(ATTRIBUTES.DATETIMEFORMAT).toString(); Assert.assertTrue(dateTime.compareTo(Element.DATETIME_PATTERN)==0); }