Interface UserDao
- All Known Subinterfaces:
InternalUserDao
- All Known Implementing Classes:
UserDAOHibernate
User
s, PasswordCredential
s and user attributes.-
Method Summary
Modifier and TypeMethodDescriptionadd
(User user, PasswordCredential credential) Creates a new user with the given details and credentials.Bulk add users.findByExternalId
(long directoryId, String externalId) Finds and returns the user with the given unique/external id and directory ID.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 usernamefindByName
(long directoryId, String userName) Finds and returns the user with the given name and directory ID.findByNameWithAttributes
(long directoryId, String userName) Finds and returns the user with attributes with the given name and directory ID.findDirectoryIdsContainingUserName
(String username) Find IDs of the directories that contain user with specified username in the cachegetAllExternalIds
(long directoryId) Return all users externalId in the given directory.getCredential
(long directoryId, String userName) Returns the credential for the given user.getCredentialHistory
(long directoryId, String userName) Returns the previous credentials for the given user, starting with the oldest.long
getUserCount
(long directoryId) Return number of users in given directory.void
Removes the user.removeAllUsers
(long directoryId, Set<String> userNames) Bulk remove all the given users from directory.void
removeAttribute
(User user, String attributeName) Removes the attributes for the user with the given name.Changes the user's name to the provided new name.<T> List<T>
search
(long directoryId, EntityQuery<T> query) Returns users matching the search query in the given directory, ordered by name.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.void
Adds or updates a user's attributes with the new Map of attribute values.Updates all the user properties (except the username) of the user with the same directory and case-insensitive name.void
updateCredential
(User user, PasswordCredential credential, int maxCredentialHistory) Updates the credential (password) of the user with the same directory and case-insensitive name.
-
Method Details
-
findByName
Finds and returns the user with the given name and directory ID.- Throws:
UserNotFoundException
- if the user could not be found
-
findByExternalId
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
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
User add(User user, PasswordCredential credential) throws UserAlreadyExistsException, IllegalArgumentException, DirectoryNotFoundException 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 createcredential
- 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 existsIllegalArgumentException
- if the user name, directory or any details are null, or if the credential is not encryptedDirectoryNotFoundException
-
storeAttributes
void storeAttributes(User user, Map<String, Set<String>> attributes, boolean updateTimestamp) throws UserNotFoundExceptionAdds 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 forattributes
- 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 providedIllegalArgumentException
- 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 modifiedcredential
- the new credential for the usermaxCredentialHistory
- 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 providedIllegalArgumentException
- if the credential is null or not encrypted
-
rename
User rename(User user, String newName) throws UserNotFoundException, UserAlreadyExistsException, IllegalArgumentException 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 renamenewName
- the new name of the user- Returns:
- the updated user
- Throws:
UserNotFoundException
- if the user cannot be foundUserAlreadyExistsException
- if the new name is already used by a different userIllegalArgumentException
- if the new name is null- See Also:
-
removeAttribute
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 removedattributeName
- the name of the attribute to be removed- Throws:
UserNotFoundException
- if the user cannot be found
-
remove
Removes the user.- Parameters:
user
- the user to remove- Throws:
UserNotFoundException
- if the user does not exist
-
search
Returns users matching the search query in the given directory, ordered by name. Returns 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
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 fromuserNames
- set of users to be removed- Returns:
- batch result containing successes (removed users) and failures (users which were not removed)
-
setAttributeForAllInDirectory
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
Return all users externalId in the given directory. If a user's externalId isnull
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
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
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
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 usersexternalIds
- the external ids of the users to search for
-