Search in sources :

Example 21 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project jodd by oblac.

the class SessionMonitor method sessionCreated.

// ---------------------------------------------------------------- broadcast
/**
 * Stores session in map and broadcasts event to registered listeners.
 */
@Override
public void sessionCreated(final HttpSessionEvent httpSessionEvent) {
    HttpSession session = httpSessionEvent.getSession();
    sessionMap.putIfAbsent(session.getId(), session);
    for (HttpSessionListener listener : listeners) {
        listener.sessionCreated(httpSessionEvent);
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSession(javax.servlet.http.HttpSession)

Example 22 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener 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)

Aggregations

HttpSessionListener (javax.servlet.http.HttpSessionListener)22 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)15 HttpSession (javax.servlet.http.HttpSession)9 IOException (java.io.IOException)7 ServletException (javax.servlet.ServletException)5 NotSerializableException (java.io.NotSerializableException)4 WriteAbortedException (java.io.WriteAbortedException)4 ServletContext (javax.servlet.ServletContext)4 ServletContextAttributeListener (javax.servlet.ServletContextAttributeListener)4 ServletContextListener (javax.servlet.ServletContextListener)4 HttpSessionAttributeListener (javax.servlet.http.HttpSessionAttributeListener)4 Context (org.apache.catalina.Context)4 SessionAuthentication (org.eclipse.jetty.security.authentication.SessionAuthentication)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 ServletRequestAttributeListener (javax.servlet.ServletRequestAttributeListener)3 ServletRequestListener (javax.servlet.ServletRequestListener)3 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)3 Test (org.junit.Test)3 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2 ManagedListener (io.undertow.servlet.core.ManagedListener)2