1 package org.apache.turbine.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.List;
22
23 import org.apache.commons.configuration.Configuration;
24
25 import org.apache.turbine.om.security.TurbineUser;
26 import org.apache.turbine.om.security.User;
27 import org.apache.turbine.services.security.UserManager;
28 import org.apache.turbine.util.security.DataBackendException;
29 import org.apache.turbine.util.security.EntityExistsException;
30 import org.apache.turbine.util.security.PasswordMismatchException;
31 import org.apache.turbine.util.security.UnknownEntityException;
32
33 /***
34 * This Mock object is used in testing.
35 *
36 * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh</a>
37 * @version $Id: MockUserManager.java 222043 2004-12-06 17:47:33Z painter $
38 */
39 public class MockUserManager implements UserManager
40 {
41 /***
42 * Initializes the UserManager
43 *
44 * @param conf A Configuration object to init this Manager
45 */
46 public void init(Configuration conf)
47 {
48
49 }
50
51 /***
52 * Check whether a specified user's account exists.
53 *
54 * The login name is used for looking up the account.
55 *
56 * @param user The user to be checked.
57 * @return true if the specified account exists
58 * @throws DataBackendException if there was an error accessing the data backend.
59 */
60 public boolean accountExists(User user)
61 throws DataBackendException
62 {
63 return true;
64 }
65
66 /***
67 * Check whether a specified user's account exists.
68 *
69 * The login name is used for looking up the account.
70 *
71 * @param userName The name of the user to be checked.
72 * @return true if the specified account exists
73 * @throws DataBackendException if there was an error accessing the data backend.
74 */
75 public boolean accountExists(String userName)
76 throws DataBackendException
77 {
78 throw new DataBackendException("PassiveUserManager knows no users");
79 }
80
81 /***
82 * Retrieve a user from persistent storage using username as the
83 * key.
84 *
85 * @param username the name of the user.
86 * @return an User object.
87 * @exception UnknownEntityException if the user's record does not
88 * exist in the database.
89 * @exception DataBackendException if there is a problem accessing the
90 * storage.
91 */
92 public User retrieve(String username)
93 throws UnknownEntityException, DataBackendException
94 {
95 throw new DataBackendException("PassiveUserManager knows no users");
96 }
97
98 /***
99 * Retrieve a set of users that meet the specified criteria.
100 *
101 * As the keys for the criteria, you should use the constants that
102 * are defined in {@link User} interface, plus the names
103 * of the custom attributes you added to your user representation
104 * in the data storage. Use verbatim names of the attributes -
105 * without table name prefix in case of DB implementation.
106 *
107 * @param criteria The criteria of selection.
108 * @return a List of users meeting the criteria.
109 * @throws DataBackendException if there is a problem accessing the
110 * storage.
111 * @deprecated Use <a href="#retrieveList">retrieveList</a> instead.
112 */
113 public User[] retrieve(Object criteria)
114 throws DataBackendException
115 {
116 throw new DataBackendException("PassiveUserManager knows no users");
117 }
118
119 /***
120 * Retrieve a set of users that meet the specified criteria.
121 *
122 * As the keys for the criteria, you should use the constants that
123 * are defined in {@link User} interface, plus the names
124 * of the custom attributes you added to your user representation
125 * in the data storage. Use verbatim names of the attributes -
126 * without table name prefix in case of DB implementation.
127 *
128 * @param criteria The criteria of selection.
129 * @return a List of users meeting the criteria.
130 * @throws DataBackendException if there is a problem accessing the
131 * storage.
132 */
133 public List retrieveList(Object criteria)
134 throws DataBackendException
135 {
136 throw new DataBackendException("PassiveUserManager knows no users");
137 }
138
139 /***
140 * Retrieve a user from persistent storage using username as the
141 * key, and authenticate the user. The implementation may chose
142 * to authenticate to the server as the user whose data is being
143 * retrieved.
144 *
145 * @param username the name of the user.
146 * @param password the user supplied password.
147 * @return an User object.
148 * @exception PasswordMismatchException if the supplied password was
149 * incorrect.
150 * @exception UnknownEntityException if the user's record does not
151 * exist in the database.
152 * @exception DataBackendException if there is a problem accessing the
153 * storage.
154 */
155 public User retrieve(String username, String password)
156 throws PasswordMismatchException, UnknownEntityException,
157 DataBackendException
158 {
159 TurbineUser tu = new TurbineUser();
160 tu.setName(username);
161 return tu;
162 }
163
164 /***
165 * Save an User object to persistent storage. User's record is
166 * required to exist in the storage.
167 *
168 * @param user an User object to store.
169 * @exception UnknownEntityException if the user's record does not
170 * exist in the database.
171 * @exception DataBackendException if there is a problem accessing the
172 * storage.
173 */
174 public void store(User user)
175 throws UnknownEntityException, DataBackendException
176 {
177 throw new DataBackendException("PassiveUserManager does not support saving user data");
178 }
179
180 /***
181 * Saves User data when the session is unbound. The user account is required
182 * to exist in the storage.
183 *
184 * LastLogin, AccessCounter, persistent pull tools, and any data stored
185 * in the permData hashtable that is not mapped to a column will be saved.
186 *
187 * @exception UnknownEntityException if the user's account does not
188 * exist in the database.
189 * @exception DataBackendException if there is a problem accessing the
190 * storage.
191 */
192 public void saveOnSessionUnbind(User user)
193 throws UnknownEntityException, DataBackendException
194 {
195 throw new DataBackendException("PassiveUserManager does not support saving user data");
196 }
197
198 /***
199 * Authenticate an User with the specified password. If authentication
200 * is successful the method returns nothing. If there are any problems,
201 * exception was thrown.
202 *
203 * @param user an User object to authenticate.
204 * @param password the user supplied password.
205 * @exception PasswordMismatchException if the supplied password was
206 * incorrect.
207 * @exception UnknownEntityException if the user's record does not
208 * exist in the database.
209 * @exception DataBackendException if there is a problem accessing the
210 * storage.
211 */
212 public void authenticate(User user, String password)
213 throws PasswordMismatchException, UnknownEntityException,
214 DataBackendException
215 {
216 throw new DataBackendException("PassiveUserManager knows no users");
217 }
218
219 /***
220 * Creates new user account with specified attributes.
221 *
222 * @param user the object describing account to be created.
223 * @param initialPassword The password to use for the object creation
224 *
225 * @throws DataBackendException if there was an error accessing the data backend.
226 * @throws EntityExistsException if the user account already exists.
227 */
228 public void createAccount(User user, String initialPassword)
229 throws EntityExistsException, DataBackendException
230 {
231 throw new DataBackendException("PassiveUserManager does not support"
232 + " creating accounts");
233 }
234
235 /***
236 * Removes an user account from the system.
237 *
238 * @param user the object describing the account to be removed.
239 * @throws DataBackendException if there was an error accessing the data backend.
240 * @throws UnknownEntityException if the user account is not present.
241 */
242 public void removeAccount(User user)
243 throws UnknownEntityException, DataBackendException
244 {
245 throw new DataBackendException("PassiveUserManager does not support removing accounts");
246 }
247
248 /***
249 * Change the password for an User.
250 *
251 * @param user an User to change password for.
252 * @param oldPassword the current password supplied by the user.
253 * @param newPassword the current password requested by the user.
254 * @exception PasswordMismatchException if the supplied password was
255 * incorrect.
256 * @exception UnknownEntityException if the user's record does not
257 * exist in the database.
258 * @exception DataBackendException if there is a problem accessing the
259 * storage.
260 */
261 public void changePassword(User user, String oldPassword,
262 String newPassword)
263 throws PasswordMismatchException, UnknownEntityException,
264 DataBackendException
265 {
266 throw new DataBackendException("PassiveUserManager does not support setting passwords");
267 }
268
269 /***
270 * Forcibly sets new password for an User.
271 *
272 * This is supposed by the administrator to change the forgotten or
273 * compromised passwords. Certain implementatations of this feature
274 * would require administrative level access to the authenticating
275 * server / program.
276 *
277 * @param user an User to change password for.
278 * @param password the new password.
279 * @exception UnknownEntityException if the user's record does not
280 * exist in the database.
281 * @exception DataBackendException if there is a problem accessing the
282 * storage.
283 */
284 public void forcePassword(User user, String password)
285 throws UnknownEntityException, DataBackendException
286 {
287 throw new DataBackendException("PassiveUserManager does not support setting passwords");
288 }
289 }