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:
Luca Frosini 2017-11-23 16:09:19 +00:00
parent 6899669ccf
commit bbef5ed1d3
4 changed files with 27 additions and 22 deletions

View File

@ -200,9 +200,12 @@ public class ContextManagement extends EntityManagement<Context> {
parentContext.setJSON(parentJsonNode);
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.setJSON(isParentOfJsonNode);
@ -218,9 +221,8 @@ public class ContextManagement extends EntityManagement<Context> {
return getElement();
}catch (Exception e) {
if(uuid!=null) {
SecurityContext.deleteSecurityContext(orientGraph, uuid);
}
orientGraph.rollback();
SecurityContext.deleteSecurityContext(orientGraph, uuid, true);
throw e;
}
}
@ -349,7 +351,7 @@ public class ContextManagement extends EntityManagement<Context> {
element.remove();
ContextUtility.invalidContextUUIDCache(uuid);
SecurityContext.deleteSecurityContext(orientGraph, uuid);
SecurityContext.deleteSecurityContext(orientGraph, uuid, false);
return true;

View File

@ -103,7 +103,7 @@ public class SecurityContext {
}
public static void createSecurityContext(OrientGraph orientGraph,
UUID context) {
UUID context, boolean commit) {
ODatabaseDocumentTx oDatabaseDocumentTx = orientGraph.getRawGraph();
OSecurity oSecurity = oDatabaseDocumentTx.getMetadata().getSecurity();
@ -150,6 +150,9 @@ public class SecurityContext {
readerUser.save();
logger.trace("{} created", readerUser);
if(commit) {
oDatabaseDocumentTx.commit();
}
logger.trace(
"Security Context (roles and users) with UUID {} successfully created",
@ -157,7 +160,7 @@ public class SecurityContext {
}
public static void deleteSecurityContext(OrientGraph orientGraph,
UUID context) {
UUID context, boolean commit) {
logger.trace(
"Going to remove Security Context (roles and users) with UUID {}",
@ -205,6 +208,10 @@ public class SecurityContext {
logger.error("{} was not dropped successfully", role);
}
if(commit) {
oDatabaseDocumentTx.commit();
}
logger.trace(
"Security Context (roles and users) with UUID {} successfully removed",
context.toString());

View File

@ -30,7 +30,7 @@ public abstract class SecurityContextMapper {
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);
// 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 UUID MANAGEMENT_SECURITY_CONTEXT_UUID = UUID.fromString(MANAGEMENT_SECURITY_CONTEXT);
@ -53,24 +53,20 @@ public abstract class SecurityContextMapper {
.setupPool(1, 10);
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()) {
Map<UUID, OrientGraphFactory> map = new HashMap<>();
securityContextFactories.put(p, map);
getSecurityContextFactory(ADMIN_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();
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID, p, false);
}
} catch (Exception e) {

View File

@ -390,7 +390,7 @@ public class ContextManagementTest {
}
}
// @Test
@Test
public void createDevContext() throws Exception {
Context gcube = new ContextImpl("gcube");
gcube = create(gcube);