Class UserDAOHibernate

All Implemented Interfaces:
InternalUserDao, UserDao

  • Field Details

  • Constructor Details

    • UserDAOHibernate

      public UserDAOHibernate()
  • Method Details

    • add

      Description copied from interface: UserDao
      Creates a new user with the given details and credentials. The user details cannot be null, but the credential can be.
      Specified by:
      add in interface UserDao
      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
      DirectoryNotFoundException
    • addAll

      Description copied from interface: UserDao
      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.
      Specified by:
      addAll in interface UserDao
      Parameters:
      users - to be added
      Returns:
      a list of Users that failed to be added
    • addAll

      Specified by:
      addAll in interface InternalUserDao
    • findByName

      public InternalUser findByName(long directoryId, String username) throws UserNotFoundException
      Description copied from interface: InternalUserDao
      Finds and return the user with given name and director ID.
      Specified by:
      findByName in interface InternalUserDao
      Specified by:
      findByName in interface UserDao
      Specified by:
      findByName in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
      Throws:
      UserNotFoundException - if the user could not be found
    • findByExternalId

      public InternalUser findByExternalId(long directoryId, String externalId) throws UserNotFoundException
      Description copied from interface: UserDao
      Finds and returns the user with the given unique/external id and directory ID.
      Specified by:
      findByExternalId in interface UserDao
      Throws:
      UserNotFoundException - if the user could not be found
    • findByExternalIds

      public Map<String,String> findByExternalIds(long directoryId, Set<String> externalIds)
      Description copied from interface: InternalUserDao
      Searches the specified directory for usernames of users with the specified external ids, returns a map from external id to username
      Specified by:
      findByExternalIds in interface InternalUserDao
      Specified by:
      findByExternalIds in interface UserDao
      Parameters:
      directoryId - the directory to search for the users
      externalIds - the external ids of the users to search for
    • findUsersForPasswordExpiryNotification

      public Collection<InternalUserWithPasswordLastChanged> findUsersForPasswordExpiryNotification(Instant currentTime, Duration passwordMaxChangeTime, Duration remindPeriod, long directoryId, int maxResults)
      Description copied from interface: InternalUserDao
      Searches the specified directory for Internal Users who will be notified, that their passwords will soon expire
      Specified by:
      findUsersForPasswordExpiryNotification in interface InternalUserDao
      Parameters:
      currentTime - timestamp of current time
      passwordMaxChangeTime - time until password will expire after updating (in days)
      remindPeriod - duration of remind period - user will be notified if time until his password will expire will be lower than that time (in days)
      directoryId - the directory to search for the users
      Returns:
      the matching users
    • findByNumericAttributeRange

      public List<InternalUser> findByNumericAttributeRange(String attributeName, long min, long max)
      Description copied from interface: InternalUserDao
      Returns users with the given numeric attribute in the specified range. The results are returned in ascending order by the attribute value.
      Specified by:
      findByNumericAttributeRange in interface InternalUserDao
      Parameters:
      attributeName - name of the attribute to match
      min - minimum numeric value of the attribute to match
      max - maximum numeric value of the attribute to match
      Returns:
      matching users, in ascending order by the attribute value
    • setAttribute

      public void setAttribute(Collection<InternalUser> users, String attributeName, String attributeValue)
      Description copied from interface: InternalUserDao
      Sets the specified attribute for all specified users and after executing this, every user will have exactly one attribute with that name.
      Specified by:
      setAttribute in interface InternalUserDao
      Parameters:
      users - users to update
      attributeName - name of attribute to update
      attributeValue - value of attribute to update
    • findByNameWithAttributes

      public InternalUserWithAttributes findByNameWithAttributes(long directoryId, String username) throws UserNotFoundException
      Description copied from interface: UserDao
      Finds and returns the user with attributes with the given name and directory ID.
      Specified by:
      findByNameWithAttributes in interface UserDao
      Throws:
      UserNotFoundException - if the user could not be found
    • findByNames

      public Collection<InternalUser> findByNames(long directoryID, Collection<String> usernames)
      Description copied from interface: InternalUserDao
      Bulk find of users using SQL disjunction. This will return fully populated InternalUser instances with names, E-mail, Password credential records and so on. If those aren't needed then InternalUserDao.findMinimalUsersByNames(long, Collection) should be used instead due to performance reasons.
      Specified by:
      findByNames in interface InternalUserDao
      Parameters:
      directoryID - the directory to search for the users.
      usernames - names of users to find
      Returns:
      collection of found users as InternalUsers.
    • findMinimalUsersByNames

      public Collection<MinimalUser> findMinimalUsersByNames(long directoryId, Collection<String> usernames)
      Description copied from interface: InternalUserDao
      Bulk find of users using SQL disjunction. This will return a set of minimal DTOs with just the username, id and directory id.
      Specified by:
      findMinimalUsersByNames in interface InternalUserDao
      Parameters:
      directoryId - the directory to search for the users.
      usernames - names of users to find
      Returns:
      collection of found users as MinimalUsers.
    • findByIds

      public Collection<InternalUser> findByIds(Collection<Long> userIds)
      Description copied from interface: InternalUserDao
      Bulk find of users with the specified database identifiers. The result collection may be smaller than the input if ids that did not match with any users were supplied
      Specified by:
      findByIds in interface InternalUserDao
      Parameters:
      userIds - identifiers of users that will be found
      Returns:
      the matching users
    • findUserAttributes

      public Set<InternalUserAttribute> findUserAttributes(long userId)
    • getCredential

      public PasswordCredential getCredential(long directoryId, String username) throws UserNotFoundException
      Description copied from interface: UserDao
      Returns the credential for the given user. It will always be encrypted.
      Specified by:
      getCredential in interface UserDao
      Throws:
      UserNotFoundException - if the user could not be found
    • getCredentialHistory

      public List<PasswordCredential> getCredentialHistory(long directoryId, String username) throws UserNotFoundException
      Description copied from interface: UserDao
      Returns the previous credentials for the given user, starting with the oldest. May be an empty list if there are no historical credentials.
      Specified by:
      getCredentialHistory in interface UserDao
      Throws:
      UserNotFoundException - if the user could not be found
    • getPersistentClass

      public Class<InternalUser> getPersistentClass()
      Description copied from class: HibernateDao
      All subclasses of HibernateDao must implement this method for HibernateDao.load(Serializable) to work correctly.
      Specified by:
      getPersistentClass in class HibernateDao<InternalUser>
      Returns:
      the entity class for this DAO
    • remove

      public void remove(User user) throws UserNotFoundException
      Description copied from interface: UserDao
      Removes the user.
      Specified by:
      remove in interface UserDao
      Parameters:
      user - the user to remove
      Throws:
      UserNotFoundException - if the user does not exist
    • removeAll

      public void removeAll(long directoryId)
      Specified by:
      removeAll in interface InternalUserDao
    • getAllUsernames

      public List<String> getAllUsernames(long directoryId)
      Description copied from interface: InternalUserDao
      Get all usernames for users belonging to a given directory
      Specified by:
      getAllUsernames in interface InternalUserDao
      Returns:
      list of usernames
    • removeAllUsers

      public BatchResult<String> removeAllUsers(long directoryId, Set<String> userNames)
      Description copied from interface: UserDao
      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.
      Specified by:
      removeAllUsers in interface UserDao
      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)
    • getAllExternalIds

      @Nonnull public Set<String> getAllExternalIds(long directoryId) throws DirectoryNotFoundException
      Description copied from interface: UserDao
      Return all users externalId in the given directory. If a user's externalId is null or an empty String it should not be included.
      Specified by:
      getAllExternalIds in interface UserDao
      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

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

      public Set<Long> findDirectoryIdsContainingUserName(String username)
      Description copied from interface: UserDao
      Find IDs of the directories that contain user with specified username in the cache
      Specified by:
      findDirectoryIdsContainingUserName in interface UserDao
      Parameters:
      username - to be checked
      Returns:
      IDs of the directories
    • removeAttribute

      public void removeAttribute(User user, String attributeName) throws UserNotFoundException
      Description copied from interface: UserDao
      Removes the attributes for the user with the given name. Does nothing if the attribute doesn't exist.
      Specified by:
      removeAttribute in interface UserDao
      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
    • rename

      public InternalUser rename(User user, String newUsername) throws UserNotFoundException, UserAlreadyExistsException
      Description copied from interface: UserDao
      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.

      Specified by:
      rename in interface UserDao
      Parameters:
      user - the user to rename
      newUsername - 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
      See Also:
    • search

      public <T> List<T> search(long directoryID, EntityQuery<T> query)
      Description copied from interface: UserDao
      Returns users matching the search query in the given directory, ordered by name. Returns an empty list if no users match.
      Specified by:
      search in interface UserDao
      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
    • setHqlQueryTranslater

      @Autowired public void setHqlQueryTranslater(HQLQueryTranslater hqlQueryTranslater)
    • setMembershipDao

      @Autowired public void setMembershipDao(InternalMembershipDao internalMembershipDao)
    • setDirectoryDao

      @Autowired public void setDirectoryDao(DirectoryDao directoryDao)
    • removeAttribute

      public org.apache.commons.lang3.builder.DiffResult removeAttribute(InternalUser user, String attributeName)
      Overrides:
      removeAttribute in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
    • storeAttributes

      public void storeAttributes(User user, Map<String,Set<String>> attributes, boolean updateTimestamp) throws UserNotFoundException
      Description copied from interface: UserDao
      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.
      Specified by:
      storeAttributes in interface UserDao
      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

      public InternalUser update(User user) throws UserNotFoundException
      Description copied from interface: UserDao
      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 UserDao.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.

      Specified by:
      update in interface UserDao
      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
      See Also:
    • updateCredential

      public void updateCredential(User user, PasswordCredential credential, int maxPasswordHistory) throws UserNotFoundException
      Description copied from interface: UserDao
      Updates the credential (password) of the user with the same directory and case-insensitive name. The credential must be encrypted.
      Specified by:
      updateCredential in interface UserDao
      Parameters:
      user - the user whose password will be modified
      credential - the new credential for the user
      maxPasswordHistory - 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
    • addAttribute

      public void addAttribute(InternalUser user, String attributeName, String attributeValue)
      Specified by:
      addAttribute in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
    • setAttributeForAllInDirectory

      public void setAttributeForAllInDirectory(long directoryId, String attrName, String value)
      Description copied from interface: UserDao
      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.
      Specified by:
      setAttributeForAllInDirectory in interface UserDao
      Parameters:
      directoryId - The directory to set the attributes in.
      attrName - The attribute name to set.
      value - The attribute value to set.
    • setAuditProcessor

      @Autowired public void setAuditProcessor(@Qualifier("userAuditProcessor") UserAuditProcessor auditProcessor)