Example usage for javax.servlet.http HttpSessionEvent getSession

List of usage examples for javax.servlet.http HttpSessionEvent getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionEvent getSession.

Prototype

public HttpSession getSession() 

Source Link

Document

Return the session that changed.

Usage

From source file:org.hdiv.listener.InitWebSphereListener.java

/**
 * Strategies initialization.//from w w  w.  j  av a  2s. c  om
 * @param wac web application context
 * @param httpSessionEvent http session event
 */
private void initStrategies(WebApplicationContext wac, HttpSessionEvent httpSessionEvent) {

    String strategy = (String) wac.getBean("strategy");

    if (strategy.equalsIgnoreCase("cipher")) {
        IKeyFactory keyFactory = (IKeyFactory) wac.getBean("keyFactory");
        // creating encryption key
        Key key = keyFactory.generateKeyWithDefaultValues();
        String keyName = (String) wac.getBean("keyName");

        httpSessionEvent.getSession().setAttribute((keyName == null) ? Constants.KEY_NAME : keyName, key);

    } else {
        // @since HDIV 1.1
        httpSessionEvent.getSession().setAttribute(Constants.STATE_SUFFIX,
                String.valueOf(System.currentTimeMillis()));
    }
}

From source file:org.jboss.test.faces.jetty.JettyServer.java

private void createContext() {
    webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setBaseResource(serverRoot);
    webAppContext.setClassLoader(getClassLoader());

    org.mortbay.jetty.servlet.ServletHolder defaultServletHolder = new org.mortbay.jetty.servlet.ServletHolder(
            new DefaultServlet());
    //defaultServletHolder.setInitParameter("aliases", Boolean.FALSE.toString());

    webAppContext.addServlet(defaultServletHolder, "/");

    webAppContext.addEventListener(new HttpSessionListener() {

        public void sessionDestroyed(HttpSessionEvent se) {
            session = null;//from  w  w  w.ja va  2 s.c o  m
        }

        public void sessionCreated(HttpSessionEvent se) {
            session = se.getSession();
        }
    });
}

From source file:org.apache.drill.yarn.appMaster.http.WebServer.java

/**
 * @return A {@link SessionHandler} which contains a
 *         {@link HashSessionManager}//from  w ww. j  av a 2s . c  o  m
 */
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);
}

From source file:org.webcurator.ui.listener.AcegiLogoutListener.java

public void sessionDestroyed(HttpSessionEvent event) {
    // Log the logout to the console.
    log.info("Detected Logout Event");

    // Get the Spring Application Context.
    WebApplicationContext ctx = ApplicationContextFactory.getWebApplicationContext();

    // We need to get the authentication context out of the 
    // event, as it doesn't necessarily exist through the
    // standard Acegi tools.
    String remoteUser = null;/*w  w  w. ja  va2  s.  com*/
    Authentication auth = null;
    SecurityContext acegiCtx = (SecurityContext) event.getSession().getAttribute("ACEGI_SECURITY_CONTEXT");
    if (acegiCtx != null) {
        auth = acegiCtx.getAuthentication();
        if (auth != null) {
            remoteUser = auth.getName();
        }
    }

    if (remoteUser == null) {
        remoteUser = "[UNKNOWN]";
    }

    // Actions to perform on logout.
    lockManager = (LockManager) ctx.getBean("lockManager");
    lockManager.releaseLocksForOwner(remoteUser);

    if (auth != null) {
        Object blob = auth.getDetails();
        if (blob instanceof User) {
            User user = (User) auth.getDetails();
            Auditor auditor = (Auditor) ctx.getBean(Constants.BEAN_AUDITOR);
            auditor.audit(user, User.class.getName(), user.getOid(), Auditor.ACTION_LOGOUT,
                    "User " + remoteUser + " has logged out.");
        }

        SecurityContextHolder.clearContext();

        // logout for duration
        String sessionId = event.getSession().getId();
        LogonDurationDAO logonDurationDAO = (LogonDurationDAO) ctx.getBean(Constants.BEAN_LOGON_DURATION_DAO);
        logonDurationDAO.setLoggedOut(sessionId, new Date());
    }

    // Log the logout to the console.
    log.info("Detected Logout Event for: " + remoteUser);
}

From source file:org.everit.authentication.cas.CasAuthentication.java

/**
 * When an {@link HttpSession} is destroyed it must be removed from the
 * {@link CasHttpSessionRegistry}.//from   w  w  w. jav a  2 s.co m
 */
@Override
public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
    HttpSession httpSession = httpSessionEvent.getSession();
    ServletContext servletContext = httpSession.getServletContext();

    CasHttpSessionRegistry casHttpSessionRegistry = CasHttpSessionRegistry.getInstance(servicePid,
            servletContext);
    casHttpSessionRegistry.removeBySession(httpSession);
}

From source file:com.ericsson.eif.hansoft.HansoftManager.java

@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
    // Default timeout for a Jetty session is 30 min - after this we will
    // get timeout. Release the corresponding HansoftConnector - the
    // virtual session will be GC'd
    HansoftConnector.release(arg0.getSession());
}

From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java

@Override
public void sessionCreated(HttpSessionEvent se) {
    logger.debug("HTTP session created: {}", se.getSession().getId());
    sessionCount++;//from  w w w.j a  v a2s .  com
    if (isEventInterceptorActivated("interceptHttpSessionListenerEvents")) {
        SpringContextSingleton.getInstance().publishEvent(new HttpSessionCreatedEvent(se.getSession()));
    }
}

From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java

@Override
public void sessionDestroyed(HttpSessionEvent se) {
    logger.debug("HTTP session destroyed: {}", se.getSession().getId());
    sessionCount--;//www.j  a va  2  s.c o  m
    if (isEventInterceptorActivated("interceptHttpSessionListenerEvents")) {
        SpringContextSingleton.getInstance().publishEvent(new HttpSessionDestroyedEvent(se.getSession()));
    }
}

From source file:org.mifos.framework.ApplicationInitializer.java

@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
    ServletContext ctx = httpSessionEvent.getSession().getServletContext();
    final ShutdownManager shutdownManager = (ShutdownManager) ctx.getAttribute(ShutdownManager.class.getName());
    shutdownManager.sessionCreated(httpSessionEvent);
}

From source file:org.mifos.framework.ApplicationInitializer.java

@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
    ServletContext ctx = httpSessionEvent.getSession().getServletContext();
    final ShutdownManager shutdownManager = (ShutdownManager) ctx.getAttribute(ShutdownManager.class.getName());
    shutdownManager.sessionDestroyed(httpSessionEvent);
}