Interface UserDao

All Known Subinterfaces:
InternalUserDao
All Known Implementing Classes:
UserDAOHibernate

public interface UserDao
Responsible for the persistence and retrieval of Users, PasswordCredentials and user attributes.
  • Method Details

    • findByName

      TimestampedUser findByName(long directoryId, String userName) throws UserNotFoundException
      Finds and returns the user with the given name and directory ID.
      Throws:
      UserNotFoundException - if the user could not be found
    • findByExternalId

      TimestampedUser findByExternalId(long directoryId, String externalId) throws UserNotFoundException
      Finds and returns the user with the given unique/external id and directory ID.
      Throws:
      UserNotFoundException - if the user could not be found
    • findByNameWithAttributes

      UserWithAttributes findByNameWithAttributes(long directoryId, String userName) throws UserNotFoundException
      Finds and returns the user with attributes with the given name and directory ID.
      Throws:
      UserNotFoundException - if the user could not be found
    • getCredential

      PasswordCredential getCredential(long directoryId, String userName) throws UserNotFoundException
      Returns the credential for the given user. It will always be encrypted.
      Throws:
      UserNotFoundException - if the user could not be found
    • getCredentialHistory

      List<PasswordCredential> getCredentialHistory(long directoryId, String userName) throws UserNotFoundException
      Returns the previous credentials for the given user, starting with the oldest. May be an empty list if there are no historical credentials.
      Throws:
      UserNotFoundException - if the user could not be found
    • add

      Creates a new user with the given details and credentials. The user details cannot be null, but the credential can be.
      Parameters:
      user - the user to create
      credential - the encrypted password for the user, which may be null if the user's password is not yet available
      Returns:
      the newly created user
      Throws:
      UserAlreadyExistsException - if a user with the same directory and name (case-insensitive) already exists
      IllegalArgumentException - if the user name, directory or any details are null, or if the credential is not encrypted
      DirectoryNotFoundException
    • storeAttributes

      void storeAttributes(User user, Map<String,Set<String>> attributes, boolean updateTimestamp) throws UserNotFoundException
      Adds or updates a user's attributes with the new Map of attribute values. The attributes map represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing attribute. Attributes with values of empty sets in the attributes parameter are removed from the user.
      Parameters:
      user - the user to store attributes for
      attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).
      updateTimestamp - whether the updated timestamp for the user should be updated for this change. This SHOULD be true for attribute changes that might be of interest to other applications, and SHOULD be false for common, trivial attribute changes (for example the ones occurring during authentication)
      Throws:
      UserNotFoundException - user with supplied username does not exist.
    • update

      Updates all the user properties (except the username) of the user with the same directory and case-insensitive name.

      If the username changes, then the rename(User, String) method must be called first, and this method may be called afterwards if other details (eg email or display name) have also changed.

      Even if the username is changed in case only (eg from "mary" to "Mary") then the rename() method will be called first. This implies that the implementation of this method should only need to change the cwd_user table.

      Parameters:
      user - the user details, which should have the same name as the user to modify
      Returns:
      the updated user
      Throws:
      UserNotFoundException - if there is no user with the same name (case-insensitive) and directory as the user provided
      IllegalArgumentException - if the user name, directory or any details are null
      See Also:
    • updateCredential

      void updateCredential(User user, PasswordCredential credential, int maxCredentialHistory) throws UserNotFoundException, IllegalArgumentException
      Updates the credential (password) of the user with the same directory and case-insensitive name. The credential must be encrypted.
      Parameters:
      user - the user whose password will be modified
      credential - the new credential for the user
      maxCredentialHistory - the number of old passwords for the user in which the new password must not match
      Throws:
      UserNotFoundException - if there is no user with the same name (case-insensitive) and directory as the user provided
      IllegalArgumentException - if the credential is null or not encrypted
    • rename

      Changes the user's name to the provided new name.

      This method will be called for any change to a username including a case-only change (eg from "alice" to "Alice"). If there are changes to the username as well as to other user properties (eg email, display name) then callers must call the rename() method first followed by the update() method.

      Implementations of this method will normally need to update the cwd_user table as well as cwd_membership, whereas the update() method implies a change to only the cwd_user table.

      Parameters:
      user - the user to rename
      newName - the new name of the user
      Returns:
      the updated user
      Throws:
      UserNotFoundException - if the user cannot be found
      UserAlreadyExistsException - if the new name is already used by a different user
      IllegalArgumentException - if the new name is null
      See Also:
    • removeAttribute

      void removeAttribute(User user, String attributeName) throws UserNotFoundException
      Removes the attributes for the user with the given name. Does nothing if the attribute doesn't exist.
      Parameters:
      user - the user whose attribute will be removed
      attributeName - the name of the attribute to be removed
      Throws:
      UserNotFoundException - if the user cannot be found
    • remove

      void remove(User user) throws UserNotFoundException
      Removes the user.
      Parameters:
      user - the user to remove
      Throws:
      UserNotFoundException - if the user does not exist
    • search

      <T> List<T> search(long directoryId, EntityQuery<T> query)
      Returns users matching the search query in the given directory, ordered by name. Returns an empty list if no users match.
      Type Parameters:
      T - the type of objects to return, which is normally either User or String
      Parameters:
      directoryId - the ID of the directory to search
      query - the search query
      Returns:
      the list of matching users, or an empty list if no users match
    • addAll

      Bulk add users. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.
      Parameters:
      users - to be added
      Returns:
      a list of Users that failed to be added
    • removeAllUsers

      BatchResult<String> removeAllUsers(long directoryId, Set<String> userNames)
      Bulk remove all the given users from directory. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.
      Parameters:
      directoryId - the ID of the directory to remove users from
      userNames - set of users to be removed
      Returns:
      batch result containing successes (removed users) and failures (users which were not removed)
    • setAttributeForAllInDirectory

      void setAttributeForAllInDirectory(long directoryId, String attrName, String attrValue)
      Ensures that all users in the directory with the given ID have the attribute with the given name set (only) to the single given attribute value. This means that other values of that attribute will be discarded, and the attribute will be added to users who do not have it yet.
      Parameters:
      directoryId - The directory to set the attributes in.
      attrName - The attribute name to set.
      attrValue - The attribute value to set.
    • getAllExternalIds

      Set<String> getAllExternalIds(long directoryId) throws DirectoryNotFoundException
      Return all users externalId in the given directory. If a user's externalId is null or an empty String it should not be included.
      Parameters:
      directoryId - the ID of the directory
      Returns:
      set containing all externalIds with nulls filtered out
      Throws:
      DirectoryNotFoundException - when directory with given id does not exist
    • getUserCount

      long getUserCount(long directoryId) throws DirectoryNotFoundException
      Return number of users in given directory.
      Parameters:
      directoryId - the ID of the directory
      Returns:
      user count
      Throws:
      DirectoryNotFoundException - when directory with given id does not exist
    • findDirectoryIdsContainingUserName

      Set<Long> findDirectoryIdsContainingUserName(String username)
      Find IDs of the directories that contain user with specified username in the cache
      Parameters:
      username - to be checked
      Returns:
      IDs of the directories
    • findByExternalIds

      Map<String,String> findByExternalIds(long directoryId, Set<String> externalIds)
      Searches the specified directory for usernames of users with the specified external ids, returns a map from external id to username
      Parameters:
      directoryId - the directory to search for the users
      externalIds - the external ids of the users to search for