Search in sources :

Example 11 with MCRRuleMapping

use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method add.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRAclEditorPermission.class)
public Response add(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    String accessID = jsonObject.get("accessID").getAsString();
    String accessPool = jsonObject.get("accessPool").getAsString();
    String rule = jsonObject.get("rule").getAsString();
    if (RULE_STORE.existsRule(rule) && !accessID.equals("") && !accessPool.equals("")) {
        MCRRuleMapping accessRule = createRuleMap(accessID, accessPool, rule);
        if (!ACCESS_STORE.existsRule(accessID, accessPool)) {
            ACCESS_STORE.createAccessDefinition(accessRule);
            return Response.ok().build();
        } else {
            return Response.status(Status.CONFLICT).build();
        }
    } else {
        return Response.status(Status.CONFLICT).build();
    }
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 12 with MCRRuleMapping

use of org.mycore.access.mcrimpl.MCRRuleMapping in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method createRuleMap.

private MCRRuleMapping createRuleMap(String accessID, String accessPool, String rule) {
    String uid = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
    MCRRuleMapping accessRule = new MCRRuleMapping();
    accessRule.setObjId(accessID);
    accessRule.setPool(accessPool);
    accessRule.setRuleId(rule);
    accessRule.setCreationdate(new Date());
    accessRule.setCreator(uid);
    return accessRule;
}
Also used : MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) Date(java.util.Date)

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