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();
}
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();
}
}
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();
}
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();
}
}
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);
}
}
Aggregations