Package org.jivesoftware.openfire.user
Class UserMultiProvider
java.lang.Object
org.jivesoftware.openfire.user.UserMultiProvider
- All Implemented Interfaces:
UserProvider
- Direct Known Subclasses:
HybridUserProvider,MappedUserProvider
A
UserProvider that delegates to one or more 'backing' UserProvider.- Author:
- Guus der Kinderen, guus@goodbytes.nl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateUser(String username, String password, String name, String email) Creates a new user.voiddeleteUser(String username) Removes a user from all non-read-only providers.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 combination of search fields supported by the backing providers.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.static UserProviderinstantiate(String propertyName) Deprecated, for removal: This API element is subject to removal in a future version.static UserProviderinstantiate(SystemProperty<Class> implementationProperty) Instantiates a UserProvider based on Class-based system property.static UserProviderinstantiate(SystemProperty<Class> implementationProperty, SystemProperty<String> configProperty) Instantiates a UserProvider based on Class-based system property.booleanReturns whether all backing providers require an email address to be set on User objects.booleanReturns whether all backing providers require a name to be set on User objects.booleanReturns whether all backing providers are read-only.Loads the specified user by username.voidsetCreationDate(String username, Date creationDate) Changes the creation date of a user in the first provider that contains the user.voidChanges the email address of a user in the first provider that contains the user.voidsetModificationDate(String username, Date modificationDate) Changes the modification date of a user in the first provider that contains the user.voidChanges the full name of a user in the first provider that contains the user.
-
Constructor Details
-
UserMultiProvider
public UserMultiProvider()
-
-
Method Details
-
instantiate
@Deprecated(forRemoval=true, since="5.0.0") public static UserProvider instantiate(String propertyName) Deprecated, for removal: This API element is subject to removal in a future version.Instantiates a UserProvider based on a property value (that is expected to be a class name). When the property is not set, this method returns null. When the property is set, but an exception occurs while instantiating the class, this method logs the error and returns null. UserProvider classes are required to have a public, no-argument constructor.- Parameters:
propertyName- A property name (cannot be null).- Returns:
- A user provider (can be null).
-
instantiate
Instantiates a UserProvider based on Class-based system property. When the property is not set, this method returns null. When the property is set, but an exception occurs while instantiating the class, this method logs the error and returns null. UserProvider classes are required to have a public, no-argument constructor.- Parameters:
implementationProperty- A property that defines the class of the instance to be returned.- Returns:
- A user provider (can be null).
-
instantiate
public static UserProvider instantiate(@Nonnull SystemProperty<Class> implementationProperty, @Nullable SystemProperty<String> configProperty) Instantiates a UserProvider based on Class-based system property. When the property is not set, this method returns null. When the property is set, but an exception occurs while instantiating the class, this method logs the error and returns null. UserProvider classes are required to have a public, no-argument constructor, but can have an optional additional constructor that takes a single String argument. If such constructor is defined, then it is invoked with the value of the second argument of this method. This is typically used to (but needs not) identify a property (by name) that holds additional configuration for the to be instantiated UserProvider. This implementation will pass on any non-empty value to the constructor. When a configuration argument is provided, but no constructor exists in the implementation that accepts a single String value, this method will log a warning and attempt to return an instance based on the no-arg constructor of the class.- Parameters:
implementationProperty- A property that defines the class of the instance to be returned.configProperty- an opaque string value passed to the constructor.- Returns:
- A user provider (can be null).
-
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.
-
findUsers
public Collection<User> findUsers(Set<String> fields, String query) throws UnsupportedOperationException Searches for users based on a set of fields and a query string. The fields must be taken from the values returned bygetSearchFields(). 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 throws an UnsupportedOperationException when none of the backing providers support search. When fields are provided that are not supported by a particular provider, those fields are ignored by that provider (but can still be used by other providers).- 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- When none of the providers support search.
-
findUsers
public Collection<User> findUsers(Set<String> fields, String query, int startIndex, int numResults) throws UnsupportedOperationException Searches for users based on a set of fields and a query string. The fields must be taken from the values returned bygetSearchFields(). 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 throws an UnsupportedOperationException when none of the backing providers support search. When fields are provided that are not supported by a particular provider, those fields are ignored by that provider (but can still be used by other providers). 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.- 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- When none of the providers support search.
-
getSearchFields
Returns the combination of search fields supported by the backing providers. Note that the returned fields might not be supported by every backing provider.- Specified by:
getSearchFieldsin interfaceUserProvider- Returns:
- the valid search fields.
- Throws:
UnsupportedOperationException- If no search fields are returned, or when at least one of the providers throws UnsupportedOperationException when its #getSearchField() is invoked.
-
isReadOnly
public boolean isReadOnly()Returns whether all backing providers are read-only. When read-only, users can not be created, deleted, or modified. If at least one provider is not read-only, this method returns false.- Specified by:
isReadOnlyin interfaceUserProvider- Returns:
- true when all backing providers are read-only, otherwise false.
-
isNameRequired
public boolean isNameRequired()Returns whether all backing providers require a name to be set on User objects. If at least one proivder does not, this method returns false.- Specified by:
isNameRequiredin interfaceUserProvider- Returns:
- true when all backing providers require a name to be set on User objects, otherwise false.
-
isEmailRequired
public boolean isEmailRequired()Returns whether all backing providers require an email address to be set on User objects. If at least one provider does not, this method returns false.- Specified by:
isEmailRequiredin interfaceUserProvider- Returns:
- true when all backing providers require an email address to be set on User objects, otherwise false.
-
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
Removes a user from all non-read-only providers.- Specified by:
deleteUserin interfaceUserProvider- Parameters:
username- the username to delete.
-
setCreationDate
Changes the creation date of a user in the first provider that contains the user.- Specified by:
setCreationDatein interfaceUserProvider- Parameters:
username- the identifier of the user.creationDate- the date the user was created.- Throws:
UserNotFoundException- when the user was not found in any provider.UnsupportedOperationException- when the provider is read-only.
-
setModificationDate
public void setModificationDate(String username, Date modificationDate) throws UserNotFoundException Changes the modification date of a user in the first provider that contains the user.- Specified by:
setModificationDatein interfaceUserProvider- Parameters:
username- the identifier of the user.modificationDate- the date the user was (last) modified.- Throws:
UserNotFoundException- when the user was not found in any provider.UnsupportedOperationException- when the provider is read-only.
-
setName
Changes the full name of a user in the first provider that contains the user.- Specified by:
setNamein interfaceUserProvider- Parameters:
username- the identifier of the user.name- the new full name a user.- Throws:
UserNotFoundException- when the user was not found in any provider.UnsupportedOperationException- when the provider is read-only.
-
setEmail
Changes the email address of a user in the first provider that contains the user.- Specified by:
setEmailin interfaceUserProvider- Parameters:
username- the identifier of the user.email- the new email address of a user.- Throws:
UserNotFoundException- when the user was not found in any provider.UnsupportedOperationException- when the provider is read-only.
-
instantiate(SystemProperty)orinstantiate(SystemProperty, SystemProperty)instead.