}
// are we logged in?
UserHandler handler = this.getUserHandler( handlerName );
// we don't throw an exception if we are already logged out!
if ( handler != null ) {
UserState status = this.getUserState();
status.removeHandler( handlerName );
this.updateUserState();
// handling of session termination
SessionManager sessionManager = null;
try {
sessionManager = (SessionManager)this.manager.lookup( SessionManager.ROLE );
if ( mode == AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY ) {
sessionManager.terminateSession(true);
} else if ( mode == AuthenticationConstants.LOGOUT_MODE_IF_UNUSED ) {
if ( !status.hasHandler()) {
sessionManager.terminateSession( false );
}
} else if ( mode == AuthenticationConstants.LOGOUT_MODE_IF_NOT_AUTHENTICATED) {
if ( !status.hasHandler()) {
sessionManager.terminateSession( true );
}
} else {
throw new ProcessingException("Unknown logout mode: " + mode);
}