Class DefaultUserManager
- java.lang.Object
-
- org.apache.turbine.services.security.DefaultUserManager
-
- All Implemented Interfaces:
UserManager
public class DefaultUserManager extends Object implements UserManager
Default user manager. The user manager wraps Fulcrum security user objects into Turbine-specific ones.- either in a method with the same name (and very similar signature)
- or mapped to method names as listed below:
- method(s) in this manager -> Fulcrum manager method(s)
createAccount(User, String)createAccount -> addUser(User, String)removeAccount(User)-> removeUser(User)store(User)-> saveUser(User)retrieve(String)andretrieve(String, String)-> getUser(String), getUser(String, String)retrieveList(Object)-> getAllUsers()accountExists(String),accountExists(User)-> checkExists(String), checkExists(User)
TurbineUserManagerinterface are used by reference of the Fulcrum delegateumDelegateand wrapped by this manager.- Version:
- $Id: PassiveUserManager.java 1096130 2011-04-23 10:37:19Z ludwig $
- Author:
- Thomas Vandahl
-
-
Constructor Summary
Constructors Constructor Description DefaultUserManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccountExists(String userName)Check whether a specified user's account exists.booleanaccountExists(User user)Check whether a specified user's account exists.voidauthenticate(User user, String password)Authenticate an User with the specified password.voidchangePassword(User user, String oldPassword, String newPassword)Change the password for an User.voidcreateAccount(User user, String initialPassword)Creates new user account with specified attributes.voidforcePassword(User user, String password)Forcibly sets new password for an User.<A extends org.apache.fulcrum.security.acl.AccessControlList>
AgetACL(User user)Return a Class object representing the system's chosen implementation of of ACL interface.<U extends User>
UgetAnonymousUser()Constructs an User object to represent an anonymous user of the application.<U extends User>
UgetUserInstance()Construct a blank User object.<U extends User>
UgetUserInstance(String userName)Construct a blank User object.<U extends User>
UgetUserWrapper(org.apache.fulcrum.security.model.turbine.entity.TurbineUser user)Exception could be ignored, as it is tested before ininit(Configuration).StringgetUserWrapperClass()Get the wrapper class for user objectsvoidinit(org.apache.commons.configuration2.Configuration conf)Initializes the UserManagerbooleanisAnonymousUser(User u)Checks whether a passed user object matches the anonymous user pattern according to the configured user managervoidremoveAccount(User user)Removes an user account from the system.<U extends User>
Uretrieve(String username)Retrieve a user from persistent storage using username as the key.<U extends User>
Uretrieve(String username, String password)Retrieve a user from persistent storage using username as the key, and authenticate the user.List<? extends User>retrieveList(Object criteria)Retrieve a set of users that meet the specified criteria.voidsaveOnSessionUnbind(User user)Saves User data when the session is unbound.voidsetUserWrapperClass(String userWrapperClass2)Set the wrapper class for user objectsvoidstore(User user)Save an User object to persistent storage.protected <U extends User>
Uwrap(org.apache.fulcrum.security.model.turbine.entity.TurbineUser user)Wrap a Fulcrum user object into a Turbine user object
-
-
-
Constructor Detail
-
DefaultUserManager
public DefaultUserManager()
-
-
Method Detail
-
wrap
protected <U extends User> U wrap(org.apache.fulcrum.security.model.turbine.entity.TurbineUser user)
Wrap a Fulcrum user object into a Turbine user object- Type Parameters:
U- user class- Parameters:
user- the user object to delegate to- Returns:
- the wrapped object
-
getUserWrapper
public <U extends User> U getUserWrapper(org.apache.fulcrum.security.model.turbine.entity.TurbineUser user)
Exception could be ignored, as it is tested before ininit(Configuration).- Type Parameters:
U- user class- Parameters:
user- the user object to wrap- Returns:
- instance extending
User
-
getUserWrapperClass
public String getUserWrapperClass()
Get the wrapper class for user objects- Returns:
- the wrapper class name
-
setUserWrapperClass
public void setUserWrapperClass(String userWrapperClass2)
Set the wrapper class for user objects- Parameters:
userWrapperClass2- the wrapper class name
-
init
public void init(org.apache.commons.configuration2.Configuration conf) throws InitializationException
Initializes the UserManager- Specified by:
initin interfaceUserManager- Parameters:
conf- A Configuration object to init this Manager- Throws:
InitializationException- When something went wrong.
-
accountExists
public boolean accountExists(User user) throws org.apache.fulcrum.security.util.DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.- Specified by:
accountExistsin interfaceUserManager- Parameters:
user- The user to be checked.- Returns:
- true if the specified account exists
- Throws:
org.apache.fulcrum.security.util.DataBackendException- if there was an error accessing the data backend.
-
accountExists
public boolean accountExists(String userName) throws org.apache.fulcrum.security.util.DataBackendException
Check whether a specified user's account exists. The login name is used for looking up the account.- Specified by:
accountExistsin interfaceUserManager- Parameters:
userName- The name of the user to be checked.- Returns:
- true if the specified account exists
- Throws:
org.apache.fulcrum.security.util.DataBackendException- if there was an error accessing the data backend.
-
retrieve
public <U extends User> U retrieve(String username) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.DataBackendException
Retrieve a user from persistent storage using username as the key.- Specified by:
retrievein interfaceUserManager- Type Parameters:
U- user class- Parameters:
username- the name of the user.- Returns:
- an User object.
- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
retrieveList
public List<? extends User> retrieveList(Object criteria) throws org.apache.fulcrum.security.util.DataBackendException
Retrieve a set of users that meet the specified criteria. As the keys for the criteria, you should use the constants that are defined inUserinterface, 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:
retrieveListin interfaceUserManager- Parameters:
criteria- The criteria of selection.- Returns:
- a List of users meeting the criteria.
- Throws:
org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
retrieve
public <U extends User> U retrieve(String username, String password) throws org.apache.fulcrum.security.util.PasswordMismatchException, org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.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:
retrievein interfaceUserManager- Type Parameters:
U- user class- Parameters:
username- the name of the user.password- the user supplied password.- Returns:
- an User object.
- Throws:
org.apache.fulcrum.security.util.PasswordMismatchException- if the supplied password was incorrect.org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
store
public void store(User user) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.DataBackendException
Save an User object to persistent storage. User's record is required to exist in the storage.- Specified by:
storein interfaceUserManager- Parameters:
user- an User object to store.- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
saveOnSessionUnbind
public void saveOnSessionUnbind(User user) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.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:
saveOnSessionUnbindin interfaceUserManager- Parameters:
user- the user in the session- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the user's account does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
authenticate
public void authenticate(User user, String password) throws org.apache.fulcrum.security.util.PasswordMismatchException, org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.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:
authenticatein interfaceUserManager- Parameters:
user- an User object to authenticate.password- the user supplied password.- Throws:
org.apache.fulcrum.security.util.PasswordMismatchException- if the supplied password was incorrect.org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
createAccount
public void createAccount(User user, String initialPassword) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.EntityExistsException, org.apache.fulcrum.security.util.DataBackendException
Creates new user account with specified attributes.- Specified by:
createAccountin interfaceUserManager- Parameters:
user- the object describing account to be created.initialPassword- The password to use for the object creation- Throws:
org.apache.fulcrum.security.util.DataBackendException- if there was an error accessing the data backend.org.apache.fulcrum.security.util.EntityExistsException- if the user account already exists.org.apache.fulcrum.security.util.UnknownEntityException- if the user account cannot be created.
-
removeAccount
public void removeAccount(User user) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.DataBackendException
Removes an user account from the system.- Specified by:
removeAccountin interfaceUserManager- Parameters:
user- the object describing the account to be removed.- Throws:
org.apache.fulcrum.security.util.DataBackendException- if there was an error accessing the data backend.org.apache.fulcrum.security.util.UnknownEntityException- if the user account is not present.
-
changePassword
public void changePassword(User user, String oldPassword, String newPassword) throws org.apache.fulcrum.security.util.PasswordMismatchException, org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.DataBackendException
Change the password for an User.- Specified by:
changePasswordin interfaceUserManager- Parameters:
user- an User to change password for.oldPassword- the current password supplied by the user.newPassword- the current password requested by the user.- Throws:
org.apache.fulcrum.security.util.PasswordMismatchException- if the supplied password was incorrect.org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
forcePassword
public void forcePassword(User user, String password) throws org.apache.fulcrum.security.util.UnknownEntityException, org.apache.fulcrum.security.util.DataBackendException
Forcibly sets new password for an User. This is supposed by the administrator to change the forgotten or compromised passwords. Certain implementations of this feature would require administrative level access to the authenticating server / program.- Specified by:
forcePasswordin interfaceUserManager- Parameters:
user- an User to change password for.password- the new password.- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the user's record does not exist in the database.org.apache.fulcrum.security.util.DataBackendException- if there is a problem accessing the storage.
-
getAnonymousUser
public <U extends User> U getAnonymousUser() throws org.apache.fulcrum.security.util.UnknownEntityException
Constructs an User object to represent an anonymous user of the application.- Specified by:
getAnonymousUserin interfaceUserManager- Type Parameters:
U- user class- Returns:
- An anonymous Turbine User.
- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the anonymous User object couldn't be constructed.
-
isAnonymousUser
public boolean isAnonymousUser(User u)
Checks whether a passed user object matches the anonymous user pattern according to the configured user manager- Specified by:
isAnonymousUserin interfaceUserManager- Parameters:
u- a user object- Returns:
- True if this is an anonymous user
-
getUserInstance
public <U extends User> U getUserInstance() throws org.apache.fulcrum.security.util.DataBackendException
Construct a blank User object. This method calls getUserClass, and then creates a new object using the default constructor.- Specified by:
getUserInstancein interfaceUserManager- Type Parameters:
U- user class- Returns:
- an object implementing User interface.
- Throws:
org.apache.fulcrum.security.util.DataBackendException- if the object could not be instantiated.
-
getUserInstance
public <U extends User> U getUserInstance(String userName) throws org.apache.fulcrum.security.util.DataBackendException
Construct a blank User object. This method calls getUserClass, and then creates a new object using the default constructor.- Specified by:
getUserInstancein interfaceUserManager- Type Parameters:
U- user class- Parameters:
userName- The name of the user.- Returns:
- an object implementing User interface.
- Throws:
org.apache.fulcrum.security.util.DataBackendException- if the object could not be instantiated.
-
getACL
public <A extends org.apache.fulcrum.security.acl.AccessControlList> A getACL(User user) throws org.apache.fulcrum.security.util.UnknownEntityException
Return a Class object representing the system's chosen implementation of of ACL interface.- Specified by:
getACLin interfaceUserManager- Type Parameters:
A- ACL class- Parameters:
user- the user- Returns:
- systems's chosen implementation of ACL interface.
- Throws:
org.apache.fulcrum.security.util.UnknownEntityException- if the implementation of ACL interface could not be determined, or does not exist.
-
-