/* CubusSessionListener.java
Copyright (c) 2009 Juergen Schlierf, All Rights Reserved
This file is part of Cubusmail (http://code.google.com/p/cubusmail/).
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Cubusmail. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cubusmail.server.services;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.cubusmail.server.mail.IMailbox;
import com.cubusmail.server.mail.SessionManager;
/**
* Force a mailbox logout if session expires.
*
* @author Juergen Schlierf
*/
public class CubusSessionListener implements HttpSessionListener {
private final Log log = LogFactory.getLog( getClass() );
/*
* (non-Javadoc)
*
* @see
* javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http
* .HttpSessionEvent)
*/
public void sessionCreated( HttpSessionEvent event ) {
}
/*
* (non-Javadoc)
*
* @see
* javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet
* .http.HttpSessionEvent)
*/
public void sessionDestroyed( HttpSessionEvent event ) {
try {
log.debug( "Session expired. Execute logout." );
if ( SessionManager.get( event.getSession() ) != null ) {
IMailbox mailbox = SessionManager.get( event.getSession() ).getMailbox();
if ( mailbox != null && mailbox.isLoggedIn() ) {
mailbox.logout();
}
}
}
catch (Throwable ex) {
// nothing to do
log.warn( ex.getMessage() );
}
}
}