Class UserDAOHibernate
- All Implemented Interfaces:
InternalUserDao
,UserDao
-
Field Summary
Fields inherited from class com.atlassian.crowd.util.persistence.hibernate.HibernateDao
batchFinder, batchProcessor, logger, statelessSessionBatchProcessor, timeSource
Fields inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
sessionFactory
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(User user, PasswordCredential credential) Creates a new user with the given details and credentials.Bulk add users.void
addAttribute
(InternalUser user, String attributeName, String attributeValue) 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 usernamefindByIds
(Collection<Long> userIds) Bulk find of users with the specified database identifiers.findByName
(long directoryId, String username) Finds and return the user with given name and director ID.findByNames
(long directoryID, Collection<String> usernames) Bulk find of users using SQL disjunction.findByNameWithAttributes
(long directoryId, String username) Finds and returns the user with attributes with the given name and directory ID.findByNumericAttributeRange
(String attributeName, long min, long max) Returns users with the given numeric attribute in the specified range.findDirectoryIdsContainingUserName
(String username) Find IDs of the directories that contain user with specified username in the cachefindMinimalUsersByNames
(long directoryId, Collection<String> usernames) Bulk find of users using SQL disjunction.findUserAttributes
(long userId) findUsersForPasswordExpiryNotification
(Instant currentTime, Duration passwordMaxChangeTime, Duration remindPeriod, long directoryId, int maxResults) Searches the specified directory for Internal Users who will be notified, that their passwords will soon expiregetAllExternalIds
(long directoryId) Return all users externalId in the given directory.getAllUsernames
(long directoryId) Get all usernames for users belonging to a given directorygetCredential
(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.All subclasses of HibernateDao must implement this method forHibernateDao.load(Serializable)
to work correctly.long
getUserCount
(long directoryId) Return number of users in given directory.void
Removes the user.void
removeAll
(long directoryId) removeAllUsers
(long directoryId, Set<String> userNames) Bulk remove all the given users from directory.org.apache.commons.lang3.builder.DiffResult
removeAttribute
(InternalUser user, String attributeName) 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
setAttribute
(Collection<InternalUser> users, String attributeName, String attributeValue) Sets the specified attribute for all specified users and after executing this, every user will have exactly one attribute with that name.void
setAttributeForAllInDirectory
(long directoryId, String attrName, String value) 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
setAuditProcessor
(UserAuditProcessor auditProcessor) void
setDirectoryDao
(DirectoryDao directoryDao) void
setHqlQueryTranslater
(HQLQueryTranslater hqlQueryTranslater) void
setMembershipDao
(InternalMembershipDao internalMembershipDao) 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 maxPasswordHistory) Updates the credential (password) of the user with the same directory and case-insensitive name.Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.InternalDirectoryEntityHibernateDao
executeBatchedQueriesIfNecessary, removeAttribute, storeAttributes, updateTimestamps
Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.HibernateDao
createDeleteQuery, createDeleteQuery, createQuery, createQuery, executeHQLQuery, findAllInternal, findByProperties, findByPropertiesOptional, findByProperty, findByProperty, findByPropertyOptional, findByPropertyOrThrow, getCountByProperties, load, load, loadOptional, loadReference, loadReference, remove, removeByIdIfPresent, save, saveOrUpdate, session, setBatchFinder, setBatchProcessor, setClock, setStatelessSessionBatchProcessor, toPredicates, update
Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
setSessionFactory, withStatelessSession
-
Field Details
-
EXTERNAL_ID
- See Also:
-
DIRECTORY_ID
- See Also:
-
-
Constructor Details
-
UserDAOHibernate
public UserDAOHibernate()
-
-
Method Details
-
add
public InternalUser add(User user, PasswordCredential credential) throws DirectoryNotFoundException, UserAlreadyExistsException 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 interfaceUserDao
- 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 existsDirectoryNotFoundException
-
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. -
addAll
public BatchResultWithIdReferences<User> addAll(Collection<UserTemplateWithCredentialAndAttributes> users) - Specified by:
addAll
in interfaceInternalUserDao
-
findByName
Description copied from interface:InternalUserDao
Finds and return the user with given name and director ID.- Specified by:
findByName
in interfaceInternalUserDao
- Specified by:
findByName
in interfaceUserDao
- Specified by:
findByName
in classInternalDirectoryEntityHibernateDao<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 interfaceUserDao
- Throws:
UserNotFoundException
- if the user could not be found
-
findByExternalIds
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 interfaceInternalUserDao
- Specified by:
findByExternalIds
in interfaceUserDao
- Parameters:
directoryId
- the directory to search for the usersexternalIds
- 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 interfaceInternalUserDao
- Parameters:
currentTime
- timestamp of current timepasswordMaxChangeTime
- 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
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 interfaceInternalUserDao
- Parameters:
attributeName
- name of the attribute to matchmin
- minimum numeric value of the attribute to matchmax
- 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 interfaceInternalUserDao
- Parameters:
users
- users to updateattributeName
- name of attribute to updateattributeValue
- 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 interfaceUserDao
- Throws:
UserNotFoundException
- if the user could not be found
-
findByNames
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 thenInternalUserDao.findMinimalUsersByNames(long, Collection)
should be used instead due to performance reasons.- Specified by:
findByNames
in interfaceInternalUserDao
- 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 interfaceInternalUserDao
- Parameters:
directoryId
- the directory to search for the users.usernames
- names of users to find- Returns:
- collection of found users as MinimalUsers.
-
findByIds
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 interfaceInternalUserDao
- Parameters:
userIds
- identifiers of users that will be found- Returns:
- the matching users
-
findUserAttributes
-
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 interfaceUserDao
- 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 interfaceUserDao
- Throws:
UserNotFoundException
- if the user could not be found
-
getPersistentClass
Description copied from class:HibernateDao
All subclasses of HibernateDao must implement this method forHibernateDao.load(Serializable)
to work correctly.- Specified by:
getPersistentClass
in classHibernateDao<InternalUser>
- Returns:
- the entity class for this DAO
-
remove
Description copied from interface:UserDao
Removes the user.- Specified by:
remove
in interfaceUserDao
- Parameters:
user
- the user to remove- Throws:
UserNotFoundException
- if the user does not exist
-
removeAll
public void removeAll(long directoryId) - Specified by:
removeAll
in interfaceInternalUserDao
-
getAllUsernames
Description copied from interface:InternalUserDao
Get all usernames for users belonging to a given directory- Specified by:
getAllUsernames
in interfaceInternalUserDao
- Returns:
- list of usernames
-
removeAllUsers
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 interfaceUserDao
- 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)
-
getAllExternalIds
Description copied from interface:UserDao
Return all users externalId in the given directory. If a user's externalId isnull
or an empty String it should not be included.- Specified by:
getAllExternalIds
in interfaceUserDao
- 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
Description copied from interface:UserDao
Return number of users in given directory.- Specified by:
getUserCount
in interfaceUserDao
- Parameters:
directoryId
- the ID of the directory- Returns:
- user count
- Throws:
DirectoryNotFoundException
- when directory with given id does not exist
-
findDirectoryIdsContainingUserName
Description copied from interface:UserDao
Find IDs of the directories that contain user with specified username in the cache- Specified by:
findDirectoryIdsContainingUserName
in interfaceUserDao
- Parameters:
username
- to be checked- Returns:
- IDs of the directories
-
removeAttribute
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 interfaceUserDao
- 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
-
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 interfaceUserDao
- Parameters:
user
- the user to renamenewUsername
- 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 user- See Also:
-
search
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. -
setHqlQueryTranslater
-
setMembershipDao
-
setDirectoryDao
-
removeAttribute
public org.apache.commons.lang3.builder.DiffResult removeAttribute(InternalUser user, String attributeName) - Overrides:
removeAttribute
in classInternalDirectoryEntityHibernateDao<InternalUser,
InternalUserAttribute>
-
storeAttributes
public void storeAttributes(User user, Map<String, Set<String>> attributes, boolean updateTimestamp) throws UserNotFoundExceptionDescription 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 interfaceUserDao
- 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
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 interfaceUserDao
- 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 interfaceUserDao
- Parameters:
user
- the user whose password will be modifiedcredential
- the new credential for the usermaxPasswordHistory
- 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
- Specified by:
addAttribute
in classInternalDirectoryEntityHibernateDao<InternalUser,
InternalUserAttribute>
-
setAttributeForAllInDirectory
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 interfaceUserDao
- 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)
-