Class UserManager
- Author:
- Matt Tucker
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemProperty<Boolean>
When enabled, allows Openfire to process data for local JIDs that potentially are future users.static final SystemProperty<Class>
static final SystemProperty<Class>
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Exposed for test use onlycreateUser
(String username, String password, String name, String email) Creates a new User.void
deleteUser
(User user) Deletes a user (optional operation).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.static UserManager
Returns a singleton UserManager instance.Returns the set of fields that can be used for searching for users.Returns the User specified by username.getUser
(org.xmpp.packet.JID user) Returns the User specified by jid node.int
Returns the total number of users in the system.Returns an unmodifiable Collection of usernames of all users in the system.static UserPropertyProvider
Returns the currently-installed UserPropertyProvider.static UserProvider
Returns the currently-installed UserProvider.getUsers()
Returns an unmodifiable Collection of all users in the system.getUsers
(int startIndex, int numResults) Returns an unmodifiable Collection of all users starting atstartIndex
with the given number of results.static boolean
isPotentialFutureLocalUser
(org.xmpp.packet.JID user) Checks if the provided address belongs to a locally registered user that potentially has not registered yet.boolean
isRegisteredUser
(org.xmpp.packet.JID user, boolean checkRemoteDomains) Returns true if the specified JID belongs to a local or remote registered user.static void
setProvider
(UserProvider provider) Exposed for test use only
-
Field Details
-
USER_PROVIDER
-
USER_PROPERTY_PROVIDER
-
ALLOW_FUTURE_USERS
When enabled, allows Openfire to process data for local JIDs that potentially are future users. To be used when users are provisioned externally/on an ad-hoc basis.
-
-
Method Details
-
getUserProvider
Returns the currently-installed UserProvider. Warning: in virtually all cases the user provider should not be used directly. Instead, the appropriate methods in UserManager should be called. Direct access to the user provider is only provided for special-case logic.- Returns:
- the current UserProvider.
-
getUserPropertyProvider
Returns the currently-installed UserPropertyProvider. Warning: in virtually all cases the user property provider should not be used directly. Instead, use the Map returned byUser.getProperties()
to create, read, update or delete user properties. Failure to do so is likely to result in inconsistent data behavior and race conditions. Direct access to the user property provider is only provided for special-case logic.- Returns:
- the current UserPropertyProvider.
- See Also:
-
getInstance
Returns a singleton UserManager instance.- Returns:
- a UserManager instance.
-
createUser
public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException Creates a new User. Required values are username and password. The email address and name can optionally benull
, unless the UserProvider deems that either of them are required.- Parameters:
username
- the new and unique username for the account.password
- the password for the account (plain text).name
- the name of the user, which can benull
unless the UserProvider deems that it's required.email
- the email address to associate with the new account, which can benull
, unless the UserProvider deems that it's required.- Returns:
- a new User.
- Throws:
UserAlreadyExistsException
- if the username already exists in the system.UnsupportedOperationException
- if the provider does not support the operation.
-
deleteUser
Deletes a user (optional operation).- Parameters:
user
- the user to delete.
-
getUser
Returns the User specified by username.- Parameters:
username
- the username of the user.- Returns:
- the User that matches
username
. - Throws:
UserNotFoundException
- if the user does not exist.
-
getUser
Returns the User specified by jid node.- Parameters:
user
- the username of the user.- Returns:
- the User that matches
username
. - Throws:
UserNotFoundException
- if the user does not exist.
-
getUserCount
public int getUserCount()Returns the total number of users in the system.- Returns:
- the total number of users.
-
getUsers
Returns an unmodifiable Collection of all users in the system.- Returns:
- an unmodifiable Collection of all users.
-
getUsernames
Returns an unmodifiable Collection of usernames of all users in the system.- Returns:
- an unmodifiable Collection of all usernames in the system.
-
getUsers
Returns an unmodifiable Collection of all users starting atstartIndex
with the given number of results. This is useful to support pagination in a GUI where you may only want to display a certain number of results per page. It is possible that the number of results returned will be less than that specified bynumResults
ifnumResults
is greater than the number of records left to display.- Parameters:
startIndex
- the beginning index to start the results at.numResults
- the total number of results to return.- Returns:
- a Collection of users in the specified range.
-
getSearchFields
Returns 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 thefindUsers(Set,String)
method.This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.
- 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 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 if this operation is not supported by the user provider.
- 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 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".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.
- 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).
-
isRegisteredUser
public boolean isRegisteredUser(@Nonnull org.xmpp.packet.JID user, boolean checkRemoteDomains) Returns true if the specified JID belongs to a local or remote registered user. If allowed by the 'checkRemoteDomains', argument, for remote users (i.e. domain does not match local domain) a disco#info request is going to be sent to the bare JID of the user. If 'checkRemoteDomains' is false, this method will return 'false' for all JIDs of which the domain-part does not match the local domain.WARNING: If the supplied JID could be a remote user and the disco#info result packet comes back on the same thread as the one the calls this method then it will not be processed, and this method will block for 60 seconds by default. To change the timeout, update the system property
usermanager.remote-disco-info-timeout-seconds
- Parameters:
user
- to JID of the user to check it it's a registered user.checkRemoteDomains
- false the lookup is allowed to include calls to remote XMPP domains.- Returns:
- true if the specified JID belongs to a registered user.
-
isPotentialFutureLocalUser
public static boolean isPotentialFutureLocalUser(org.xmpp.packet.JID user) Checks if the provided address belongs to a locally registered user that potentially has not registered yet. This method is intended to be used in use-cases where data addressed at a local user is processed, prior to that user having received a representation in the user manager. This can occur when users are created on ad-hoc basis, such as through the result of external authentication. When the feature that allows future users to be considered is disabled, this method will always return false.- Parameters:
user
- The address of a user- Returns:
- True if the address could be used for a locally registered user, potentially not having registered yet.
-
setProvider
Exposed for test use only -
clearCaches
public void clearCaches()Exposed for test use only
-