org.apache.turbine.services.security.torque
Class TorqueUserManager

java.lang.Object
  extended byorg.apache.turbine.services.security.torque.TorqueUserManager
All Implemented Interfaces:
UserManager
Direct Known Subclasses:
DBUserManager

public class TorqueUserManager
extends java.lang.Object
implements UserManager

An UserManager performs User objects related tasks on behalf of the BaseSecurityService. This implementation uses a relational database for storing user data. It expects that the User interface implementation will be castable to BaseObject.

Version:
$Id: TorqueUserManager.java 534527 2007-05-02 16:10:59Z tv $
Author:
Jon S. Stevens, John D. McNally, Frank Y. Kim, Craig D. Berry, Rafal Krzewski, Henning P. Schmiedehausen

Constructor Summary
TorqueUserManager()
           
 
Method Summary
 boolean accountExists(java.lang.String userName)
          Check whether a specified user's account exists.
 boolean accountExists(User user)
          Check whether a specified user's account exists.
 void authenticate(User user, java.lang.String password)
          Authenticate an User with the specified password.
 void changePassword(User user, java.lang.String oldPassword, java.lang.String newPassword)
          Change the password for an User.
 void createAccount(User user, java.lang.String initialPassword)
          Creates new user account with specified attributes.
 void forcePassword(User user, java.lang.String password)
          Forcibly sets new password for an User.
 void init(org.apache.commons.configuration.Configuration conf)
          Initializes the UserManager
 void removeAccount(User user)
          Removes an user account from the system.
 User[] retrieve(org.apache.torque.util.Criteria criteria)
          Retrieve a set of users that meet the specified criteria.
 User retrieve(java.lang.String userName)
          Retrieve a user from persistent storage using username as the key.
 User retrieve(java.lang.String userName, java.lang.String password)
          Retrieve a user from persistent storage using username as the key, and authenticate the user.
 User retrieveById(java.lang.Object key)
          Retrieve a user from persistent storage using the primary key
 java.util.List retrieveList(org.apache.torque.util.Criteria criteria)
          Retrieve a list of users that meet the specified criteria.
 void saveOnSessionUnbind(User user)
          Saves User data when the session is unbound.
 void store(User user)
          Save an User object to persistent storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TorqueUserManager

public TorqueUserManager()
Method Detail

init

public void init(org.apache.commons.configuration.Configuration conf)
          throws InitializationException
Initializes the UserManager

Specified by:
init in interface UserManager
Parameters:
conf - A Configuration object to init this Manager
Throws:
InitializationException - When something went wrong.

accountExists

public boolean accountExists(User user)
                      throws DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.

Specified by:
accountExists in interface UserManager
Parameters:
user - The user to be checked.
Returns:
true if the specified account exists
Throws:
DataBackendException - if there was an error accessing the data backend.

accountExists

public boolean accountExists(java.lang.String userName)
                      throws DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.

Specified by:
accountExists in interface UserManager
Parameters:
userName - The name of the user to be checked.
Returns:
true if the specified account exists
Throws:
DataBackendException - if there was an error accessing the data backend.

retrieve

public User retrieve(java.lang.String userName)
              throws UnknownEntityException,
                     DataBackendException
Retrieve a user from persistent storage using username as the key.

Specified by:
retrieve in interface UserManager
Parameters:
userName - the name of the user.
Returns:
an User object.
Throws:
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

retrieveById

public User retrieveById(java.lang.Object key)
                  throws UnknownEntityException,
                         DataBackendException
Retrieve a user from persistent storage using the primary key

Specified by:
retrieveById in interface UserManager
Parameters:
key - The primary key object
Returns:
an User object.
Throws:
UnknownEntityException - if the user's record does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

retrieve

public User[] retrieve(org.apache.torque.util.Criteria criteria)
                throws DataBackendException
Deprecated. Use retrieveList instead.

Description copied from interface: UserManager
Retrieve a set of users that meet the specified criteria. As the keys for the criteria, you should use the constants that are defined in User interface, plus the names of the custom attributes you added to your user representation in the data storage. Use verbatim names of the attributes - without table name prefix in case of DB implementation.

Specified by:
retrieve in interface UserManager
Parameters:
criteria - The criteria of selection.
Returns:
a List of users meeting the criteria.
Throws:
DataBackendException - if there is a problem accessing the storage.

retrieveList

public java.util.List retrieveList(org.apache.torque.util.Criteria criteria)
                            throws DataBackendException
Retrieve a list of users that meet the specified criteria. As the keys for the criteria, you should use the constants that are defined in User interface, plus the names of the custom attributes you added to your user representation in the data storage. Use verbatim names of the attributes - without table name prefix in case of Torque implementation.

Specified by:
retrieveList in interface UserManager
Parameters:
criteria - The criteria of selection.
Returns:
a List of users meeting the criteria.
Throws:
DataBackendException - if there is a problem accessing the storage.

retrieve

public User retrieve(java.lang.String userName,
                     java.lang.String password)
              throws PasswordMismatchException,
                     UnknownEntityException,
                     DataBackendException
Retrieve a user from persistent storage using username as the key, and authenticate the user. The implementation may chose to authenticate to the server as the user whose data is being retrieved.

Specified by:
retrieve in interface UserManager
Parameters:
userName - the name of the user.
password - the user supplied password.
Returns:
an User object.
Throws:
PasswordMismatchException - if the supplied password was incorrect.
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

store

public void store(User user)
           throws UnknownEntityException,
                  DataBackendException
Save an User object to persistent storage. User's account is required to exist in the storage.

Specified by:
store in interface UserManager
Parameters:
user - an User object to store.
Throws:
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

saveOnSessionUnbind

public void saveOnSessionUnbind(User user)
                         throws UnknownEntityException,
                                DataBackendException
Saves User data when the session is unbound. The user account is required to exist in the storage. LastLogin, AccessCounter, persistent pull tools, and any data stored in the permData hashtable that is not mapped to a column will be saved.

Specified by:
saveOnSessionUnbind in interface UserManager
Throws:
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

authenticate

public void authenticate(User user,
                         java.lang.String password)
                  throws PasswordMismatchException,
                         UnknownEntityException,
                         DataBackendException
Authenticate an User with the specified password. If authentication is successful the method returns nothing. If there are any problems, exception was thrown.

Specified by:
authenticate in interface UserManager
Parameters:
user - an User object to authenticate.
password - the user supplied password.
Throws:
PasswordMismatchException - if the supplied password was incorrect.
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

changePassword

public void changePassword(User user,
                           java.lang.String oldPassword,
                           java.lang.String newPassword)
                    throws PasswordMismatchException,
                           UnknownEntityException,
                           DataBackendException
Change the password for an User. The user must have supplied the old password to allow the change.

Specified by:
changePassword in interface UserManager
Parameters:
user - an User to change password for.
oldPassword - The old password to verify
newPassword - The new password to set
Throws:
PasswordMismatchException - if the supplied password was incorrect.
UnknownEntityException - if the user's account does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

forcePassword

public void forcePassword(User user,
                          java.lang.String password)
                   throws UnknownEntityException,
                          DataBackendException
Forcibly sets new password for an User. This is supposed by the administrator to change the forgotten or compromised passwords. Certain implementatations of this feature would require administrative level access to the authenticating server / program.

Specified by:
forcePassword in interface UserManager
Parameters:
user - an User to change password for.
password - the new password.
Throws:
UnknownEntityException - if the user's record does not exist in the database.
DataBackendException - if there is a problem accessing the storage.

createAccount

public void createAccount(User user,
                          java.lang.String initialPassword)
                   throws EntityExistsException,
                          DataBackendException
Creates new user account with specified attributes.

Specified by:
createAccount in interface UserManager
Parameters:
user - The object describing account to be created.
initialPassword - the password for the new account
Throws:
DataBackendException - if there was an error accessing the data backend.
EntityExistsException - if the user account already exists.

removeAccount

public void removeAccount(User user)
                   throws UnknownEntityException,
                          DataBackendException
Removes an user account from the system.

Specified by:
removeAccount in interface UserManager
Parameters:
user - the object describing the account to be removed.
Throws:
DataBackendException - if there was an error accessing the data backend.
UnknownEntityException - if the user account is not present.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.