Example usage for javax.servlet.http HttpSessionBindingEvent getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name with which the attribute is bound to or unbound from the session.

Usage

From source file:org.musicrecital.webapp.listener.UserCounterListener.java

/**
 * Needed for Acegi Security 1.0, as it adds an anonymous user to the session and
 * then replaces it after authentication. http://forum.springframework.org/showthread.php?p=63593
 *
 * @param event the session binding event
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
 */// w  w  w . j a  v a  2s.c  o  m
public void attributeReplaced(HttpSessionBindingEvent event) {
    if (event.getName().equals(EVENT_KEY) && !isAnonymous()) {
        final SecurityContext securityContext = (SecurityContext) event.getValue();
        if (securityContext.getAuthentication() != null
                && securityContext.getAuthentication().getPrincipal() instanceof User) {
            final User user = (User) securityContext.getAuthentication().getPrincipal();
            addUsername(user);
        }
    }
}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was added.
 *
 * @param event The session attribute event
 *//* w  w  w  .j av a 2  s .com*/
public void attributeAdded(HttpSessionBindingEvent event) {

    log("attributeAdded('" + event.getSession().getId() + "', '" + event.getName() + "', '" + event.getValue()
            + "')");

}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was removed.
 *
 * @param event The session attribute event
 */// w w w.j a v a  2 s.co  m
public void attributeRemoved(HttpSessionBindingEvent event) {

    log("attributeRemoved('" + event.getSession().getId() + "', '" + event.getName() + "', '" + event.getValue()
            + "')");

}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was replaced.
 *
 * @param event The session attribute event
 *///from   w ww .  ja  va  2 s.com
public void attributeReplaced(HttpSessionBindingEvent event) {

    log("attributeReplaced('" + event.getSession().getId() + "', '" + event.getName() + "', '"
            + event.getValue() + "')");

}

From source file:alpha.portal.webapp.listener.UserCounterListener.java

/**
 * This method is designed to catch when user's login and record their name.
 * //from www .j  a  va 2 s. c o  m
 * @param event
 *            the event to process
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
 */
public void attributeAdded(final HttpSessionBindingEvent event) {
    if (event.getName().equals(UserCounterListener.EVENT_KEY) && !this.isAnonymous()) {
        final SecurityContext securityContext = (SecurityContext) event.getValue();
        if (securityContext.getAuthentication().getPrincipal() instanceof User) {
            final User user = (User) securityContext.getAuthentication().getPrincipal();
            this.addUsername(user);
        }
    }
}

From source file:alpha.portal.webapp.listener.UserCounterListener.java

/**
 * When user's logout, remove their name from the hashMap.
 * //  w w  w .ja  v  a2  s .  c  o m
 * @param event
 *            the session binding event
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)
 */
public void attributeRemoved(final HttpSessionBindingEvent event) {
    if (event.getName().equals(UserCounterListener.EVENT_KEY) && !this.isAnonymous()) {
        final SecurityContext securityContext = (SecurityContext) event.getValue();
        final Authentication auth = securityContext.getAuthentication();
        if ((auth != null) && (auth.getPrincipal() instanceof User)) {
            final User user = (User) auth.getPrincipal();
            this.removeUsername(user);
        }
    }
}

From source file:alpha.portal.webapp.listener.UserCounterListener.java

/**
 * Needed for Acegi Security 1.0, as it adds an anonymous user to the
 * session and then replaces it after authentication.
 * http://forum.springframework.org/showthread.php?p=63593
 * //from w  ww . ja va 2  s . co  m
 * @param event
 *            the session binding event
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
 */
public void attributeReplaced(final HttpSessionBindingEvent event) {
    if (event.getName().equals(UserCounterListener.EVENT_KEY) && !this.isAnonymous()) {
        final SecurityContext securityContext = (SecurityContext) event.getValue();
        if ((securityContext.getAuthentication() != null)
                && (securityContext.getAuthentication().getPrincipal() instanceof User)) {
            final User user = (User) securityContext.getAuthentication().getPrincipal();
            this.addUsername(user);
        }
    }
}

From source file:com.github.javaplugs.jsf.ViewScope.java

@Override
public void valueBound(HttpSessionBindingEvent event) {
    logger.trace("Session event bound " + event.getName());
}

From source file:com.github.javaplugs.jsf.ViewScope.java

/**
 * Seems like it called after our listeners was unbounded from http session.
 * Looks like view scope it destroyed. But should we call callback or not is a big question.
 *
 * @see HttpSessionBindingListener for more details
 */// w ww  .  j a  v  a2 s  . c  o m
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
    logger.trace("Session event unbound " + event.getName());
    final Set<ViewScopeViewMapListener> listeners;
    synchronized (sessionToListeners) {
        if (sessionToListeners.containsKey(event.getSession())) {
            listeners = sessionToListeners.get(event.getSession());
            sessionToListeners.remove(event.getSession());
        } else {
            listeners = null;
        }
    }
    if (listeners != null) {
        // I just hope that JSF context already done this job
        for (ViewScopeViewMapListener listener : listeners) {
            // As long as our callbacks can run only once - this is not such big deal
            listener.doCallback();
        }
    }
}

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testDestroyHttpSessionWithListener(StandardManager manager) throws Exception {
    WADIHttpSession session = (WADIHttpSession) manager.create(null);
    HttpSession wrapper = session.getWrapper();

    String key = "foo";
    Object val = new Listener();
    wrapper.setAttribute(key, val);
    wrapper.setAttribute("bar", "baz");
    events.clear();/* ww  w  .ja v  a 2 s.  c  om*/

    session.destroy();

    assertTrue(events.size() == 4);
    {
        Pair pair = (Pair) events.get(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueUnbound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    {
        Pair pair = (Pair) events.get(2);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    {
        Pair pair = (Pair) events.get(3);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("sessionDestroyed"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    events.clear();
}