Search in sources :

Example 1 with AbstractSessionManager

use of org.eclipse.jetty.server.session.AbstractSessionManager in project hadoop by apache.

the class HttpServer2 method initializeWebServer.

private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws IOException {
    Preconditions.checkNotNull(webAppContext);
    int maxThreads = conf.getInt(HTTP_MAX_THREADS_KEY, -1);
    // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the
    // default value (currently 250).
    QueuedThreadPool threadPool = (QueuedThreadPool) webServer.getThreadPool();
    threadPool.setDaemon(true);
    if (maxThreads != -1) {
        threadPool.setMaxThreads(maxThreads);
    }
    SessionManager sm = webAppContext.getSessionHandler().getSessionManager();
    if (sm instanceof AbstractSessionManager) {
        AbstractSessionManager asm = (AbstractSessionManager) sm;
        asm.setHttpOnly(true);
        asm.getSessionCookieConfig().setSecure(true);
    }
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLog requestLog = HttpRequestLog.getRequestLog(name);
    handlers.addHandler(contexts);
    if (requestLog != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        requestLogHandler.setRequestLog(requestLog);
        handlers.addHandler(requestLogHandler);
    }
    handlers.addHandler(webAppContext);
    final String appDir = getWebAppsPath(name);
    addDefaultApps(contexts, appDir, conf);
    webServer.setHandler(handlers);
    Map<String, String> xFrameParams = new HashMap<>();
    xFrameParams.put(X_FRAME_ENABLED, String.valueOf(this.xFrameOptionIsEnabled));
    xFrameParams.put(X_FRAME_VALUE, this.xFrameOption.toString());
    addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
    final FilterInitializer[] initializers = getFilterInitializers(conf);
    if (initializers != null) {
        conf = new Configuration(conf);
        conf.set(BIND_ADDRESS, hostName);
        for (FilterInitializer c : initializers) {
            c.initFilter(this, conf);
        }
    }
    addDefaultServlets();
    if (pathSpecs != null) {
        for (String path : pathSpecs) {
            LOG.info("adding path spec: " + path);
            addFilterPathMapping(path, webAppContext);
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HashMap(java.util.HashMap) SessionManager(org.eclipse.jetty.server.SessionManager) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) AuthenticationFilterInitializer(org.apache.hadoop.security.AuthenticationFilterInitializer) RequestLog(org.eclipse.jetty.server.RequestLog) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 2 with AbstractSessionManager

use of org.eclipse.jetty.server.session.AbstractSessionManager in project hadoop by apache.

the class HttpServer2 method addDefaultApps.

/**
   * Add default apps.
   * @param appDir The application directory
   * @throws IOException
   */
protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) throws IOException {
    // set up the context for "/logs/" if "hadoop.log.dir" property is defined
    // and it's enabled.
    String logDir = System.getProperty("hadoop.log.dir");
    boolean logsEnabled = conf.getBoolean(CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED, CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED_DEFAULT);
    if (logDir != null && logsEnabled) {
        ServletContextHandler logContext = new ServletContextHandler(parent, "/logs");
        logContext.setResourceBase(logDir);
        logContext.addServlet(AdminAuthorizedServlet.class, "/*");
        if (conf.getBoolean(CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES, CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
            @SuppressWarnings("unchecked") Map<String, String> params = logContext.getInitParams();
            params.put("org.eclipse.jetty.servlet.Default.aliases", "true");
        }
        logContext.setDisplayName("logs");
        SessionHandler handler = new SessionHandler();
        SessionManager sm = handler.getSessionManager();
        if (sm instanceof AbstractSessionManager) {
            AbstractSessionManager asm = (AbstractSessionManager) sm;
            asm.setHttpOnly(true);
            asm.getSessionCookieConfig().setSecure(true);
        }
        logContext.setSessionHandler(handler);
        setContextAttributes(logContext, conf);
        addNoCacheFilter(logContext);
        defaultContexts.put(logContext, true);
    }
    // set up the context for "/static/*"
    ServletContextHandler staticContext = new ServletContextHandler(parent, "/static");
    staticContext.setResourceBase(appDir + "/static");
    staticContext.addServlet(DefaultServlet.class, "/*");
    staticContext.setDisplayName("static");
    @SuppressWarnings("unchecked") Map<String, String> params = staticContext.getInitParams();
    params.put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    params.put("org.eclipse.jetty.servlet.Default.gzip", "true");
    SessionHandler handler = new SessionHandler();
    SessionManager sm = handler.getSessionManager();
    if (sm instanceof AbstractSessionManager) {
        AbstractSessionManager asm = (AbstractSessionManager) sm;
        asm.setHttpOnly(true);
        asm.getSessionCookieConfig().setSecure(true);
    }
    staticContext.setSessionHandler(handler);
    setContextAttributes(staticContext, conf);
    defaultContexts.put(staticContext, true);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) SessionManager(org.eclipse.jetty.server.SessionManager) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 3 with AbstractSessionManager

use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.

the class AuthenticationServerImpl method initServer.

@Override
protected void initServer() throws Exception {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    String authDocumentRoot = loader.getResource(AUTH_DOCUMENT_ROOT).toString();
    _server = new Server();
    initConnectors();
    // Static Pages
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[] { "*" });
    resourceHandler.setResourceBase(authDocumentRoot);
    // AuthN servlet filters
    ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    rootHandler.setContextPath("/");
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { resourceHandler, rootHandler });
    _server.setHandler(handlerCollection);
    ((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
    final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
    rootHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
    // Add the REST resources
    if (_app != null) {
        ResourceConfig config = new DefaultResourceConfig();
        config.add(_app);
        Map<String, MediaType> type = config.getMediaTypeMappings();
        type.put("json", MediaType.APPLICATION_JSON_TYPE);
        type.put("xml", MediaType.APPLICATION_XML_TYPE);
        rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
    }
    // load trust store from file to zk. must do it before authmgr started, who holds the connection with ad.
    loadTrustStoreFromLocalFiles();
    _dbClient.start();
    _tokenManager.init();
    _authManager.init();
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) AbstractSecuredWebServer(com.emc.storageos.security.AbstractSecuredWebServer) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DelegatingFilterProxy(org.springframework.web.filter.DelegatingFilterProxy) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 4 with AbstractSessionManager

use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.

the class TestWebServer method initServer.

/**
 * Initialize server handlers, rest resources.
 *
 * @throws Exception
 */
private void initServer() throws Exception {
    _server = new Server();
    initConnectors();
    // AuthN servlet filters
    ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    rootHandler.setContextPath("/");
    _server.setHandler(rootHandler);
    ((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
    // Add the REST resources
    if (_app != null) {
        ResourceConfig config = new DefaultResourceConfig();
        config.add(_app);
        Map<String, MediaType> type = config.getMediaTypeMappings();
        type.put(MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN_TYPE);
        rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
    }
}
Also used : Server(org.eclipse.jetty.server.Server) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 5 with AbstractSessionManager

use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.

the class AbstractSecuredWebServer method initServer.

/**
 * Initialize server handlers, rest resources.
 *
 * @throws Exception
 */
protected void initServer() throws Exception {
    _server = new Server();
    initThreadPool();
    initConnectors();
    // AuthN servlet filters
    servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setContextPath("/");
    _server.setHandler(servletHandler);
    ((AbstractSessionManager) servletHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
    if (_disabler != null) {
        final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_disablingFilter));
        servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
        _log.warn("security checks are disabled... skipped adding security filters");
    } else {
        final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
        servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
    }
    // Add the REST resources
    if (_app != null) {
        ResourceConfig config = new DefaultResourceConfig();
        config.add(_app);
        Map<String, MediaType> type = config.getMediaTypeMappings();
        type.put("json", MediaType.APPLICATION_JSON_TYPE);
        type.put("xml", MediaType.APPLICATION_XML_TYPE);
        type.put("octet-stream", MediaType.APPLICATION_OCTET_STREAM_TYPE);
        type.put("form-data", MediaType.MULTIPART_FORM_DATA_TYPE);
        servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
        // AuthZ resource filters
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, _resourceFilterFactory);
        // Adding the ContainerResponseFilter
        props.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, _responseFilter);
        config.setPropertiesAndFeatures(props);
    }
    if (_dbClient != null) {
        // Otherwise there could be a dependency loop between services.
        if (startDbClientInBackground) {
            _log.info("starting dbclient in background");
            new Thread() {

                public void run() {
                    _dbClient.start();
                }
            }.start();
        } else {
            _log.info("starting dbclient");
            _dbClient.start();
        }
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DelegatingFilterProxy(org.springframework.web.filter.DelegatingFilterProxy) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Aggregations

AbstractSessionManager (org.eclipse.jetty.server.session.AbstractSessionManager)5 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 DefaultResourceConfig (com.sun.jersey.api.core.DefaultResourceConfig)3 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)3 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)3 MediaType (javax.ws.rs.core.MediaType)3 Server (org.eclipse.jetty.server.Server)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 HashMap (java.util.HashMap)2 SessionManager (org.eclipse.jetty.server.SessionManager)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 DelegatingFilterProxy (org.springframework.web.filter.DelegatingFilterProxy)2 AbstractSecuredWebServer (com.emc.storageos.security.AbstractSecuredWebServer)1 Configuration (org.apache.hadoop.conf.Configuration)1 AuthenticationFilterInitializer (org.apache.hadoop.security.AuthenticationFilterInitializer)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 RequestLog (org.eclipse.jetty.server.RequestLog)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)1