KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > authentication > acting > LogoutAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.webapps.authentication.acting;
17
18 import java.util.Map JavaDoc;
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 /**
31  * This action logs the current user out of a given handler
32  *
33  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
34  * @version CVS $Id: LogoutAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
35 */

36 public final class LogoutAction
37 extends ServiceableAction
38 implements ThreadSafe {
39
40     public Map JavaDoc act(Redirector redirector,
41                    SourceResolver resolver,
42                    Map JavaDoc objectModel,
43                    String JavaDoc source,
44                    Parameters par)
45     throws Exception JavaDoc {
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 JavaDoc 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         // logout
66
AuthenticationManager authManager = null;
67         try {
68             authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE);
69             RequestState state = authManager.getState();
70             
71             final String JavaDoc 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