Refs #10238: Refactor Context Port Type
Task-Url: https://support.d4science.org/issues/10238 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158790 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6899669ccf
commit
bbef5ed1d3
|
@ -200,9 +200,12 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
parentContext.setJSON(parentJsonNode);
|
parentContext.setJSON(parentJsonNode);
|
||||||
|
|
||||||
checkContext(parentContext);
|
checkContext(parentContext);
|
||||||
createVertex();
|
if(uuid==null){
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
SecurityContext.createSecurityContext(orientGraph, uuid, true);
|
||||||
|
|
||||||
SecurityContext.createSecurityContext(orientGraph, uuid);
|
createVertex();
|
||||||
|
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||||
isParentOfManagement.setJSON(isParentOfJsonNode);
|
isParentOfManagement.setJSON(isParentOfJsonNode);
|
||||||
|
@ -218,9 +221,8 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
|
|
||||||
return getElement();
|
return getElement();
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
if(uuid!=null) {
|
orientGraph.rollback();
|
||||||
SecurityContext.deleteSecurityContext(orientGraph, uuid);
|
SecurityContext.deleteSecurityContext(orientGraph, uuid, true);
|
||||||
}
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +351,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
element.remove();
|
element.remove();
|
||||||
|
|
||||||
ContextUtility.invalidContextUUIDCache(uuid);
|
ContextUtility.invalidContextUUIDCache(uuid);
|
||||||
SecurityContext.deleteSecurityContext(orientGraph, uuid);
|
SecurityContext.deleteSecurityContext(orientGraph, uuid, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class SecurityContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createSecurityContext(OrientGraph orientGraph,
|
public static void createSecurityContext(OrientGraph orientGraph,
|
||||||
UUID context) {
|
UUID context, boolean commit) {
|
||||||
|
|
||||||
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraph.getRawGraph();
|
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraph.getRawGraph();
|
||||||
OSecurity oSecurity = oDatabaseDocumentTx.getMetadata().getSecurity();
|
OSecurity oSecurity = oDatabaseDocumentTx.getMetadata().getSecurity();
|
||||||
|
@ -150,6 +150,9 @@ public class SecurityContext {
|
||||||
readerUser.save();
|
readerUser.save();
|
||||||
logger.trace("{} created", readerUser);
|
logger.trace("{} created", readerUser);
|
||||||
|
|
||||||
|
if(commit) {
|
||||||
|
oDatabaseDocumentTx.commit();
|
||||||
|
}
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Security Context (roles and users) with UUID {} successfully created",
|
"Security Context (roles and users) with UUID {} successfully created",
|
||||||
|
@ -157,7 +160,7 @@ public class SecurityContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteSecurityContext(OrientGraph orientGraph,
|
public static void deleteSecurityContext(OrientGraph orientGraph,
|
||||||
UUID context) {
|
UUID context, boolean commit) {
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Going to remove Security Context (roles and users) with UUID {}",
|
"Going to remove Security Context (roles and users) with UUID {}",
|
||||||
|
@ -205,6 +208,10 @@ public class SecurityContext {
|
||||||
logger.error("{} was not dropped successfully", role);
|
logger.error("{} was not dropped successfully", role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(commit) {
|
||||||
|
oDatabaseDocumentTx.commit();
|
||||||
|
}
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"Security Context (roles and users) with UUID {} successfully removed",
|
"Security Context (roles and users) with UUID {} successfully removed",
|
||||||
context.toString());
|
context.toString());
|
||||||
|
|
|
@ -30,7 +30,7 @@ public abstract class SecurityContextMapper {
|
||||||
protected static final String ADMIN_SECURITY_CONTEXT = "00000000-0000-0000-0000-000000000000";
|
protected static final String ADMIN_SECURITY_CONTEXT = "00000000-0000-0000-0000-000000000000";
|
||||||
protected static final UUID ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT);
|
protected static final UUID ADMIN_SECURITY_CONTEXT_UUID = UUID.fromString(ADMIN_SECURITY_CONTEXT);
|
||||||
|
|
||||||
// Used to Persist Context and thei relations
|
// Used to Persist Context and their relations
|
||||||
public static final String MANAGEMENT_SECURITY_CONTEXT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
public static final String MANAGEMENT_SECURITY_CONTEXT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
||||||
public static final UUID MANAGEMENT_SECURITY_CONTEXT_UUID = UUID.fromString(MANAGEMENT_SECURITY_CONTEXT);
|
public static final UUID MANAGEMENT_SECURITY_CONTEXT_UUID = UUID.fromString(MANAGEMENT_SECURITY_CONTEXT);
|
||||||
|
|
||||||
|
@ -53,24 +53,20 @@ public abstract class SecurityContextMapper {
|
||||||
.setupPool(1, 10);
|
.setupPool(1, 10);
|
||||||
|
|
||||||
factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString());
|
factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||||
|
OrientGraph orientGraph = factory.getTx();
|
||||||
|
|
||||||
|
if (created) {
|
||||||
|
SecurityContext.createSecurityContext(orientGraph, ADMIN_SECURITY_CONTEXT_UUID, true);
|
||||||
|
SecurityContext.createSecurityContext(orientGraph, MANAGEMENT_SECURITY_CONTEXT_UUID, true);
|
||||||
|
DatabaseIntializator.createEntitiesAndRelations();
|
||||||
|
}
|
||||||
|
|
||||||
for (PermissionMode p : PermissionMode.values()) {
|
for (PermissionMode p : PermissionMode.values()) {
|
||||||
Map<UUID, OrientGraphFactory> map = new HashMap<>();
|
Map<UUID, OrientGraphFactory> map = new HashMap<>();
|
||||||
securityContextFactories.put(p, map);
|
securityContextFactories.put(p, map);
|
||||||
|
|
||||||
getSecurityContextFactory(ADMIN_SECURITY_CONTEXT_UUID, p, false);
|
getSecurityContextFactory(ADMIN_SECURITY_CONTEXT_UUID, p, false);
|
||||||
}
|
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID, p, false);
|
||||||
|
|
||||||
if (created) {
|
|
||||||
OrientGraph orientGraph = factory.getTx();
|
|
||||||
SecurityContext.createSecurityContext(orientGraph, MANAGEMENT_SECURITY_CONTEXT_UUID);
|
|
||||||
|
|
||||||
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID,
|
|
||||||
PermissionMode.READER, false);
|
|
||||||
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID,
|
|
||||||
PermissionMode.WRITER, false);
|
|
||||||
|
|
||||||
DatabaseIntializator.createEntitiesAndRelations();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -390,7 +390,7 @@ public class ContextManagementTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void createDevContext() throws Exception {
|
public void createDevContext() throws Exception {
|
||||||
Context gcube = new ContextImpl("gcube");
|
Context gcube = new ContextImpl("gcube");
|
||||||
gcube = create(gcube);
|
gcube = create(gcube);
|
||||||
|
|
Loading…
Reference in New Issue