001: /*
002: * Copyright 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.users;
018:
019: import java.util.Iterator;
020: import org.apache.catalina.Group;
021: import org.apache.catalina.Role;
022: import org.apache.catalina.User;
023:
024: /**
025: * <p>Convenience base class for {@link User} implementations.</p>
026: *
027: * @author Craig R. McClanahan
028: * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:50 $
029: * @since 4.1
030: */
031:
032: public abstract class AbstractUser implements User {
033:
034: // ----------------------------------------------------- Instance Variables
035:
036: /**
037: * The full name of this user.
038: */
039: protected String fullName = null;
040:
041: /**
042: * The logon password of this user.
043: */
044: protected String password = null;
045:
046: /**
047: * The logon username of this user.
048: */
049: protected String username = null;
050:
051: // ------------------------------------------------------------- Properties
052:
053: /**
054: * Return the full name of this user.
055: */
056: public String getFullName() {
057:
058: return (this .fullName);
059:
060: }
061:
062: /**
063: * Set the full name of this user.
064: *
065: * @param fullName The new full name
066: */
067: public void setFullName(String fullName) {
068:
069: this .fullName = fullName;
070:
071: }
072:
073: /**
074: * Return the set of {@link Group}s to which this user belongs.
075: */
076: public abstract Iterator getGroups();
077:
078: /**
079: * Return the logon password of this user, optionally prefixed with the
080: * identifier of an encoding scheme surrounded by curly braces, such as
081: * <code>{md5}xxxxx</code>.
082: */
083: public String getPassword() {
084:
085: return (this .password);
086:
087: }
088:
089: /**
090: * Set the logon password of this user, optionally prefixed with the
091: * identifier of an encoding scheme surrounded by curly braces, such as
092: * <code>{md5}xxxxx</code>.
093: *
094: * @param password The new logon password
095: */
096: public void setPassword(String password) {
097:
098: this .password = password;
099:
100: }
101:
102: /**
103: * Return the set of {@link Role}s assigned specifically to this user.
104: */
105: public abstract Iterator getRoles();
106:
107: /**
108: * Return the logon username of this user, which must be unique
109: * within the scope of a {@link UserDatabase}.
110: */
111: public String getUsername() {
112:
113: return (this .username);
114:
115: }
116:
117: /**
118: * Set the logon username of this user, which must be unique within
119: * the scope of a {@link UserDatabase}.
120: *
121: * @param username The new logon username
122: */
123: public void setUsername(String username) {
124:
125: this .username = username;
126:
127: }
128:
129: // --------------------------------------------------------- Public Methods
130:
131: /**
132: * Add a new {@link Group} to those this user belongs to.
133: *
134: * @param group The new group
135: */
136: public abstract void addGroup(Group group);
137:
138: /**
139: * Add a new {@link Role} to those assigned specifically to this user.
140: *
141: * @param role The new role
142: */
143: public abstract void addRole(Role role);
144:
145: /**
146: * Is this user in the specified {@link Group}?
147: *
148: * @param group The group to check
149: */
150: public abstract boolean isInGroup(Group group);
151:
152: /**
153: * Is this user specifically assigned the specified {@link Role}? This
154: * method does <strong>NOT</strong> check for roles inherited based on
155: * {@link Group} membership.
156: *
157: * @param role The role to check
158: */
159: public abstract boolean isInRole(Role role);
160:
161: /**
162: * Remove a {@link Group} from those this user belongs to.
163: *
164: * @param group The old group
165: */
166: public abstract void removeGroup(Group group);
167:
168: /**
169: * Remove all {@link Group}s from those this user belongs to.
170: */
171: public abstract void removeGroups();
172:
173: /**
174: * Remove a {@link Role} from those assigned to this user.
175: *
176: * @param role The old role
177: */
178: public abstract void removeRole(Role role);
179:
180: /**
181: * Remove all {@link Role}s from those assigned to this user.
182: */
183: public abstract void removeRoles();
184:
185: // ------------------------------------------------------ Principal Methods
186:
187: /**
188: * Make the principal name the same as the group name.
189: */
190: public String getName() {
191:
192: return (getUsername());
193:
194: }
195:
196: }
|