Search in sources :

Example 6 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project nutzboot by nutzam.

the class TomcatStarter method addNutzSupport.

private void addNutzSupport() {
    List<WebFilterFace> filters = appContext.getBeans(WebFilterFace.class);
    Collections.sort(filters, Comparator.comparing(WebFilterFace::getOrder));
    filters.forEach((face) -> addFilter(face));
    appContext.getBeans(WebServletFace.class).forEach((face) -> {
        if (face.getServlet() == null) {
            return;
        }
        addServlet(face);
    });
    appContext.getBeans(WebEventListenerFace.class).forEach((face) -> {
        EventListener listener = face.getEventListener();
        if (listener != null) {
            if ((listener instanceof ServletContextAttributeListener) || (listener instanceof ServletRequestAttributeListener) || (listener instanceof ServletRequestListener) || (listener instanceof HttpSessionIdListener) || (listener instanceof HttpSessionAttributeListener)) {
                this.tomcatContext.addApplicationEventListener(listener);
            }
            if ((listener instanceof ServletContextListener) || (listener instanceof HttpSessionListener)) {
                this.tomcatContext.addApplicationLifecycleListener(listener);
            }
        }
    });
}
Also used : ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) HttpSessionListener(javax.servlet.http.HttpSessionListener) WebEventListenerFace(org.nutz.boot.starter.WebEventListenerFace) ServletContextListener(javax.servlet.ServletContextListener) ServletRequestListener(javax.servlet.ServletRequestListener) HttpSessionAttributeListener(javax.servlet.http.HttpSessionAttributeListener) WebFilterFace(org.nutz.boot.starter.WebFilterFace) WebServletFace(org.nutz.boot.starter.WebServletFace) EventListener(java.util.EventListener) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener)

Example 7 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project drill by axbaretto.

the class WebServer method createSessionHandler.

/**
 * @return A {@link SessionHandler} which contains a
 *         {@link HashSessionManager}
 */
private SessionHandler createSessionHandler(Config config, final SecurityHandler securityHandler) {
    SessionManager sessionManager = new HashSessionManager();
    sessionManager.setMaxInactiveInterval(config.getInt(DrillOnYarnConfig.HTTP_SESSION_MAX_IDLE_SECS));
    sessionManager.addEventListener(new HttpSessionListener() {

        @Override
        public void sessionCreated(HttpSessionEvent se) {
        // No-op
        }

        @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);
            }
        }
    });
    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)

Example 8 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project tomcat70 by apache.

the class StandardSessionContext method tellNew.

/**
 * Inform the listeners about the new session.
 */
public void tellNew() {
    // Notify interested session event listeners
    fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
    // Notify interested application event listeners
    Context context = (Context) manager.getContainer();
    Object[] listeners = context.getApplicationLifecycleListeners();
    if (listeners != null) {
        HttpSessionEvent event = new HttpSessionEvent(getSession());
        for (int i = 0; i < listeners.length; i++) {
            if (!(listeners[i] instanceof HttpSessionListener))
                continue;
            HttpSessionListener listener = (HttpSessionListener) listeners[i];
            try {
                context.fireContainerEvent("beforeSessionCreated", listener);
                listener.sessionCreated(event);
                context.fireContainerEvent("afterSessionCreated", listener);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                try {
                    context.fireContainerEvent("afterSessionCreated", listener);
                } catch (Exception e) {
                // Ignore
                }
                manager.getContainer().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) WriteAbortedException(java.io.WriteAbortedException)

Example 9 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project drill by apache.

the class WebServer method createSessionHandler.

/**
 * It creates A {@link SessionHandler}
 *
 * @param config Drill configs
 * @param securityHandler Set of initparameters that are used by the Authentication
 * @return session handler
 */
private SessionHandler createSessionHandler(Config config, final SecurityHandler securityHandler) {
    SessionHandler sessionHandler = new SessionHandler();
    sessionHandler.setMaxInactiveInterval(config.getInt(DrillOnYarnConfig.HTTP_SESSION_MAX_IDLE_SECS));
    sessionHandler.addEventListener(new HttpSessionListener() {

        @Override
        public void sessionCreated(HttpSessionEvent se) {
        // No-op
        }

        @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);
            }
        }
    });
    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 10 with HttpSessionListener

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

the class SessionMonitor method sessionDestroyed.

/**
 * Removes session from a map and broadcasts event to registered listeners.
 */
@Override
public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
    HttpSession session = httpSessionEvent.getSession();
    sessionMap.remove(session.getId());
    for (HttpSessionListener listener : listeners) {
        listener.sessionDestroyed(httpSessionEvent);
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSession(javax.servlet.http.HttpSession)

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