diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContextMapper.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContextMapper.java index 11e3112..6564b16 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContextMapper.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContextMapper.java @@ -55,23 +55,15 @@ public abstract class SecurityContextMapper { factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString()); for (PermissionMode p : PermissionMode.values()) { - OrientGraphFactory f = new OrientGraphFactory( - DatabaseEnvironment.DB_URI, - DatabaseEnvironment.CHANGED_ADMIN_USERNAME, - DatabaseEnvironment.CHANGED_ADMIN_PASSWORD) - .setupPool(1, 10); - - f.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString()); - Map map = new HashMap<>(); - map.put(ADMIN_SECURITY_CONTEXT_UUID, f); securityContextFactories.put(p, map); + + getSecurityContextFactory(ADMIN_SECURITY_CONTEXT_UUID, p, false); } - + if (created) { OrientGraph orientGraph = factory.getTx(); - SecurityContext.createSecurityContext(orientGraph, - MANAGEMENT_SECURITY_CONTEXT_UUID); + SecurityContext.createSecurityContext(orientGraph, MANAGEMENT_SECURITY_CONTEXT_UUID); getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID, PermissionMode.READER, false); @@ -124,8 +116,7 @@ public abstract class SecurityContextMapper { UUID context, PermissionMode permissionMode, boolean recreate) { OrientGraphFactory factory = null; - Map permissionSecurityContextFactories = securityContextFactories - .get(permissionMode); + Map permissionSecurityContextFactories = securityContextFactories.get(permissionMode); if(recreate) { permissionSecurityContextFactories.remove(context); @@ -134,12 +125,18 @@ public abstract class SecurityContextMapper { } if (factory == null) { - - String username = getSecurityRoleOrUserName(permissionMode, - SecurityType.USER, context); - String password = DatabaseEnvironment.DEFAULT_PASSWORDS - .get(permissionMode); - + + String username = null; + String password = null; + + if(context.compareTo(ADMIN_SECURITY_CONTEXT_UUID)==0){ + username = DatabaseEnvironment.CHANGED_ADMIN_USERNAME; + password = DatabaseEnvironment.CHANGED_ADMIN_PASSWORD; + }else { + username = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, context); + password = DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode); + } + factory = new OrientGraphFactory(DatabaseEnvironment.DB_URI, username, password).setupPool(1, 10); factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString()); @@ -152,7 +149,7 @@ public abstract class SecurityContextMapper { public static OrientGraph getSecurityContextGraph( UUID context, PermissionMode permissionMode) { - OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true); + OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false); OrientGraph orientGraph = factory.getTx(); if(orientGraph.isClosed()) { factory = getSecurityContextFactory(context, permissionMode, true); @@ -163,7 +160,7 @@ public abstract class SecurityContextMapper { public static OrientGraphNoTx getSecurityContextGraphNoTx( UUID context, PermissionMode permissionMode) { - OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true); + OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false); OrientGraphNoTx orientGraphNoTx = factory.getNoTx(); if(orientGraphNoTx.isClosed()) { factory = getSecurityContextFactory(context, permissionMode, true); @@ -174,7 +171,7 @@ public abstract class SecurityContextMapper { public static ODatabaseDocumentTx getSecurityContextDatabaseDocumentTx( UUID context, PermissionMode permissionMode) { - OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true); + OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false); ODatabaseDocumentTx databaseDocumentTx = factory.getDatabase(); if(databaseDocumentTx.isClosed()) { factory = getSecurityContextFactory(context, permissionMode, true);