Search in sources :

Example 66 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project structr by structr.

the class SessionHelper method invalidateSession.

public static synchronized void invalidateSession(final HttpSession session) {
    if (session != null) {
        final String sessionId = session.getId();
        try {
            final SessionCache sessionCache = Services.getInstance().getService(HttpService.class).getSessionCache();
            synchronized (sessionCache) {
                SessionHandler handler = sessionCache.getSessionHandler();
                handler.clearEventListeners();
                handler.removeSession(sessionId, true);
            }
        } catch (final Exception ex) {
            logger.warn("Invalidating session failed: {}", sessionId);
        }
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HttpService(org.structr.rest.service.HttpService) SessionCache(org.eclipse.jetty.server.session.SessionCache) FrameworkException(org.structr.common.error.FrameworkException)

Example 67 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project neo4j by neo4j.

the class Jetty9WebServer method loadJaxRsResource.

private void loadJaxRsResource(String mountPoint) {
    log.debug("Mounting servlet at [%s]", mountPoint);
    SessionHandler sessionHandler = new SessionHandler();
    sessionHandler.setServer(getJetty());
    JaxRsServletHolderFactory jaxRsServletHolderFactory = jaxRsServletHolderFactories.get(mountPoint);
    ServletContextHandler jerseyContext = new ServletContextHandler();
    jerseyContext.setServer(getJetty());
    jerseyContext.setErrorHandler(new NeoJettyErrorHandler());
    jerseyContext.setContextPath(mountPoint);
    jerseyContext.setSessionHandler(sessionHandler);
    jerseyContext.addServlet(jaxRsServletHolderFactory.create(binder, wadlEnabled), "/*");
    addFiltersTo(jerseyContext);
    handlers.addHandler(jerseyContext);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 68 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project drill by apache.

the class WebServer method createSessionHandler.

/**
 * Create a {@link SessionHandler}
 *
 * @param securityHandler Set of init parameters that are used by the Authentication
 * @return session handler
 */
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
    SessionHandler sessionHandler = new SessionHandler();
    // SessionManager sessionManager = new HashSessionManager();
    sessionHandler.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
    // response cookie will be returned with HttpOnly flag
    sessionHandler.getSessionCookieConfig().setHttpOnly(true);
    sessionHandler.addEventListener(new HttpSessionListener() {

        @Override
        public void sessionCreated(HttpSessionEvent se) {
        }

        @Override
        public void sessionDestroyed(HttpSessionEvent se) {
            final HttpSession session = se.getSession();
            if (session == null) {
                return;
            }
            final Object authCreds = session.getAttribute(SessionAuthentication.__J_AUTHENTICATED);
            if (authCreds != null) {
                final SessionAuthentication sessionAuth = (SessionAuthentication) authCreds;
                securityHandler.logout(sessionAuth);
                session.removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
            }
            // Clear all the resources allocated for this session
            final WebSessionResources webSessionResources = (WebSessionResources) session.getAttribute(WebSessionResources.class.getSimpleName());
            if (webSessionResources != null) {
                webSessionResources.close();
                session.removeAttribute(WebSessionResources.class.getSimpleName());
            }
        }
    });
    return sessionHandler;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSession(javax.servlet.http.HttpSession) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) SessionAuthentication(org.eclipse.jetty.security.authentication.SessionAuthentication)

Example 69 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project knox 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) {
        // Minimum number of threads must be > 3.
        // DatanodeHttpServer sets the HTTP_MAX_THREADS_KEY to 3
        threadPool.setMaxThreads(Math.max(maxThreads, 4));
    }
    SessionHandler sessionHandler = webAppContext.getSessionHandler();
    sessionHandler.setHttpOnly(true);
    sessionHandler.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 = setHeaders(conf);
    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 : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) AuthenticationFilterInitializer(org.apache.hadoop.security.AuthenticationFilterInitializer) RequestLog(org.eclipse.jetty.server.RequestLog) Configuration(org.apache.hadoop.conf.Configuration) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 70 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project knox by apache.

the class HttpServer2 method addDefaultApps.

/*
   * Add default apps.
   * @param appDir The application directory
   */
protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) {
    // 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();
        handler.setHttpOnly(true);
        handler.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();
    handler.setHttpOnly(true);
    handler.getSessionCookieConfig().setSecure(true);
    staticContext.setSessionHandler(handler);
    setContextAttributes(staticContext, conf);
    defaultContexts.put(staticContext, true);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)70 Server (org.eclipse.jetty.server.Server)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)13 IOException (java.io.IOException)10 Test (org.junit.Test)9 ServletException (javax.servlet.ServletException)8 HttpSession (javax.servlet.http.HttpSession)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Handler (org.eclipse.jetty.server.Handler)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 ArrayList (java.util.ArrayList)4 SessionCookieConfig (javax.servlet.SessionCookieConfig)4 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)4 HttpSessionListener (javax.servlet.http.HttpSessionListener)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4