protected void doGet()

in src/main/java/org/apache/sling/scripting/core/impl/SlingBindingsVariablesListJsonServlet.java [103:144]


    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException {
        boolean allowed = true;
        if (webconsoleSecurity == null) {
            log("Access forbidden as the WebConsoleSecurity reference is not set");
            allowed = false;
        } else if (!(webconsoleSecurity instanceof WebConsoleSecurityProvider2)) {
            log("Access forbidden as the WebConsoleSecurity reference does not implement WebConsoleSecurityProvider2");
            allowed = false;
        } else if (!((WebConsoleSecurityProvider2)webconsoleSecurity).authenticate(request, response)) {
            log("Access forbidden as the WebConsoleSecurity component returned false");
            // the request is terminated without any more response sent back to the client.
            //    The WebConsoleSecurityProvider2 implementation may have sent auth challenge to the client
            //    in the case of anonymous access.
            allowed = false;
        }
        if (!allowed) {
            if (!response.isCommitted()) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
            }
            return;
        }

        response.setContentType("application/json");
        JSONWriter jsonWriter = new JSONWriter(response.getWriter());
        jsonWriter.array();
        // get filter by engine selector
        String requestedExtension = request.getParameter(PARAMETER_EXTENSION);
        if (requestedExtension != null && !requestedExtension.isEmpty() ) {
            ScriptEngine selectedScriptEngine = scriptEngineManager.getEngineByExtension(requestedExtension);
            if (selectedScriptEngine == null) {
                throw new IllegalArgumentException("Invalid extension requested: "+requestedExtension);
            } else {
                writeBindingsToJsonWriter(jsonWriter, selectedScriptEngine.getFactory(), request, response);
            }
        } else {
            for (ScriptEngineFactory engineFactory : scriptEngineManager.getEngineFactories()) {
                writeBindingsToJsonWriter(jsonWriter, engineFactory, request, response);
            }
        }
        jsonWriter.endArray();
    }