Search in sources :

Example 6 with MCRRuleMapping

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();
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) JsonObject(com.google.gson.JsonObject) MCRAccessStore(org.mycore.access.mcrimpl.MCRAccessStore) Date(java.util.Date) POST(javax.ws.rs.POST)

Example 7 with MCRRuleMapping

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)));
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) Test(org.junit.Test)

Example 8 with MCRRuleMapping

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());
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) Test(org.junit.Test)

Example 9 with MCRRuleMapping

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;
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) Date(java.util.Date)

Example 10 with MCRRuleMapping

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();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) JsonObject(com.google.gson.JsonObject) MCRAccessStore(org.mycore.access.mcrimpl.MCRAccessStore) DELETE(javax.ws.rs.DELETE)

Aggregations

MCRRuleMapping (org.mycore.access.mcrimpl.MCRRuleMapping)12 JsonObject (com.google.gson.JsonObject)6 JsonParser (com.google.gson.JsonParser)4 Consumes (javax.ws.rs.Consumes)4 MCRRestrictedAccess (org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)4 Date (java.util.Date)3 Test (org.junit.Test)3 JsonArray (com.google.gson.JsonArray)2 DELETE (javax.ws.rs.DELETE)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 MCRAccessStore (org.mycore.access.mcrimpl.MCRAccessStore)2 EntityManager (javax.persistence.EntityManager)1 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1