001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webapps.authentication.user;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.cocoon.ProcessingException;
023: import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
024: import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
025: import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
026:
027: /**
028: * The authentication Handler.
029: *
030: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
031: * @deprecated This block is deprecated and will be removed in future versions.
032: * @version CVS $Id: UserHandler.java 433543 2006-08-22 06:22:54Z crossley $
033: */
034: public final class UserHandler implements java.io.Serializable {
035:
036: /** The corresponding handler */
037: private HandlerConfiguration handler;
038:
039: /** Are all apps loaded? */
040: private boolean appsLoaded = false;
041:
042: /** The context */
043: private AuthenticationContext context;
044:
045: /** Loaded List */
046: private List loadedApps = new ArrayList(3);
047:
048: /** Application contexts */
049: private List applicationContexts;
050:
051: /** The unique user ID */
052: private String userID;
053:
054: /**
055: * Create a new handler object.
056: */
057: public UserHandler(HandlerConfiguration handler,
058: AuthenticationContext context) {
059: this .context = context;
060: this .handler = handler;
061: this .context.init(this );
062: }
063:
064: /**
065: * Are all application contexts already loaded?
066: */
067: public boolean getApplicationsLoaded() {
068: if (this .handler.getApplications().isEmpty()) {
069: return true;
070: }
071: return this .appsLoaded;
072: }
073:
074: /**
075: * Add a handler context
076: */
077: public AuthenticationContext getContext() {
078: return this .context;
079: }
080:
081: /**
082: * Get the handler name
083: */
084: public String getHandlerName() {
085: return this .handler.getName();
086: }
087:
088: /**
089: * Get the handler configuration
090: */
091: public HandlerConfiguration getHandlerConfiguration() {
092: return this .handler;
093: }
094:
095: /**
096: * Is the named application context already loaded?
097: */
098: public boolean isApplicationLoaded(ApplicationConfiguration appConf) {
099: return this .loadedApps.contains(appConf);
100: }
101:
102: /**
103: * Notify that the application context has been loaded
104: */
105: public void setApplicationIsLoaded(ApplicationConfiguration appConf) {
106: this .loadedApps.add(appConf);
107: this .appsLoaded = (this .loadedApps.size() == this .handler
108: .getApplications().size());
109: }
110:
111: /**
112: * Get the unique user id
113: */
114: public String getUserId() {
115: if (null == this .userID) {
116: try {
117: this .userID = (String) this .context.getContextInfo()
118: .get("ID");
119: } catch (ProcessingException ignore) {
120: this .userID = "";
121: }
122: }
123: return this .userID;
124: }
125:
126: /**
127: * Test if the user has a role
128: * @since 2.1.6
129: */
130: public boolean isUserInRole(String role) {
131: return this .context.isUserInRole(role);
132: }
133:
134: public void addApplicationContext(String name) {
135: if (this .applicationContexts == null) {
136: this .applicationContexts = new ArrayList(3);
137: }
138: this .applicationContexts.add(name);
139: }
140:
141: /**
142: * Return the list or null.
143: */
144: public List getApplicationContexts() {
145: return this.applicationContexts;
146: }
147: }
|