public class UserDAOHibernate extends InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute> implements InternalUserDao, UserDao
Modifier and Type | Field and Description |
---|---|
static String |
DIRECTORY_ID |
static String |
EXTERNAL_ID |
batchFinder, batchProcessor, logger, statelessSessionBatchProcessor, timeSource
sessionFactory
Constructor and Description |
---|
UserDAOHibernate() |
Modifier and Type | Method and Description |
---|---|
InternalUser |
add(User user,
PasswordCredential credential)
Creates a new user with the given details and credentials.
|
BatchResultWithIdReferences<User> |
addAll(Collection<UserTemplateWithCredentialAndAttributes> users) |
BatchResult<User> |
addAll(Set<UserTemplateWithCredentialAndAttributes> users)
Bulk add users.
|
void |
addAttribute(InternalUser user,
String attributeName,
String attributeValue) |
InternalUser |
findByExternalId(long directoryId,
String externalId)
Finds and returns the user with the given unique/external id and directory ID.
|
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
|
Collection<InternalUser> |
findByIds(Collection<Long> userIds)
Bulk find of users with the specified database identifiers.
|
InternalUser |
findByName(long directoryId,
String username)
Finds and return the user with given name and director ID.
|
Collection<InternalUser> |
findByNames(long directoryID,
Collection<String> usernames)
Bulk find of users using SQL disjunction.
|
InternalUserWithAttributes |
findByNameWithAttributes(long directoryId,
String username)
Finds and returns the user with attributes with the given name and directory ID.
|
List<InternalUser> |
findByNumericAttributeRange(String attributeName,
long min,
long max)
Returns users with the given numeric attribute in the specified range.
|
Set<Long> |
findDirectoryIdsContainingUserName(String username)
Find IDs of the directories that contain user with specified username in the cache
|
Collection<MinimalUser> |
findMinimalUsersByNames(long directoryId,
Collection<String> usernames)
Bulk find of users using SQL disjunction.
|
Set<InternalUserAttribute> |
findUserAttributes(long userId) |
Collection<InternalUserWithPasswordLastChanged> |
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 expire
|
Set<String> |
getAllExternalIds(long directoryId)
Return all users externalId in the given directory.
|
List<String> |
getAllUsernames(long directoryId)
Get all usernames for users belonging to a given directory
|
PasswordCredential |
getCredential(long directoryId,
String username)
Returns the credential for the given user.
|
List<PasswordCredential> |
getCredentialHistory(long directoryId,
String username)
Returns the previous credentials for the given user, starting with the oldest.
|
Class<InternalUser> |
getPersistentClass()
All subclasses of HibernateDao must implement this method for
HibernateDao.load(Serializable) to work
correctly. |
long |
getUserCount(long directoryId)
Return number of users in given directory.
|
void |
remove(User user)
Removes the user.
|
void |
removeAll(long directoryId) |
BatchResult<String> |
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.
|
InternalUser |
rename(User user,
String newUsername)
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 |
storeAttributes(User user,
Map<String,Set<String>> attributes,
boolean updateTimestamp)
Adds or updates a user's attributes with the new Map of attribute values.
|
InternalUser |
update(User user)
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.
|
executeBatchedQueriesIfNecessary, removeAttribute, storeAttributes, updateTimestamps
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
setSessionFactory, withStatelessSession
public static final String EXTERNAL_ID
public static final String DIRECTORY_ID
public InternalUser add(User user, PasswordCredential credential) throws DirectoryNotFoundException, UserAlreadyExistsException
UserDao
add
in interface UserDao
user
- the user to createcredential
- the encrypted password for the user, which may be null if the user's password is not yet availableUserAlreadyExistsException
- if a user with the same directory and name (case-insensitive) already existsDirectoryNotFoundException
public BatchResult<User> addAll(Set<UserTemplateWithCredentialAndAttributes> users)
UserDao
public BatchResultWithIdReferences<User> addAll(Collection<UserTemplateWithCredentialAndAttributes> users)
addAll
in interface InternalUserDao
public InternalUser findByName(long directoryId, String username) throws UserNotFoundException
InternalUserDao
findByName
in interface InternalUserDao
findByName
in interface UserDao
findByName
in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
UserNotFoundException
- if the user could not be foundpublic InternalUser findByExternalId(long directoryId, String externalId) throws UserNotFoundException
UserDao
findByExternalId
in interface UserDao
UserNotFoundException
- if the user could not be foundpublic Map<String,String> findByExternalIds(long directoryId, Set<String> externalIds)
InternalUserDao
findByExternalIds
in interface InternalUserDao
findByExternalIds
in interface UserDao
directoryId
- the directory to search for the usersexternalIds
- the external ids of the users to search forpublic Collection<InternalUserWithPasswordLastChanged> findUsersForPasswordExpiryNotification(Instant currentTime, Duration passwordMaxChangeTime, Duration remindPeriod, long directoryId, int maxResults)
InternalUserDao
findUsersForPasswordExpiryNotification
in interface InternalUserDao
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 userspublic List<InternalUser> findByNumericAttributeRange(String attributeName, long min, long max)
InternalUserDao
findByNumericAttributeRange
in interface InternalUserDao
attributeName
- name of the attribute to matchmin
- minimum numeric value of the attribute to matchmax
- maximum numeric value of the attribute to matchpublic void setAttribute(Collection<InternalUser> users, String attributeName, String attributeValue)
InternalUserDao
setAttribute
in interface InternalUserDao
users
- users to updateattributeName
- name of attribute to updateattributeValue
- value of attribute to updatepublic InternalUserWithAttributes findByNameWithAttributes(long directoryId, String username) throws UserNotFoundException
UserDao
findByNameWithAttributes
in interface UserDao
UserNotFoundException
- if the user could not be foundpublic Collection<InternalUser> findByNames(long directoryID, Collection<String> usernames)
InternalUserDao
InternalUserDao.findMinimalUsersByNames(long, Collection)
should be used instead due to performance reasons.findByNames
in interface InternalUserDao
directoryID
- the directory to search for the users.usernames
- names of users to findpublic Collection<MinimalUser> findMinimalUsersByNames(long directoryId, Collection<String> usernames)
InternalUserDao
findMinimalUsersByNames
in interface InternalUserDao
directoryId
- the directory to search for the users.usernames
- names of users to findpublic Collection<InternalUser> findByIds(Collection<Long> userIds)
InternalUserDao
findByIds
in interface InternalUserDao
userIds
- identifiers of users that will be foundpublic Set<InternalUserAttribute> findUserAttributes(long userId)
public PasswordCredential getCredential(long directoryId, String username) throws UserNotFoundException
UserDao
getCredential
in interface UserDao
UserNotFoundException
- if the user could not be foundpublic List<PasswordCredential> getCredentialHistory(long directoryId, String username) throws UserNotFoundException
UserDao
getCredentialHistory
in interface UserDao
UserNotFoundException
- if the user could not be foundpublic Class<InternalUser> getPersistentClass()
HibernateDao
HibernateDao.load(Serializable)
to work
correctly.getPersistentClass
in class HibernateDao<InternalUser>
public void remove(User user) throws UserNotFoundException
UserDao
remove
in interface UserDao
user
- the user to removeUserNotFoundException
- if the user does not existpublic void removeAll(long directoryId)
removeAll
in interface InternalUserDao
public List<String> getAllUsernames(long directoryId)
InternalUserDao
getAllUsernames
in interface InternalUserDao
public BatchResult<String> removeAllUsers(long directoryId, Set<String> userNames)
UserDao
removeAllUsers
in interface UserDao
directoryId
- the ID of the directory to remove users fromuserNames
- set of users to be removed@Nonnull public Set<String> getAllExternalIds(long directoryId) throws DirectoryNotFoundException
UserDao
null
or an empty String it should not be included.getAllExternalIds
in interface UserDao
directoryId
- the ID of the directoryDirectoryNotFoundException
- when directory with given id does not existpublic long getUserCount(long directoryId) throws DirectoryNotFoundException
UserDao
getUserCount
in interface UserDao
directoryId
- the ID of the directoryDirectoryNotFoundException
- when directory with given id does not existpublic Set<Long> findDirectoryIdsContainingUserName(String username)
UserDao
findDirectoryIdsContainingUserName
in interface UserDao
username
- to be checkedpublic void removeAttribute(User user, String attributeName) throws UserNotFoundException
UserDao
removeAttribute
in interface UserDao
user
- the user whose attribute will be removedattributeName
- the name of the attribute to be removedUserNotFoundException
- if the user cannot be foundpublic InternalUser rename(User user, String newUsername) throws UserNotFoundException, UserAlreadyExistsException
UserDao
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.
rename
in interface UserDao
user
- the user to renamenewUsername
- the new name of the userUserNotFoundException
- if the user cannot be foundUserAlreadyExistsException
- if the new name is already used by a different userUserDao.update(User)
public <T> List<T> search(long directoryID, EntityQuery<T> query)
UserDao
@Autowired public void setHqlQueryTranslater(HQLQueryTranslater hqlQueryTranslater)
@Autowired public void setMembershipDao(InternalMembershipDao internalMembershipDao)
@Autowired public void setDirectoryDao(DirectoryDao directoryDao)
public org.apache.commons.lang3.builder.DiffResult removeAttribute(InternalUser user, String attributeName)
removeAttribute
in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
public void storeAttributes(User user, Map<String,Set<String>> attributes, boolean updateTimestamp) throws UserNotFoundException
UserDao
storeAttributes
in interface UserDao
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)UserNotFoundException
- user with supplied username does not exist.public InternalUser update(User user) throws UserNotFoundException
UserDao
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.
update
in interface UserDao
user
- the user details, which should have the same name as the user to modifyUserNotFoundException
- if there is no user with the same name (case-insensitive) and directory as the
user providedUserDao.rename(User, String)
public void updateCredential(User user, PasswordCredential credential, int maxPasswordHistory) throws UserNotFoundException
UserDao
updateCredential
in interface UserDao
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 matchUserNotFoundException
- if there is no user with the same name (case-insensitive) and directory as the user providedpublic void addAttribute(InternalUser user, String attributeName, String attributeValue)
addAttribute
in class InternalDirectoryEntityHibernateDao<InternalUser,InternalUserAttribute>
public void setAttributeForAllInDirectory(long directoryId, String attrName, String value)
UserDao
setAttributeForAllInDirectory
in interface UserDao
directoryId
- The directory to set the attributes in.attrName
- The attribute name to set.value
- The attribute value to set.@Autowired public void setAuditProcessor(@Qualifier(value="userAuditProcessor") UserAuditProcessor auditProcessor)
Copyright © 2024 Atlassian. All rights reserved.