Search in sources :

Example 6 with SessionManager

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

the class WebServer method createSessionHandler.

/**
   * @return A {@link SessionHandler} which contains a {@link HashSessionManager}
   */
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
    SessionManager sessionManager = new HashSessionManager();
    sessionManager.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
    sessionManager.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 new SessionHandler(sessionManager);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HttpSessionListener(javax.servlet.http.HttpSessionListener) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) HttpSession(javax.servlet.http.HttpSession) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) SessionAuthentication(org.eclipse.jetty.security.authentication.SessionAuthentication)

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