Search in sources :

Example 11 with MCRRestrictedAccess

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();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) MCRAccessRule(org.mycore.access.mcrimpl.MCRAccessRule) GET(javax.ws.rs.GET) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 12 with MCRRestrictedAccess

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();
}
Also used : JsonArray(com.google.gson.JsonArray) Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) 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