Search in sources :

Example 1 with SessionManager

use of org.eclipse.jetty.server.SessionManager 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 SessionManager

use of org.eclipse.jetty.server.SessionManager 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 SessionManager

use of org.eclipse.jetty.server.SessionManager in project jfinal by jfinal.

the class JettyServer method persistSession.

private void persistSession(WebAppContext webApp) {
    String storeDir = getStoreDir();
    SessionManager sm = webApp.getSessionHandler().getSessionManager();
    if (sm instanceof HashSessionManager) {
        ((HashSessionManager) sm).setStoreDirectory(new File(storeDir));
        return;
    }
    HashSessionManager hsm = new HashSessionManager();
    hsm.setStoreDirectory(new File(storeDir));
    SessionHandler sh = new SessionHandler();
    sh.setSessionManager(hsm);
    webApp.setSessionHandler(sh);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) File(java.io.File)

Example 4 with SessionManager

use of org.eclipse.jetty.server.SessionManager in project jfinal by jfinal.

the class JettyServerForIDEA method persistSession.

private void persistSession(WebAppContext webApp) {
    String storeDir = getStoreDir();
    SessionManager sm = webApp.getSessionHandler().getSessionManager();
    if (sm instanceof HashSessionManager) {
        ((HashSessionManager) sm).setStoreDirectory(new File(storeDir));
        return;
    }
    HashSessionManager hsm = new HashSessionManager();
    hsm.setStoreDirectory(new File(storeDir));
    SessionHandler sh = new SessionHandler();
    sh.setSessionManager(hsm);
    webApp.setSessionHandler(sh);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) File(java.io.File)

Example 5 with SessionManager

use of org.eclipse.jetty.server.SessionManager in project neo4j by neo4j.

the class Jetty9WebServer method loadAllMounts.

private void loadAllMounts() throws IOException {
    SessionManager sm = new HashSessionManager();
    final SortedSet<String> mountpoints = new TreeSet<>((Comparator<String>) (o1, o2) -> o2.compareTo(o1));
    mountpoints.addAll(staticContent.keySet());
    mountpoints.addAll(jaxRSPackages.keySet());
    mountpoints.addAll(jaxRSClasses.keySet());
    for (String contentKey : mountpoints) {
        final boolean isStatic = staticContent.containsKey(contentKey);
        final boolean isJaxrsPackage = jaxRSPackages.containsKey(contentKey);
        final boolean isJaxrsClass = jaxRSClasses.containsKey(contentKey);
        if (countSet(isStatic, isJaxrsPackage, isJaxrsClass) > 1) {
            throw new RuntimeException(format("content-key '%s' is mapped more than once", contentKey));
        } else if (isStatic) {
            loadStaticContent(sm, contentKey);
        } else if (isJaxrsPackage) {
            loadJAXRSPackage(sm, contentKey);
        } else if (isJaxrsClass) {
            loadJAXRSClasses(sm, contentKey);
        } else {
            throw new RuntimeException(format("content-key '%s' is not mapped", contentKey));
        }
    }
}
Also used : Request(org.eclipse.jetty.server.Request) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslSocketConnectorFactory(org.neo4j.server.security.ssl.SslSocketConnectorFactory) Log(org.neo4j.logging.Log) SortedSet(java.util.SortedSet) ServletException(javax.servlet.ServletException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MovedContextHandler(org.eclipse.jetty.server.handler.MovedContextHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Map(java.util.Map) Filter(javax.servlet.Filter) KeyStoreInformation(org.neo4j.bolt.security.ssl.KeyStoreInformation) URI(java.net.URI) InjectableProvider(org.neo4j.server.database.InjectableProvider) Server(org.eclipse.jetty.server.Server) BlockingArrayQueue(org.eclipse.jetty.util.BlockingArrayQueue) EnumSet(java.util.EnumSet) Collection(java.util.Collection) BlockingQueue(java.util.concurrent.BlockingQueue) PortBindException(org.neo4j.helpers.PortBindException) String.format(java.lang.String.format) List(java.util.List) Optional(java.util.Optional) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) BindException(java.net.BindException) TreeSet(java.util.TreeSet) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ArrayList(java.util.ArrayList) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) Config(org.neo4j.kernel.configuration.Config) RequestLog(org.eclipse.jetty.server.RequestLog) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Iterator(java.util.Iterator) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Consumer(java.util.function.Consumer) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) Injectable(org.neo4j.server.plugins.Injectable) SessionManager(org.eclipse.jetty.server.SessionManager) Resource(org.eclipse.jetty.util.resource.Resource) DispatcherType(javax.servlet.DispatcherType) Comparator(java.util.Comparator) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) TreeSet(java.util.TreeSet)

Aggregations

SessionManager (org.eclipse.jetty.server.SessionManager)6 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)5 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)4 File (java.io.File)2 HashMap (java.util.HashMap)2 RequestLog (org.eclipse.jetty.server.RequestLog)2 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)2 AbstractSessionManager (org.eclipse.jetty.server.session.AbstractSessionManager)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 BindException (java.net.BindException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 Iterator (java.util.Iterator)1