Search in sources :

Example 1 with AuthenticationCheckFilter

use of org.apache.qpid.server.management.plugin.filter.AuthenticationCheckFilter in project qpid-broker-j by apache.

the class HttpManagement method createServer.

private Server createServer(Collection<HttpPort<?>> ports) {
    LOGGER.debug("Starting up web server on {}", ports);
    _jettyServerExecutor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("Jetty-Server-Thread"));
    Server server = new Server(new ExecutorThreadPool(_jettyServerExecutor));
    int lastPort = -1;
    for (HttpPort<?> port : ports) {
        ServerConnector connector = createConnector(port, server);
        connector.addBean(new ConnectionTrackingListener());
        server.addConnector(connector);
        _portConnectorMap.put(port, connector);
        lastPort = port.getPort();
    }
    ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.setContextPath("/");
    root.setCompactPath(true);
    server.setHandler(root);
    final ErrorHandler errorHandler = new ErrorHandler() {

        @Override
        protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
            String uri = request.getRequestURI();
            writeErrorPageMessage(request, writer, code, message, uri);
            for (int i = 0; i < 20; i++) writer.write("<br/>                                                \n");
        }
    };
    root.setErrorHandler(errorHandler);
    // set servlet context attributes for broker and configuration
    root.getServletContext().setAttribute(HttpManagementUtil.ATTR_BROKER, getBroker());
    root.getServletContext().setAttribute(HttpManagementUtil.ATTR_MANAGEMENT_CONFIGURATION, this);
    root.addFilter(new FilterHolder(new ExceptionHandlingFilter()), "/*", EnumSet.allOf(DispatcherType.class));
    FilterHolder corsFilter = new FilterHolder(new CrossOriginFilter());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, getCorsAllowOrigins());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, Joiner.on(",").join(getCorsAllowMethods()));
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, getCorsAllowHeaders());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(getCorsAllowCredentials()));
    root.addFilter(corsFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(new FilterHolder(new ForbiddingTraceFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
    FilterHolder loggingFilter = new FilterHolder(new LoggingFilter());
    root.addFilter(loggingFilter, "/api/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(loggingFilter, "/service/*", EnumSet.of(DispatcherType.REQUEST));
    FilterHolder restAuthorizationFilter = new FilterHolder(new AuthenticationCheckFilter());
    restAuthorizationFilter.setInitParameter(AuthenticationCheckFilter.INIT_PARAM_ALLOWED, "/service/sasl");
    root.addFilter(restAuthorizationFilter, "/api/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(restAuthorizationFilter, "/apidocs/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(restAuthorizationFilter, "/service/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(new FilterHolder(new InteractiveAuthenticationFilter()), "/index.html", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(new FilterHolder(new InteractiveAuthenticationFilter()), "/", EnumSet.of(DispatcherType.REQUEST));
    FilterHolder redirectFilter = new FilterHolder(new RedirectFilter());
    redirectFilter.setInitParameter(RedirectFilter.INIT_PARAM_REDIRECT_URI, "/index.html");
    root.addFilter(redirectFilter, "/login.html", EnumSet.of(DispatcherType.REQUEST));
    if (_serveUncompressedDojo) {
        root.addFilter(RewriteRequestForUncompressedJavascript.class, "/dojo/dojo/*", EnumSet.of(DispatcherType.REQUEST));
        root.addFilter(RewriteRequestForUncompressedJavascript.class, "/dojo/dojox/*", EnumSet.of(DispatcherType.REQUEST));
    }
    addRestServlet(root);
    ServletHolder queryServlet = new ServletHolder(new BrokerQueryServlet());
    root.addServlet(queryServlet, "/api/latest/querybroker/*");
    root.addServlet(queryServlet, "/api/v" + BrokerModel.MODEL_VERSION + "/querybroker/*");
    ServletHolder vhQueryServlet = new ServletHolder(new VirtualHostQueryServlet());
    root.addServlet(vhQueryServlet, "/api/latest/queryvhost/*");
    root.addServlet(vhQueryServlet, "/api/v" + BrokerModel.MODEL_VERSION + "/queryvhost/*");
    ServletHolder apiDocsServlet = new ServletHolder(new ApiDocsServlet());
    final ServletHolder rewriteSerlvet = new ServletHolder(new RewriteServlet("^(.*)$", "$1/"));
    for (String path : new String[] { "/apidocs", "/apidocs/latest", "/apidocs/" + getLatestSupportedVersion() }) {
        root.addServlet(rewriteSerlvet, path);
        root.addServlet(apiDocsServlet, path + "/");
    }
    root.addServlet(new ServletHolder(new StructureServlet()), "/service/structure");
    root.addServlet(new ServletHolder(new QueueReportServlet()), "/service/queuereport/*");
    root.addServlet(new ServletHolder(new MetaDataServlet()), "/service/metadata");
    root.addServlet(new ServletHolder(new SaslServlet()), "/service/sasl");
    root.addServlet(new ServletHolder(new RootServlet("/", "/apidocs/", "index.html")), "/");
    root.addServlet(new ServletHolder(new LogoutServlet()), "/logout");
    root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDojoPath(), true)), "/dojo/dojo/*");
    root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDijitPath(), true)), "/dojo/dijit/*");
    root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDojoxPath(), true)), "/dojo/dojox/*");
    root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDgridPath(), true)), "/dojo/dgrid/*");
    root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDstorePath(), true)), "/dojo/dstore/*");
    for (String pattern : STATIC_FILE_TYPES) {
        root.addServlet(new ServletHolder(new FileServlet()), pattern);
    }
    root.addServlet(new ServletHolder(new TimeZoneServlet()), "/service/timezones");
    root.getSessionHandler().getSessionCookieConfig().setName(JSESSIONID_COOKIE_PREFIX + lastPort);
    root.getSessionHandler().getSessionCookieConfig().setHttpOnly(true);
    root.getSessionHandler().setMaxInactiveInterval(getSessionTimeout());
    return server;
}
Also used : ApiDocsServlet(org.apache.qpid.server.management.plugin.servlet.rest.ApiDocsServlet) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) MetaDataServlet(org.apache.qpid.server.management.plugin.servlet.rest.MetaDataServlet) DaemonThreadFactory(org.apache.qpid.server.util.DaemonThreadFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) LoggingFilter(org.apache.qpid.server.management.plugin.filter.LoggingFilter) AuthenticationCheckFilter(org.apache.qpid.server.management.plugin.filter.AuthenticationCheckFilter) SaslServlet(org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet) InteractiveAuthenticationFilter(org.apache.qpid.server.management.plugin.filter.InteractiveAuthenticationFilter) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) BrokerQueryServlet(org.apache.qpid.server.management.plugin.servlet.rest.BrokerQueryServlet) QueueReportServlet(org.apache.qpid.server.management.plugin.servlet.rest.QueueReportServlet) FileServlet(org.apache.qpid.server.management.plugin.servlet.FileServlet) DispatcherType(javax.servlet.DispatcherType) TimeZoneServlet(org.apache.qpid.server.management.plugin.servlet.rest.TimeZoneServlet) ForbiddingTraceFilter(org.apache.qpid.server.management.plugin.filter.ForbiddingTraceFilter) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) RedirectFilter(org.apache.qpid.server.management.plugin.filter.RedirectFilter) RootServlet(org.apache.qpid.server.management.plugin.servlet.RootServlet) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) LogoutServlet(org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet) VirtualHostQueryServlet(org.apache.qpid.server.management.plugin.servlet.rest.VirtualHostQueryServlet) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) ExceptionHandlingFilter(org.apache.qpid.server.management.plugin.filter.ExceptionHandlingFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) StructureServlet(org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 DispatcherType (javax.servlet.DispatcherType)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AuthenticationCheckFilter (org.apache.qpid.server.management.plugin.filter.AuthenticationCheckFilter)1 ExceptionHandlingFilter (org.apache.qpid.server.management.plugin.filter.ExceptionHandlingFilter)1 ForbiddingTraceFilter (org.apache.qpid.server.management.plugin.filter.ForbiddingTraceFilter)1 InteractiveAuthenticationFilter (org.apache.qpid.server.management.plugin.filter.InteractiveAuthenticationFilter)1 LoggingFilter (org.apache.qpid.server.management.plugin.filter.LoggingFilter)1 RedirectFilter (org.apache.qpid.server.management.plugin.filter.RedirectFilter)1 FileServlet (org.apache.qpid.server.management.plugin.servlet.FileServlet)1 RootServlet (org.apache.qpid.server.management.plugin.servlet.RootServlet)1 ApiDocsServlet (org.apache.qpid.server.management.plugin.servlet.rest.ApiDocsServlet)1 BrokerQueryServlet (org.apache.qpid.server.management.plugin.servlet.rest.BrokerQueryServlet)1 LogoutServlet (org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet)1 MetaDataServlet (org.apache.qpid.server.management.plugin.servlet.rest.MetaDataServlet)1 QueueReportServlet (org.apache.qpid.server.management.plugin.servlet.rest.QueueReportServlet)1 SaslServlet (org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet)1 StructureServlet (org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet)1 TimeZoneServlet (org.apache.qpid.server.management.plugin.servlet.rest.TimeZoneServlet)1