Search in sources :

Example 6 with MCRRestrictedAccess

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

the class MCRClassificationEditorResource method save.

@POST
@Path("save")
@MCRRestrictedAccess(MCRClassificationWritePermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response save(String json) {
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (jsonStreamParser.hasNext()) {
        JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
        List<JsonObject> saveList = new ArrayList<>();
        for (JsonElement jsonElement : saveObjArray) {
            saveList.add(jsonElement.getAsJsonObject());
        }
        saveList.sort(new IndexComperator());
        for (JsonObject jsonObject : saveList) {
            String status = getStatus(jsonObject);
            SaveElement categ = getCateg(jsonObject);
            MCRJSONCategory parsedCateg = parseJson(categ.getJson());
            if ("update".equals(status)) {
                new UpdateOp(parsedCateg, jsonObject).run();
            } else if ("delete".equals(status)) {
                deleteCateg(categ.getJson());
            } else {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
        // Status.CONFLICT
        return Response.status(Status.OK).build();
    } else {
        return Response.status(Status.BAD_REQUEST).build();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonStreamParser(com.google.gson.JsonStreamParser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 7 with MCRRestrictedAccess

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

the class MCRWebCLIResource method start.

@GET
@MCRRestrictedAccess(MCRWebCLIPermission.class)
@Produces(MediaType.TEXT_HTML)
public Response start() {
    InputStream mainGui = getClass().getResourceAsStream("/META-INF/resources/modules/webcli/index.html");
    MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
    LOGGER.info("MyCore Session REST ID: {}", mcrSession.getID());
    LOGGER.info("REST ThreadID: {}", Thread.currentThread().getName());
    return Response.ok(mainGui).build();
}
Also used : MCRSession(org.mycore.common.MCRSession) InputStream(java.io.InputStream) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 8 with MCRRestrictedAccess

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

the class MCRAclEditorResource method addRule.

@POST
@Path("rule")
@MCRRestrictedAccess(MCRAclEditorPermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public String addRule(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    String ruleDesc = jsonObject.get("ruleDesc").getAsString();
    String ruleText = jsonObject.get("ruleText").getAsString();
    MCRAccessRule accessRule;
    try {
        accessRule = createAccessRule(ruleDesc, ruleText);
    } catch (Exception e) {
        return "";
    }
    RULE_STORE.createRule(accessRule);
    return accessRule.getId();
}
Also used : JsonObject(com.google.gson.JsonObject) MCRAccessRule(org.mycore.access.mcrimpl.MCRAccessRule) WebApplicationException(javax.ws.rs.WebApplicationException) JsonParser(com.google.gson.JsonParser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 9 with MCRRestrictedAccess

use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess 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 10 with MCRRestrictedAccess

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

the class MCRAclEditorResource method removeRule.

@DELETE
@Path("rule")
@MCRRestrictedAccess(MCRAclEditorPermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response removeRule(String data) {
    JsonParser jsonParser = new JsonParser();
    JsonObject jsonObject = jsonParser.parse(data).getAsJsonObject();
    String ruleID = jsonObject.get("ruleID").getAsString();
    if (!ACCESS_STORE.isRuleInUse(ruleID)) {
        RULE_STORE.deleteRule(ruleID);
        return Response.ok().build();
    } else {
        return Response.status(Status.CONFLICT).build();
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) 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