Class UserMultiProvider

java.lang.Object
org.jivesoftware.openfire.user.UserMultiProvider
All Implemented Interfaces:
UserProvider
Direct Known Subclasses:
HybridUserProvider, MappedUserProvider

public abstract class UserMultiProvider extends Object implements UserProvider
A UserProvider that delegates to one or more 'backing' UserProvider.
Author:
Guus der Kinderen, guus@goodbytes.nl
  • 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

      public static UserProvider instantiate(@Nonnull SystemProperty<Class> implementationProperty)
      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: UserProvider
      Returns the number of users in the system.
      Specified by:
      getUserCount in interface UserProvider
      Returns:
      the total number of users.
    • getUsers

      public Collection<User> getUsers()
      Description copied from interface: UserProvider
      Returns an unmodifiable Collections of all users in the system. The UserCollection class 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 to UserManager.getUser(String).
      Specified by:
      getUsers in interface UserProvider
      Returns:
      an unmodifiable Collection of all users.
    • getUsernames

      public Collection<String> getUsernames()
      Description copied from interface: UserProvider
      Returns an unmodifiable Collection of usernames of all users in the system.
      Specified by:
      getUsernames in interface UserProvider
      Returns:
      an unmodifiable Collection of all usernames in the system.
    • getUsers

      public Collection<User> getUsers(int startIndex, int numResults)
      Description copied from interface: UserProvider
      Returns an unmodifiable Collections of users in the system within the specified range. The UserCollection class 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 to UserManager.getUser(String).

      It is possible that the number of results returned will be less than that specified by numResults if numResults is greater than the number of records left to display.

      Specified by:
      getUsers in interface UserProvider
      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 by 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 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:
      findUsers in interface UserProvider
      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 by 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 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:
      findUsers in interface UserProvider
      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

      public Set<String> getSearchFields() throws UnsupportedOperationException
      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:
      getSearchFields in interface UserProvider
      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:
      isReadOnly in interface UserProvider
      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:
      isNameRequired in interface UserProvider
      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:
      isEmailRequired in interface UserProvider
      Returns:
      true when all backing providers require an email address to be set on User objects, otherwise false.
    • loadUser

      public User loadUser(String username) throws UserNotFoundException
      Description copied from interface: UserProvider
      Loads the specified user by username.
      Specified by:
      loadUser in interface UserProvider
      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: UserProvider
      Creates a new user. This method should throw an UnsupportedOperationException if this operation is not supporte by the backend user store.
      Specified by:
      createUser in interface UserProvider
      Parameters:
      username - the username.
      password - the plain-text password.
      name - the user's name, which can be null, unless isNameRequired is set to true.
      email - the user's email address, which can be null, unless isEmailRequired is set to true.
      Returns:
      a new User.
      Throws:
      UserAlreadyExistsException - if the username is already in use.
    • deleteUser

      public void deleteUser(String username)
      Removes a user from all non-read-only providers.
      Specified by:
      deleteUser in interface UserProvider
      Parameters:
      username - the username to delete.
    • setCreationDate

      public void setCreationDate(String username, Date creationDate) throws UserNotFoundException
      Changes the creation date of a user in the first provider that contains the user.
      Specified by:
      setCreationDate in interface UserProvider
      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:
      setModificationDate in interface UserProvider
      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

      public void setName(String username, String name) throws UserNotFoundException
      Changes the full name of a user in the first provider that contains the user.
      Specified by:
      setName in interface UserProvider
      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

      public void setEmail(String username, String email) throws UserNotFoundException
      Changes the email address of a user in the first provider that contains the user.
      Specified by:
      setEmail in interface UserProvider
      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.