Search in sources :

Example 1 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method remove.

@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRAclEditorPermission.class)
public String remove(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    JsonArray jsonArray = jsonObject.getAsJsonArray("access");
    for (int i = 0; i < jsonArray.size(); i++) {
        JsonObject accessAsJsonObject = jsonArray.get(i).getAsJsonObject();
        String accessID = accessAsJsonObject.get("accessID").getAsString();
        String accessPool = accessAsJsonObject.get("accessPool").getAsString();
        if (ACCESS_STORE.existsRule(accessID, accessPool)) {
            MCRRuleMapping accessRule = ACCESS_STORE.getAccessDefinition(accessPool, accessID);
            if (!accessRule.getObjId().equals("")) {
                ACCESS_STORE.deleteAccessDefinition(accessRule);
                accessAsJsonObject.addProperty("success", "1");
            } else {
                accessAsJsonObject.addProperty("success", "0");
            }
        } else {
            accessAsJsonObject.addProperty("success", "0");
        }
    }
    return jsonObject.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 2 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method editRule.

@PUT
@Path("rule")
@MCRRestrictedAccess(MCRAclEditorPermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response editRule(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    String ruleID = jsonObject.get("ruleID").getAsString();
    String ruleDesc = jsonObject.get("ruleDesc").getAsString();
    String ruleText = jsonObject.get("ruleText").getAsString();
    String uid = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
    if (RULE_STORE.existsRule(ruleID)) {
        try {
            MCRAccessRule accessRule = new MCRAccessRule(ruleID, uid, new Date(), ruleText, ruleDesc);
            RULE_STORE.updateRule(accessRule);
            return Response.ok().build();
        } catch (Exception e) {
            return Response.status(Status.CONFLICT).build();
        }
    } else {
        return Response.status(Status.CONFLICT).build();
    }
}
Also used : JsonObject(com.google.gson.JsonObject) MCRAccessRule(org.mycore.access.mcrimpl.MCRAccessRule) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) JsonParser(com.google.gson.JsonParser) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 3 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method editMulti.

@PUT
@Path("multi")
@MCRRestrictedAccess(MCRAclEditorPermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public String editMulti(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    JsonArray jsonArray = jsonObject.getAsJsonArray("access");
    for (int i = 0; i < jsonArray.size(); i++) {
        JsonObject accessAsJsonObject = jsonArray.get(i).getAsJsonObject();
        String accessID = accessAsJsonObject.get("accessID").getAsString();
        String accessPool = accessAsJsonObject.get("accessPool").getAsString();
        String accessRule = accessAsJsonObject.get("accessRule").getAsString();
        if (ACCESS_STORE.existsRule(accessID, accessPool) && RULE_STORE.existsRule(accessRule)) {
            MCRRuleMapping newAccessRule = createRuleMap(accessID, accessPool, accessRule);
            MCRRuleMapping oldAccessRule = ACCESS_STORE.getAccessDefinition(accessPool, accessID);
            if (oldAccessRule != null && !oldAccessRule.getObjId().equals("")) {
                ACCESS_STORE.updateAccessDefinition(newAccessRule);
                accessAsJsonObject.addProperty("success", "1");
            } else {
                ACCESS_STORE.createAccessDefinition(newAccessRule);
                accessAsJsonObject.addProperty("success", "1");
            }
        } else {
            accessAsJsonObject.addProperty("success", "0");
        }
    }
    return jsonObject.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) MCRRuleMapping(org.mycore.access.mcrimpl.MCRRuleMapping) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 4 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.

the class MCRAclEditorResource method edit.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRAclEditorPermission.class)
public Response edit(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    String accessIDOld = jsonObject.get("accessIDOld").getAsString();
    String accessPoolOld = jsonObject.get("accessPoolOld").getAsString();
    String mode = jsonObject.get("mode").getAsString();
    String accessIDNew = jsonObject.get("accessIDNew").getAsString();
    String accessPoolNew = jsonObject.get("accessPoolNew").getAsString();
    String accessRuleNew = jsonObject.get("accessRuleNew").getAsString();
    if (!ACCESS_STORE.existsRule(accessIDNew, accessPoolNew) || mode.equals("rule")) {
        if (ACCESS_STORE.existsRule(accessIDOld, accessPoolOld) && RULE_STORE.existsRule(accessRuleNew) && !accessIDNew.equals("") && !accessPoolNew.equals("")) {
            MCRRuleMapping accessRule = createRuleMap(accessIDNew, accessPoolNew, accessRuleNew);
            MCRRuleMapping oldAccessRule = ACCESS_STORE.getAccessDefinition(accessPoolOld, accessIDOld);
            if (oldAccessRule != null && !oldAccessRule.getObjId().equals("")) {
                if (mode.equals("rule")) {
                    ACCESS_STORE.updateAccessDefinition(accessRule);
                } else {
                    ACCESS_STORE.deleteAccessDefinition(oldAccessRule);
                    ACCESS_STORE.createAccessDefinition(accessRule);
                }
            } else {
                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) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 5 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.

the class MCRJerseyDefaultFeature method registerAccessFilter.

protected void registerAccessFilter(FeatureContext context, Class<?> resourceClass, Method resourceMethod) {
    MCRRestrictedAccess restrictedAccessMETHOD = resourceMethod.getAnnotation(MCRRestrictedAccess.class);
    MCRRestrictedAccess restrictedAccessTYPE = resourceClass.getAnnotation(MCRRestrictedAccess.class);
    if (restrictedAccessMETHOD != null) {
        LOGGER.info("Access to {} is restricted by {}", resourceMethod, restrictedAccessMETHOD.value().getCanonicalName());
        addFilter(context, restrictedAccessMETHOD);
    } else if (restrictedAccessTYPE != null) {
        LOGGER.info("Access to {} is restricted by {}", resourceClass.getName(), restrictedAccessTYPE.value().getCanonicalName());
        addFilter(context, restrictedAccessTYPE);
    }
}
Also used : MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Aggregations

MCRRestrictedAccess (org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)12 JsonObject (com.google.gson.JsonObject)10 Consumes (javax.ws.rs.Consumes)8 JsonParser (com.google.gson.JsonParser)7 JsonArray (com.google.gson.JsonArray)5 Path (javax.ws.rs.Path)5 MCRRuleMapping (org.mycore.access.mcrimpl.MCRRuleMapping)4 GET (javax.ws.rs.GET)3 POST (javax.ws.rs.POST)3 PUT (javax.ws.rs.PUT)3 MCRAccessRule (org.mycore.access.mcrimpl.MCRAccessRule)3 DELETE (javax.ws.rs.DELETE)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonStreamParser (com.google.gson.JsonStreamParser)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1