use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.
the class MCRWCMSAccessResource method createOrUpdate.
@POST
public String createOrUpdate(@QueryParam("webPageID") String webPageID, @QueryParam("perm") String perm, @QueryParam("ruleID") String ruleID) {
MCRAccessStore accessStore = MCRAccessStore.getInstance();
JsonObject returnObject = new JsonObject();
if (MCRLayoutUtilities.hasRule(perm, webPageID)) {
MCRRuleMapping ruleMap = accessStore.getAccessDefinition(perm, MCRLayoutUtilities.getWebpageACLID(webPageID));
ruleMap.setRuleId(ruleID);
accessStore.updateAccessDefinition(ruleMap);
} else {
MCRRuleMapping ruleMap = new MCRRuleMapping();
ruleMap.setCreator(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID());
ruleMap.setCreationdate(new Date());
ruleMap.setPool(perm);
ruleMap.setRuleId(ruleID);
ruleMap.setObjId(MCRLayoutUtilities.getWebpageACLID(webPageID));
accessStore.createAccessDefinition(ruleMap);
}
JsonObject doneObject = new JsonObject();
returnObject.addProperty("type", "editDone");
returnObject.add("edit", doneObject);
doneObject.addProperty("ruleId", MCRLayoutUtilities.getRuleID(perm, webPageID));
doneObject.addProperty("ruleDes", MCRLayoutUtilities.getRuleDescr(perm, webPageID));
return returnObject.toString();
}
use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.
the class MCRJPAAccessStoreTest method deleteAccessDefinition.
/**
* Test method for
* {@link org.mycore.backend.jpa.access.MCRJPAAccessStore#deleteAccessDefinition(org.mycore.access.mcrimpl.MCRRuleMapping)}.
*/
@Test
public void deleteAccessDefinition() {
final String objID = "test";
final String permission = "maytest";
MCRRuleMapping ruleMapping = addRuleMapping(objID, permission, TRUE_RULE.getRid());
startNewTransaction();
ACCESS_STORE.deleteAccessDefinition(ruleMapping);
startNewTransaction();
assertNull(MCRHIBConnection.instance().getSession().get(MCRACCESS.class, new MCRACCESSPK(permission, objID)));
}
use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.
the class MCRJPAAccessStoreTest method updateAccessDefinition.
/**
* Test method for
* {@link org.mycore.backend.jpa.access.MCRJPAAccessStore#updateAccessDefinition(org.mycore.access.mcrimpl.MCRRuleMapping)}.
*/
@Test
public void updateAccessDefinition() {
final String objID = "test";
final String permission = "maytest";
MCRRuleMapping ruleMapping = addRuleMapping(objID, permission, TRUE_RULE.getRid());
startNewTransaction();
ruleMapping.setRuleId(FALSE_RULE.getRid());
ACCESS_STORE.updateAccessDefinition(ruleMapping);
startNewTransaction();
MCRACCESS access = MCRHIBConnection.instance().getSession().get(MCRACCESS.class, new MCRACCESSPK(permission, objID));
assertEquals(FALSE_RULE, access.getRule());
}
use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.
the class MCRJPAAccessStoreTest method addRuleMapping.
private MCRRuleMapping addRuleMapping(final String objID, final String permission, final String rid) {
MCRRuleMapping rulemapping = new MCRRuleMapping();
rulemapping.setCreationdate(new Date());
rulemapping.setCreator("JUnit");
rulemapping.setObjId(objID);
rulemapping.setPool(permission);
rulemapping.setRuleId(rid);
ACCESS_STORE.createAccessDefinition(rulemapping);
return rulemapping;
}
use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.
the class MCRWCMSAccessResource method delete.
@DELETE
public String delete(@QueryParam("webPageID") String webPageID, @QueryParam("perm") String perm) {
JsonObject returnObject = new JsonObject();
if (!MCRLayoutUtilities.hasRule(perm, webPageID)) {
throw new WebApplicationException(Status.NOT_FOUND);
}
MCRAccessStore accessStore = MCRAccessStore.getInstance();
MCRRuleMapping ruleMap = accessStore.getAccessDefinition(perm, MCRLayoutUtilities.getWebpageACLID(webPageID));
accessStore.deleteAccessDefinition(ruleMap);
JsonObject doneObject = new JsonObject();
returnObject.addProperty("type", "editDone");
returnObject.add("edit", doneObject);
return returnObject.toString();
}
Aggregations