KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > authentication > user > UserHandler


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.user;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.cocoon.ProcessingException;
22 import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
23 import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
24 import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
25
26 /**
27  * The authentication Handler.
28  *
29  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
30  * @version CVS $Id: UserHandler.java 37163 2004-08-28 13:05:18Z cziegeler $
31 */

32 public final class UserHandler
33 implements java.io.Serializable JavaDoc {
34
35     /** The corresponding handler */
36     private HandlerConfiguration handler;
37     
38     /** Are all apps loaded? */
39     private boolean appsLoaded = false;
40
41     /** The context */
42     private AuthenticationContext context;
43     
44     /** Loaded List */
45     private List JavaDoc loadedApps = new ArrayList JavaDoc(3);
46     
47     /** Application contexts */
48     private List JavaDoc applicationContexts;
49      
50     /** The unique user ID */
51     private String JavaDoc userID;
52      
53     /**
54      * Create a new handler object.
55      */

56     public UserHandler(HandlerConfiguration handler, AuthenticationContext context) {
57         this.context = context;
58         this.handler = handler;
59         this.context.init(this);
60     }
61
62     /**
63      * Are all application contexts already loaded?
64      */

65     public boolean getApplicationsLoaded() {
66         if ( this.handler.getApplications().isEmpty() ) {
67             return true;
68         }
69         return this.appsLoaded;
70     }
71     
72     /**
73      * Add a handler context
74      */

75     public AuthenticationContext getContext() {
76         return this.context;
77     }
78
79     /**
80      * Get the handler name
81      */

82     public String JavaDoc getHandlerName() {
83         return this.handler.getName();
84     }
85     
86     /**
87      * Get the handler configuration
88      */

89     public HandlerConfiguration getHandlerConfiguration() {
90         return this.handler;
91     }
92     
93     /**
94      * Is the named application context already loaded?
95      */

96     public boolean isApplicationLoaded(ApplicationConfiguration appConf) {
97         return this.loadedApps.contains( appConf );
98     }
99     
100     /**
101      * Notify that the application context has been loaded
102      */

103     public void setApplicationIsLoaded(ApplicationConfiguration appConf) {
104         this.loadedApps.add( appConf );
105         this.appsLoaded = (this.loadedApps.size() == this.handler.getApplications().size());
106     }
107     
108     /**
109      * Get the unique user id
110      */

111     public String JavaDoc getUserId() {
112         if ( null == this.userID) {
113             try {
114                 this.userID = (String JavaDoc) this.context.getContextInfo().get("ID");
115             } catch (ProcessingException ignore) {
116                 this.userID = "";
117             }
118         }
119         return this.userID;
120     }
121     
122     /**
123      * Test if the user has a role
124      * @since 2.1.6
125      */

126     public boolean isUserInRole(String JavaDoc role) {
127         return this.context.isUserInRole(role);
128     }
129     
130     public void addApplicationContext(String JavaDoc name) {
131         if ( this.applicationContexts == null) {
132             this.applicationContexts = new ArrayList JavaDoc(3);
133         }
134         this.applicationContexts.add( name );
135     }
136     
137     /**
138      * Return the list or null.
139      */

140     public List JavaDoc getApplicationContexts() {
141         return this.applicationContexts;
142     }
143 }
144
Popular Tags