KickJava   Java API By Example, From Geeks To Geeks.

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


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.RequestState;
27
28 /**
29  * This is the authentication action
30  * This action contains the complete configuration for the authentication
31  * Manager. During configuration the AuthenticationManager class gets this
32  * configuration to configure the instances properly.
33  * The main task of this action is to check if the user is authenticated
34  * using a handler. If not a redirect takes place.
35  *
36  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
37  * @version CVS $Id: AuthAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
38 */

39 public final class AuthAction
40 extends ServiceableAction
41 implements ThreadSafe {
42
43     public Map JavaDoc act(Redirector redirector,
44                    SourceResolver resolver,
45                    Map JavaDoc objectModel,
46                    String JavaDoc source,
47                    Parameters par)
48     throws Exception JavaDoc {
49         if (this.getLogger().isDebugEnabled() ) {
50             this.getLogger().debug("BEGIN act resolver="+resolver+
51                                    ", objectModel="+objectModel+
52                                    ", source="+source+
53                                    ", par="+par);
54         }
55         String JavaDoc handlerName = null;
56         String JavaDoc applicationName = null;
57         AuthenticationManager authManager = null;
58         Map JavaDoc map = null;
59
60         try {
61             handlerName = par.getParameter("handler", null);
62             applicationName = par.getParameter("application", null);
63
64             authManager = (AuthenticationManager) this.manager.lookup( AuthenticationManager.ROLE );
65
66             // do authentication
67
if ( !authManager.checkAuthentication(redirector, handlerName, applicationName) ) {
68                 // All events are ignored
69
// the sitemap.xsl ensures that only the redirect is processed
70
} else {
71                 RequestState state = authManager.getState();
72                 map = state.getHandler().getContext().getContextInfo();
73             }
74         } finally {
75             this.manager.release( authManager );
76         }
77         if (this.getLogger().isDebugEnabled() ) {
78             this.getLogger().debug("END act map="+map);
79         }
80         return map;
81     }
82
83 }
84
Popular Tags