1 16 package org.apache.cocoon.webapps.authentication.acting; 17 18 import java.util.Map ; 19 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.cocoon.ProcessingException; 23 import org.apache.cocoon.acting.ServiceableAction; 24 import org.apache.cocoon.environment.Redirector; 25 import org.apache.cocoon.environment.SourceResolver; 26 import org.apache.cocoon.webapps.authentication.AuthenticationConstants; 27 import org.apache.cocoon.webapps.authentication.AuthenticationManager; 28 import org.apache.cocoon.webapps.authentication.user.RequestState; 29 30 36 public final class LogoutAction 37 extends ServiceableAction 38 implements ThreadSafe { 39 40 public Map act(Redirector redirector, 41 SourceResolver resolver, 42 Map objectModel, 43 String source, 44 Parameters par) 45 throws Exception { 46 if (this.getLogger().isDebugEnabled() ) { 47 this.getLogger().debug("BEGIN act resolver="+resolver+ 48 ", objectModel="+objectModel+ 49 ", source="+source+ 50 ", par="+par); 51 } 52 53 int mode; 54 final String modeString = par.getParameter("mode", "if-not-authenticated"); 55 if ( modeString.equals("if-not-authenticated") ) { 56 mode = AuthenticationConstants.LOGOUT_MODE_IF_NOT_AUTHENTICATED; 57 } else if ( modeString.equalsIgnoreCase("if-unused") ) { 58 mode = AuthenticationConstants.LOGOUT_MODE_IF_UNUSED; 59 } else if ( modeString.equalsIgnoreCase("immediately") ) { 60 mode = AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY; 61 } else { 62 throw new ProcessingException("Unknown mode " + modeString); 63 } 64 65 AuthenticationManager authManager = null; 67 try { 68 authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE); 69 RequestState state = authManager.getState(); 70 71 final String handlerName = par.getParameter("handler", 72 (state == null ? null : state.getHandlerName())); 73 if ( null == handlerName ) { 74 throw new ProcessingException("LogoutAction requires at least the handler parameter."); 75 } 76 authManager.logout( handlerName , mode ); 77 } finally { 78 this.manager.release( authManager ); 79 } 80 81 if (this.getLogger().isDebugEnabled() ) { 82 this.getLogger().debug("END act map={}"); 83 } 84 85 return EMPTY_MAP; 86 } 87 88 } 89 | Popular Tags |