Example usage for javax.servlet.http HttpSessionBindingEvent getSession

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

Introduction

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

Prototype

@Override
public HttpSession getSession() 

Source Link

Document

Return the session that changed.

Usage

From source file:com.sslexplorer.security.DefaultLogonController.java

public void initialiseSession(HttpSession session, User user) throws UserDatabaseException {
    if (log.isInfoEnabled())
        log.info("Initialising session " + session.getId() + " with user "
                + (user == null ? "[none]" : user.getPrincipalName()));
    PropertyProfile profile = (PropertyProfile) session.getAttribute(Constants.SELECTED_PROFILE);
    session.setAttribute(Constants.USER, user);
    String logonInfo = MessageResources.getMessageResources("com.sslexplorer.navigation.ApplicationResources")
            .getMessage("footer.info", user.getPrincipalName(),
                    SimpleDateFormat.getDateTimeInstance().format(new Date()));
    session.setAttribute(Constants.LOGON_INFO, logonInfo);
    try {/*from  w ww  .  j av  a 2  s  .c  o  m*/
        List profiles = ResourceUtil.filterResources(user, ProfilesFactory.getInstance()
                .getPropertyProfiles(user.getPrincipalName(), true, user.getRealm().getResourceId()), true);
        session.setAttribute(Constants.PROFILES, profiles);
        if (profiles.size() == 0) {
            throw new UserDatabaseException("You do not have permission to use any profiles.");
        }
        String startupProfile = Property.getProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE));
        if (profiles.size() < 2) {
            profile = (PropertyProfile) profiles.get(0);
        } else if (!startupProfile.equals(ProfilesListDataSource.SELECT_ON_LOGIN)) {
            int profileId = Integer.parseInt(startupProfile);
            profile = null;
            for (Iterator i = profiles.iterator(); i.hasNext();) {
                PropertyProfile p = (PropertyProfile) i.next();
                if (profileId == p.getResourceId()) {
                    profile = p;
                    break;
                }
            }
            if (profile == null) {
                profile = ProfilesFactory.getInstance().getPropertyProfile(null, "Default",
                        UserDatabaseManager.getInstance().getDefaultUserDatabase().getRealm().getResourceId());
            }
        }
        if (profile != null) {
            if (log.isInfoEnabled())
                log.info("Switching user " + user.getPrincipalName() + " to profile "
                        + profile.getResourceName());
            session.setAttribute(Constants.SELECTED_PROFILE, profile);
        }
    } catch (Exception e) {
        throw new UserDatabaseException("Failed to initialise profiles.", e);
    }
    final String logonTicket = (String) session.getAttribute(Constants.LOGON_TICKET);
    session.setAttribute(Constants.LOGOFF_HOOK, new HttpSessionBindingListener() {
        public void valueBound(HttpSessionBindingEvent evt) {
        }

        public void valueUnbound(HttpSessionBindingEvent evt) {
            if (log.isDebugEnabled())
                log.debug("Session unbound");
            // We should should only log off completely if no other
            // session has
            // the logon ticket
            SessionInfo currentTicketSessionInfo = ((SessionInfo) logons.get(logonTicket));
            if (currentTicketSessionInfo == null
                    || evt.getSession().getId().equals(currentTicketSessionInfo.getHttpSession().getId())) {
                if (log.isDebugEnabled())
                    log.debug("Session (" + evt.getSession().getId()
                            + ") unbound is the current session for ticket " + logonTicket
                            + " so a logoff will be performed.");
                logoff(logonTicket);
            } else {
                if (log.isDebugEnabled())
                    log.debug("Session unbound is NOT the current session, ignoring.");
            }
        }
    });
    if (log.isDebugEnabled())
        log.debug("Using profile: " + (profile == null ? "DEFAULT" : profile.getResourceName()) + ")");
    session.removeAttribute(Constants.SESSION_LOCKED);

    resetSessionTimeout(user, profile, session);
}

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

/**
 * Handles the case when a special session attribute is added. If an attribute added (manually or
 * when restoring a persistent session) with name starting with
 * {@link CasHttpSessionActivationListener#SESSION_ATTR_NAME_SERVICE_PID_PREFIX} this listener
 * method will:/*  ww w .ja  v  a2 s.  co  m*/
 * <ul>
 * <li>Register a {@link CasHttpSessionActivationListener} instance to the session and remove the
 * added session attribute if the {@link CasHttpSessionActivationListener} IS NOT REGISTERED to
 * the session already with the Service PID stored in the session. This is necessary to
 * re-register the EventListener when a session is restored from its persistent state.</li>
 * <li>Remove the {@link CasHttpSessionActivationListener} instance from the session if the
 * {@link CasHttpSessionActivationListener} IS REGISTERED to the session already with the Service
 * PID stored in the session. This is necessary to remove the EventListener from the session
 * before it will be Serialized, because the {@link CasHttpSessionActivationListener} is not
 * {@link java.io.Serializable} and cannot be instantiated/deserialized by a non-OSGi technology
 * </li>
 * </ul>
 */
@Override
public void attributeAdded(final HttpSessionBindingEvent event) {
    String addedAttributeName = event.getName();
    if (addedAttributeName.startsWith(CasHttpSessionActivationListener.SESSION_ATTR_NAME_SERVICE_PID_PREFIX)) {

        String servicePid = (String) event.getValue();
        String casHttpSessionActivationListenerSessionAttrName = CasHttpSessionActivationListener
                .createSessionAttrNameInstance(servicePid);

        HttpSession httpSession = event.getSession();
        if (httpSession.getAttribute(casHttpSessionActivationListenerSessionAttrName) == null) {

            CasHttpSessionActivationListener.registerInstance(servicePid, httpSession);
            String attributeNameToRemove = CasHttpSessionActivationListener
                    .createSessionAttrNameServicePid(servicePid);
            if (attributeNameToRemove.equals(addedAttributeName)) {
                httpSession.removeAttribute(attributeNameToRemove);
            }
        } else {
            CasHttpSessionActivationListener.removeInstance(servicePid, httpSession);
        }
    }
}

From source file:org.h3270.web.SessionState.java

public void valueUnbound(HttpSessionBindingEvent event) {
    // disconnect all s3270 sessions when the HttpSession times out and release
    // associated logical units in the pool
    for (Iterator i = terminalStates.iterator(); i.hasNext();) {
        TerminalState ts = (TerminalState) i.next();
        if (ts.getTerminal() != null && ts.getTerminal().isConnected()) {
            if (logger.isInfoEnabled())
                logger.info("Session unbound, disconnecting terminal " + ts.getTerminal());
            ts.getTerminal().disconnect();

            String logicalUnit = ts.getTerminal().getLogicalUnit();
            if (logicalUnit != null) {
                ServletContext servletContext = event.getSession().getServletContext();
                LogicalUnitPool pool = (LogicalUnitPool) servletContext
                        .getAttribute(LogicalUnitPool.SERVLET_CONTEXT_KEY);
                pool.releaseLogicalUnit(logicalUnit);
            }/*from  w w w.ja  v  a2 s  .c  o  m*/
        }
    }
}

From source file:org.projectforge.web.debug.SessionSerializableChecker.java

/**
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
 *//*from  w  w  w.ja va  2s  . com*/
public void attributeAdded(final HttpSessionBindingEvent evt) {
    if (WebConfiguration.isDevelopmentMode() == true) {
        check(evt.getSession(), evt.getName(), evt.getValue());
    }
}

From source file:org.projectforge.web.debug.SessionSerializableChecker.java

/**
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
 *///from  w ww.j  a v a  2s .  co  m
public void attributeReplaced(final HttpSessionBindingEvent evt) {
    if (WebConfiguration.isDevelopmentMode() == true) {
        check(evt.getSession(), evt.getName(), evt.getValue());
    }
}