use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.
the class MCRAclEditorResource method list.
@GET
@MCRRestrictedAccess(MCRAclEditorPermission.class)
public String list() {
Collection<String> ruleIDs = RULE_STORE.retrieveAllIDs();
JsonArray jsonARules = new JsonArray();
JsonObject jsonObj = new JsonObject();
for (String id : ruleIDs) {
MCRAccessRule rule = RULE_STORE.getRule(id);
JsonObject jsonO = new JsonObject();
jsonO.addProperty("ruleID", id);
jsonO.addProperty("desc", rule.getDescription());
jsonO.addProperty("ruleSt", rule.getRuleString());
jsonARules.add(jsonO);
}
jsonObj.add("rules", jsonARules);
JsonArray jsonAAccess = new JsonArray();
Collection<String> ids = ACCESS_STORE.getDistinctStringIDs();
for (String id : ids) {
Collection<String> pools = ACCESS_STORE.getPoolsForObject(id);
for (String pool : pools) {
JsonObject jsonO = new JsonObject();
jsonO.addProperty("accessID", id);
jsonO.addProperty("accessPool", pool);
jsonO.addProperty("rule", ACCESS_STORE.getRuleID(id, pool));
jsonAAccess.add(jsonO);
}
}
jsonObj.add("access", jsonAAccess);
return jsonObj.toString();
}
use of org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess in project mycore by MyCoRe-Org.
the class MCREchoResource method doEcho.
@GET
@Produces(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRRequireLogin.class)
public String doEcho() {
Gson gson = new Gson();
JsonObject jRequest = new JsonObject();
jRequest.addProperty("secure", request.isSecure());
jRequest.addProperty("authType", request.getAuthType());
jRequest.addProperty("context", request.getContextPath());
jRequest.addProperty("localAddr", request.getLocalAddr());
jRequest.addProperty("localName", request.getLocalName());
jRequest.addProperty("method", request.getMethod());
jRequest.addProperty("pathInfo", request.getPathInfo());
jRequest.addProperty("protocol", request.getProtocol());
jRequest.addProperty("queryString", request.getQueryString());
jRequest.addProperty("remoteAddr", request.getRemoteAddr());
jRequest.addProperty("remoteHost", request.getRemoteHost());
jRequest.addProperty("remoteUser", request.getRemoteUser());
jRequest.addProperty("remotePort", request.getRemotePort());
jRequest.addProperty("requestURI", request.getRequestURI());
jRequest.addProperty("scheme", request.getScheme());
jRequest.addProperty("serverName", request.getServerName());
jRequest.addProperty("servletPath", request.getServletPath());
jRequest.addProperty("serverPort", request.getServerPort());
HttpSession session = request.getSession(false);
List<String> attributes = Collections.list(session.getAttributeNames());
JsonObject sessionJSON = new JsonObject();
JsonObject attributesJSON = new JsonObject();
attributes.forEach(attr -> attributesJSON.addProperty(attr, session.getAttribute(attr).toString()));
sessionJSON.add("attributes", attributesJSON);
sessionJSON.addProperty("id", session.getId());
sessionJSON.addProperty("creationTime", session.getCreationTime());
sessionJSON.addProperty("lastAccessedTime", session.getLastAccessedTime());
sessionJSON.addProperty("maxInactiveInterval", session.getMaxInactiveInterval());
sessionJSON.addProperty("isNew", session.isNew());
jRequest.add("session", sessionJSON);
jRequest.addProperty("localPort", request.getLocalPort());
JsonArray jLocales = new JsonArray();
Enumeration<Locale> locales = request.getLocales();
while (locales.hasMoreElements()) {
jLocales.add(gson.toJsonTree(locales.nextElement().toString()));
}
jRequest.add("locales", jLocales);
JsonObject header = new JsonObject();
jRequest.add("header", header);
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
header.addProperty(headerName, headerValue);
}
JsonObject parameter = new JsonObject();
jRequest.add("parameter", parameter);
for (Map.Entry<String, String[]> param : request.getParameterMap().entrySet()) {
if (param.getValue().length == 1) {
parameter.add(param.getKey(), gson.toJsonTree(param.getValue()[0]));
} else {
parameter.add(param.getKey(), gson.toJsonTree(param.getValue()));
}
}
return jRequest.toString();
}
Aggregations