KickJava   Java API By Example, From Geeks To Geeks.

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


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.acting.ServiceableAction;
23 import org.apache.cocoon.environment.Redirector;
24 import org.apache.cocoon.environment.SourceResolver;
25 import org.apache.cocoon.webapps.authentication.AuthenticationManager;
26 import org.apache.cocoon.webapps.authentication.user.UserHandler;
27
28 /**
29  * This action tests if the user is logged in for a given handler.
30  *
31  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
32  * @version CVS $Id: LoggedInAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
33 */

34 public final class LoggedInAction
35 extends ServiceableAction
36 implements ThreadSafe {
37
38     public Map JavaDoc act(Redirector redirector,
39                    SourceResolver resolver,
40                    Map JavaDoc objectModel,
41                    String JavaDoc source,
42                    Parameters par)
43     throws Exception JavaDoc {
44         if (this.getLogger().isDebugEnabled() ) {
45             this.getLogger().debug("BEGIN act resolver="+resolver+
46                                    ", objectModel="+objectModel+
47                                    ", source="+source+
48                                    ", par="+par);
49         }
50
51         Map JavaDoc map = null;
52         String JavaDoc handlerName = par.getParameter("handler", null);
53         AuthenticationManager authManager = null;
54
55         final boolean testNotLoggedIn = par.getParameterAsBoolean("negate-result", false);
56         
57         try {
58             authManager = (AuthenticationManager) this.manager.lookup(AuthenticationManager.ROLE);
59             UserHandler handler = authManager.isAuthenticated(handlerName);
60             if ( testNotLoggedIn ) {
61                 if ( handler == null ) {
62                     map = EMPTY_MAP;
63                 }
64             } else {
65                 if ( handler != null ) {
66                     map = EMPTY_MAP;
67                 }
68             }
69         } finally {
70             this.manager.release( authManager);
71         }
72
73         if (this.getLogger().isDebugEnabled() ) {
74             this.getLogger().debug("END act map="+map);
75         }
76
77         return map;
78     }
79
80 }
81
Popular Tags