use of javax.servlet.http.HttpSessionBindingListener in project felix by apache.
the class HttpSessionWrapper method removeAttribute.
@Override
public void removeAttribute(final String name) {
this.checkInvalid();
final Object oldValue = this.getAttribute(name);
if (oldValue != null) {
this.delegate.removeAttribute(this.getKey(name));
if (oldValue instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name));
}
if (this.context.getHttpSessionAttributeListener() != null) {
this.context.getHttpSessionAttributeListener().attributeRemoved(new HttpSessionBindingEvent(this, name, oldValue));
}
}
}
use of javax.servlet.http.HttpSessionBindingListener in project shiro by apache.
the class ShiroHttpSession method afterUnbound.
protected void afterUnbound(String s, Object o) {
if (o instanceof HttpSessionBindingListener) {
HttpSessionBindingListener listener = (HttpSessionBindingListener) o;
HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, s, o);
listener.valueUnbound(event);
}
}
use of javax.servlet.http.HttpSessionBindingListener in project shiro by apache.
the class ShiroHttpSession method afterBound.
protected void afterBound(String s, Object o) {
if (o instanceof HttpSessionBindingListener) {
HttpSessionBindingListener listener = (HttpSessionBindingListener) o;
HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, s, o);
listener.valueBound(event);
}
}
use of javax.servlet.http.HttpSessionBindingListener in project polymap4-core by Polymap4.
the class WebDavServer method createNewSession.
/**
* Initializes a new session for the given user.
* <p/>
* This method is called by {@link SecurityManagerAdapter}
*
* @param user
* @return The specified user.
*/
public static Principal createNewSession(final Principal user) {
HttpServletRequest req = io.milton.servlet.ServletRequest.getRequest();
final HttpSession session = req.getSession();
// HTTP session timeout: 30min
session.setMaxInactiveInterval(30 * 60);
FsPlugin.getDefault().sessionContextProvider.mapContext(user.getName(), true);
final SessionContext sessionContext = SessionContext.current();
// ContentManager
Locale locale = req.getLocale();
sessionContext.setAttribute("contentManager", ContentManager.forUser(user.getName(), locale, sessionContext));
// invalidate HTTP session when context is destroyed
sessionContext.addSessionListener(new ISessionListener() {
public void beforeDestroy() {
log.info("SessionContext is destroyed -> invalidating HTTP session");
try {
// sessionContext.removeSessionListener( this );
session.invalidate();
} catch (Exception e) {
log.warn("HTTP session already invalidated: " + e);
}
}
});
// session destroy listener
session.setAttribute("sessionListener", new HttpSessionBindingListener() {
public void valueBound(HttpSessionBindingEvent ev) {
}
public void valueUnbound(HttpSessionBindingEvent ev) {
//
sessionContext.execute(new Runnable() {
public void run() {
ContentManager.releaseSession(user.getName());
}
});
// prevent life-lock
if (!sessionContext.isDestroyed() && sessionContext.getAttribute("destroying") == null) {
sessionContext.setAttribute("destroying", true);
FsPlugin.getDefault().sessionContextProvider.destroyContext(sessionContext.getSessionKey());
log.info("HTTP Session destroyed: " + session.getId() + ", user: " + user);
}
}
});
log.info("New HTTP session: " + session.getId() + ", user: " + user);
return user;
}
use of javax.servlet.http.HttpSessionBindingListener in project tomcat70 by apache.
the class StandardSessionContext method setAttribute.
/**
* Bind an object to this session, using the specified name. If an object
* of the same name is already bound to this session, the object is
* replaced.
* <p>
* After this method executes, and if the object implements
* <code>HttpSessionBindingListener</code>, the container calls
* <code>valueBound()</code> on the object.
*
* @param name Name to which the object is bound, cannot be null
* @param value Object to be bound, cannot be null
* @param notify whether to notify session listeners
* @exception IllegalArgumentException if an attempt is made to add a
* non-serializable object in an environment marked distributable.
* @exception IllegalStateException if this method is called on an
* invalidated session
*/
public void setAttribute(String name, Object value, boolean notify) {
// Name cannot be null
if (name == null)
throw new IllegalArgumentException(sm.getString("standardSession.setAttribute.namenull"));
// Null value is the same as removeAttribute()
if (value == null) {
removeAttribute(name);
return;
}
// Validate our current state
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.setAttribute.ise", getIdInternal()));
}
if ((manager != null) && ((Context) manager.getContainer()).getDistributable() && !isAttributeDistributable(name, value) && !exclude(name, value)) {
throw new IllegalArgumentException(sm.getString("standardSession.setAttribute.iae", name));
}
// Construct an event with the new value
HttpSessionBindingEvent event = null;
// Call the valueBound() method if necessary
if (notify && value instanceof HttpSessionBindingListener) {
// Don't call any notification if replacing with the same value
Object oldValue = attributes.get(name);
if (value != oldValue) {
event = new HttpSessionBindingEvent(getSession(), name, value);
try {
((HttpSessionBindingListener) value).valueBound(event);
} catch (Throwable t) {
manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
}
}
}
// Replace or add this attribute
Object unbound = attributes.put(name, value);
// Call the valueUnbound() method if necessary
if (notify && (unbound != null) && (unbound != value) && (unbound instanceof HttpSessionBindingListener)) {
try {
((HttpSessionBindingListener) unbound).valueUnbound(new HttpSessionBindingEvent(getSession(), name));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
}
}
if (!notify)
return;
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object[] listeners = context.getApplicationEventListeners();
if (listeners == null)
return;
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionAttributeListener))
continue;
HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i];
try {
if (unbound != null) {
context.fireContainerEvent("beforeSessionAttributeReplaced", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(), name, unbound);
}
listener.attributeReplaced(event);
context.fireContainerEvent("afterSessionAttributeReplaced", listener);
} else {
context.fireContainerEvent("beforeSessionAttributeAdded", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(), name, value);
}
listener.attributeAdded(event);
context.fireContainerEvent("afterSessionAttributeAdded", listener);
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
if (unbound != null) {
context.fireContainerEvent("afterSessionAttributeReplaced", listener);
} else {
context.fireContainerEvent("afterSessionAttributeAdded", listener);
}
} catch (Exception e) {
// Ignore
}
manager.getContainer().getLogger().error(sm.getString("standardSession.attributeEvent"), t);
}
}
}
Aggregations