Class DefaultUserProvider
- All Implemented Interfaces:
UserProvider
- Direct Known Subclasses:
NativeUserProvider,POP3UserProvider
ofUser database table.
Passwords can be stored as plain text, or encrypted using Blowfish. The
encryption/decryption key is stored as the Openfire property passwordKey,
which is automatically created on first-time use. It's critical that the password key
not be changed once created, or existing passwords will be lost. By default
passwords will be stored encrypted. Plain-text password storage can be enabled
by setting the Openfire property user.usePlainPassword to true.
- Author:
- Matt Tucker
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateUser(String username, String password, String name, String email) Creates a new user.voiddeleteUser(String username) Delets a user.Searches for users based on a set of fields and a query string.Searches for users based on a set of fields and a query string.Returns the set of fields that can be used for searching for users.intReturns the number of users in the system.Returns an unmodifiable Collection of usernames of all users in the system.getUsers()Returns an unmodifiable Collections of all users in the system.getUsers(int startIndex, int numResults) Returns an unmodifiable Collections of users in the system within the specified range.booleanReturns true if this UserProvider requires an email address to be set on User objects.booleanReturns true if this UserProvider requires a name to be set on User objects.booleanReturns true if this UserProvider is read-only.Loads the specified user by username.voidsetCreationDate(String username, Date creationDate) Sets the date the user was created.voidSets the user's email address.voidsetModificationDate(String username, Date modificationDate) Sets the date the user was last modified.voidSets the user's name.
-
Constructor Details
-
DefaultUserProvider
public DefaultUserProvider()
-
-
Method Details
-
loadUser
Description copied from interface:UserProviderLoads the specified user by username.- Specified by:
loadUserin interfaceUserProvider- Parameters:
username- the username- Returns:
- the User.
- Throws:
UserNotFoundException- if the User could not be loaded.
-
createUser
public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException Description copied from interface:UserProviderCreates a new user. This method should throw an UnsupportedOperationException if this operation is not supporte by the backend user store.- Specified by:
createUserin interfaceUserProvider- Parameters:
username- the username.password- the plain-text password.name- the user's name, which can benull, unless isNameRequired is set to true.email- the user's email address, which can benull, unless isEmailRequired is set to true.- Returns:
- a new User.
- Throws:
UserAlreadyExistsException- if the username is already in use.
-
deleteUser
Description copied from interface:UserProviderDelets a user. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.- Specified by:
deleteUserin interfaceUserProvider- Parameters:
username- the username to delete.
-
getUserCount
public int getUserCount()Description copied from interface:UserProviderReturns the number of users in the system.- Specified by:
getUserCountin interfaceUserProvider- Returns:
- the total number of users.
-
getUsers
Description copied from interface:UserProviderReturns an unmodifiable Collections of all users in the system. TheUserCollectionclass can be used to assist in the implementation of this method. It takes a String [] of usernames and presents it as a Collection of User objects (obtained with calls toUserManager.getUser(String).- Specified by:
getUsersin interfaceUserProvider- Returns:
- an unmodifiable Collection of all users.
-
getUsernames
Description copied from interface:UserProviderReturns an unmodifiable Collection of usernames of all users in the system.- Specified by:
getUsernamesin interfaceUserProvider- Returns:
- an unmodifiable Collection of all usernames in the system.
-
getUsers
Description copied from interface:UserProviderReturns an unmodifiable Collections of users in the system within the specified range. TheUserCollectionclass can be used to assist in the implementation of this method. It takes a String [] of usernames and presents it as a Collection of User objects (obtained with calls toUserManager.getUser(String).It is possible that the number of results returned will be less than that specified by
numResultsifnumResultsis greater than the number of records left to display.- Specified by:
getUsersin interfaceUserProvider- Parameters:
startIndex- the beginning index to start the results at.numResults- the total number of results to return.- Returns:
- an unmodifiable Collection of users within the specified range.
-
setName
Description copied from interface:UserProviderSets the user's name. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.- Specified by:
setNamein interfaceUserProvider- Parameters:
username- the username.name- the name.- Throws:
UserNotFoundException- if the user could not be found.
-
setEmail
Description copied from interface:UserProviderSets the user's email address. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.- Specified by:
setEmailin interfaceUserProvider- Parameters:
username- the username.email- the email address.- Throws:
UserNotFoundException- if the user could not be found.
-
setCreationDate
Description copied from interface:UserProviderSets the date the user was created. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.- Specified by:
setCreationDatein interfaceUserProvider- Parameters:
username- the username.creationDate- the date the user was created.- Throws:
UserNotFoundException- if the user could not be found.
-
setModificationDate
public void setModificationDate(String username, Date modificationDate) throws UserNotFoundException Description copied from interface:UserProviderSets the date the user was last modified. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.- Specified by:
setModificationDatein interfaceUserProvider- Parameters:
username- the username.modificationDate- the date the user was last modified.- Throws:
UserNotFoundException- if the user could not be found.
-
getSearchFields
Description copied from interface:UserProviderReturns the set of fields that can be used for searching for users. Each field returned must support wild-card and keyword searching. For example, an implementation might send back the set {"Username", "Name", "Email"}. Any of those three fields can then be used in a search with theUserProvider.findUsers(Set,String)method.This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.
- Specified by:
getSearchFieldsin interfaceUserProvider- Returns:
- the valid search fields.
- Throws:
UnsupportedOperationException- if the provider does not support the operation (this is an optional operation).
-
findUsers
public Collection<User> findUsers(Set<String> fields, String query) throws UnsupportedOperationException Description copied from interface:UserProviderSearches for users based on a set of fields and a query string. The fields must be taken from the values returned byUserProvider.getSearchFields(). The query can include wildcards. For example, a search on the field "Name" with a query of "Ma*" might return user's with the name "Matt", "Martha" and "Madeline".This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.
- Specified by:
findUsersin interfaceUserProvider- Parameters:
fields- the fields to search on.query- the query string.- Returns:
- a Collection of users that match the search.
- Throws:
UnsupportedOperationException- if the provider does not support the operation (this is an optional operation).
-
findUsers
public Collection<User> findUsers(Set<String> fields, String query, int startIndex, int numResults) throws UnsupportedOperationException Description copied from interface:UserProviderSearches for users based on a set of fields and a query string. The fields must be taken from the values returned byUserProvider.getSearchFields(). The query can include wildcards. For example, a search on the field "Name" with a query of "Ma*" might return user's with the name "Matt", "Martha" and "Madeline".The startIndex and numResults parameters are used to page through search results. For example, if the startIndex is 0 and numResults is 10, the first 10 search results will be returned. Note that numResults is a request for the number of results to return and that the actual number of results returned may be fewer.
This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.
- Specified by:
findUsersin interfaceUserProvider- Parameters:
fields- the fields to search on.query- the query string.startIndex- the starting index in the search result to return.numResults- the number of users to return in the search result.- Returns:
- a Collection of users that match the search.
- Throws:
UnsupportedOperationException- if the provider does not support the operation (this is an optional operation).
-
isReadOnly
public boolean isReadOnly()Description copied from interface:UserProviderReturns true if this UserProvider is read-only. When read-only, users can not be created, deleted, or modified.- Specified by:
isReadOnlyin interfaceUserProvider- Returns:
- true if the user provider is read-only.
-
isNameRequired
public boolean isNameRequired()Description copied from interface:UserProviderReturns true if this UserProvider requires a name to be set on User objects.- Specified by:
isNameRequiredin interfaceUserProvider- Returns:
- true if an name is required with this provider.
-
isEmailRequired
public boolean isEmailRequired()Description copied from interface:UserProviderReturns true if this UserProvider requires an email address to be set on User objects.- Specified by:
isEmailRequiredin interfaceUserProvider- Returns:
- true if an email address is required with this provider.
-