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