001 package org.apache.turbine.services.security;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.List;
023
024 import org.apache.commons.configuration.Configuration;
025
026 import org.apache.turbine.om.security.User;
027 import org.apache.turbine.services.InitializationException;
028 import org.apache.turbine.util.security.DataBackendException;
029 import org.apache.turbine.util.security.EntityExistsException;
030 import org.apache.turbine.util.security.PasswordMismatchException;
031 import org.apache.turbine.util.security.UnknownEntityException;
032
033 /**
034 * An UserManager performs {@link org.apache.turbine.om.security.User} objects
035 * related tasks on behalf of the
036 * {@link org.apache.turbine.services.security.BaseSecurityService}.
037 *
038 * The responsibilities of this class include loading data of an user from the
039 * storage and putting them into the
040 * {@link org.apache.turbine.om.security.User} objects, saving those data
041 * to the permanent storage, and authenticating users.
042 *
043 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
044 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
045 * @version $Id: UserManager.java 1096130 2011-04-23 10:37:19Z ludwig $
046 */
047 public interface UserManager
048 {
049 /**
050 * Initializes the UserManager
051 *
052 * @param conf A Configuration object to init this Manager
053 *
054 * @throws InitializationException When something went wrong.
055 */
056 void init(Configuration conf)
057 throws InitializationException;
058
059 /**
060 * Check whether a specified user's account exists.
061 *
062 * The login name is used for looking up the account.
063 *
064 * @param user The user to be checked.
065 * @return true if the specified account exists
066 * @throws DataBackendException if there was an error accessing the data
067 * backend.
068 */
069 boolean accountExists(User user)
070 throws DataBackendException;
071
072 /**
073 * Check whether a specified user's account exists.
074 *
075 * The login name is used for looking up the account.
076 *
077 * @param userName The name of the user to be checked.
078 * @return true if the specified account exists
079 * @throws DataBackendException if there was an error accessing the data
080 * backend.
081 */
082 boolean accountExists(String userName)
083 throws DataBackendException;
084
085 /**
086 * Retrieve a user from persistent storage using username as the
087 * key.
088 *
089 * @param username the name of the user.
090 * @return an User object.
091 * @throws UnknownEntityException if the user's record does not
092 * exist in the database.
093 * @throws DataBackendException if there is a problem accessing the
094 * storage.
095 */
096 User retrieve(String username)
097 throws UnknownEntityException, DataBackendException;
098
099 /**
100 * Retrieve a set of users that meet the specified criteria.
101 *
102 * As the keys for the criteria, you should use the constants that
103 * are defined in {@link User} interface, plus the names
104 * of the custom attributes you added to your user representation
105 * in the data storage. Use verbatim names of the attributes -
106 * without table name prefix in case of DB implementation.
107 *
108 * @param criteria The criteria of selection.
109 * @return a List of users meeting the criteria.
110 * @throws DataBackendException if there is a problem accessing the
111 * storage.
112 * @deprecated Use retrieveList(Criteria crit)
113 */
114 User[] retrieve(Object criteria) throws DataBackendException;
115
116 /**
117 * Retrieve a list of users that meet the specified criteria.
118 *
119 * As the keys for the criteria, you should use the constants that
120 * are defined in {@link User} interface, plus the names
121 * of the custom attributes you added to your user representation
122 * in the data storage. Use verbatim names of the attributes -
123 * without table name prefix in case of DB implementation.
124 *
125 * @param criteria The criteria of selection.
126 * @return a List of users meeting the criteria.
127 * @throws DataBackendException if there is a problem accessing the
128 * storage.
129 */
130 List retrieveList(Object criteria)
131 throws DataBackendException;
132
133 /**
134 * Retrieve a user from persistent storage using username as the
135 * key, and authenticate the user. The implementation may chose
136 * to authenticate to the server as the user whose data is being
137 * retrieved.
138 *
139 * @param username the name of the user.
140 * @param password the user supplied password.
141 * @return an User object.
142 * @throws PasswordMismatchException if the supplied password was incorrect.
143 * @throws UnknownEntityException if the user's record does not
144 * exist in the database.
145 * @throws DataBackendException if there is a problem accessing the storage.
146 */
147 User retrieve(String username, String password)
148 throws PasswordMismatchException, UnknownEntityException,
149 DataBackendException;
150
151 /**
152 * Save an User object to persistent storage. User's record is
153 * required to exist in the storage.
154 *
155 * @param user an User object to store.
156 * @throws UnknownEntityException if the user's record does not
157 * exist in the database.
158 * @throws DataBackendException if there is a problem accessing the storage.
159 */
160 void store(User user)
161 throws UnknownEntityException, DataBackendException;
162
163 /**
164 * Saves User data when the session is unbound. The user account is required
165 * to exist in the storage.
166 *
167 * LastLogin, AccessCounter, persistent pull tools, and any data stored
168 * in the permData hashtable that is not mapped to a column will be saved.
169 *
170 * @exception UnknownEntityException if the user's account does not
171 * exist in the database.
172 * @exception DataBackendException if there is a problem accessing the
173 * storage.
174 */
175 void saveOnSessionUnbind(User user)
176 throws UnknownEntityException, DataBackendException;
177
178 /**
179 * Authenticate an User with the specified password. If authentication
180 * is successful the method returns nothing. If there are any problems,
181 * exception was thrown.
182 *
183 * @param user an User object to authenticate.
184 * @param password the user supplied password.
185 * @throws PasswordMismatchException if the supplied password was incorrect.
186 * @throws UnknownEntityException if the user's record does not
187 * exist in the database.
188 * @throws DataBackendException if there is a problem accessing the storage.
189 */
190 void authenticate(User user, String password)
191 throws PasswordMismatchException, UnknownEntityException,
192 DataBackendException;
193
194 /**
195 * Creates new user account with specified attributes.
196 *
197 * @param user the object describing account to be created.
198 * @param initialPassword password for the new user
199 * @throws DataBackendException if there was an error accessing the data
200 * backend.
201 * @throws EntityExistsException if the user account already exists.
202 */
203 void createAccount(User user, String initialPassword)
204 throws EntityExistsException, DataBackendException;
205
206 /**
207 * Removes an user account from the system.
208 *
209 * @param user the object describing the account to be removed.
210 * @throws DataBackendException if there was an error accessing the data
211 * backend.
212 * @throws UnknownEntityException if the user account is not present.
213 */
214 void removeAccount(User user)
215 throws UnknownEntityException, DataBackendException;
216
217 /**
218 * Change the password for an User.
219 *
220 * @param user an User to change password for.
221 * @param oldPassword the current password suplied by the user.
222 * @param newPassword the current password requested by the user.
223 * @throws PasswordMismatchException if the supplied password was incorrect.
224 * @throws UnknownEntityException if the user's record does not
225 * exist in the database.
226 * @throws DataBackendException if there is a problem accessing the storage.
227 */
228 void changePassword(User user, String oldPassword,
229 String newPassword)
230 throws PasswordMismatchException, UnknownEntityException,
231 DataBackendException;
232
233 /**
234 * Forcibly sets new password for an User.
235 *
236 * This is supposed by the administrator to change the forgotten or
237 * compromised passwords. Certain implementatations of this feature
238 * would require administrative level access to the authenticating
239 * server / program.
240 *
241 * @param user an User to change password for.
242 * @param password the new password.
243 * @throws UnknownEntityException if the user's record does not
244 * exist in the database.
245 * @throws DataBackendException if there is a problem accessing the storage.
246 */
247 void forcePassword(User user, String password)
248 throws UnknownEntityException, DataBackendException;
249 }