Interface UserManager
- All Known Implementing Classes:
DefaultUserManager,MockUserManager
- Since:
- v4.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe current state of a user with regard to the same username existing in other user directories. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDirectoryUpdateUserPassword(com.atlassian.crowd.embedded.api.Directory directory) Checks if the given directory is able to update user passwords.booleancanRenameUser(ApplicationUser user) Test if this user can be renamed.booleanTest if this user's group membership can be updated, i.e.booleancanUpdateUser(ApplicationUser user) Test if this user can be updated, i.e.booleanTest if this user's password can be updated, i.e.createUser(UserDetails userData) Creates a user in the specified directory (userDirectoryId).findUserInDirectory(String userName, Long directoryId) Returns aUserbased on user name and directoryIdGenerates a random password that can be used when the admin has entered a blank password.Deprecated.Since v7.0.Optional<com.atlassian.crowd.embedded.api.Directory>Get theDirectoryin which users will be created by defaultcom.atlassian.crowd.embedded.api.DirectorygetDirectory(Long directoryId) This method returns a mapping of duplicated users to the directories they have their accounts in together with information on whether the accounts are active.com.atlassian.crowd.embedded.api.GroupReturns aGroupbased on user name.com.atlassian.crowd.embedded.api.GroupgetGroupObject(String groupName) Returns aGroupbased on user name.intReturns the total number of users defined in JIRA, regardless of whether they are active or not.getUserById(Long id) Returns a user based in id.getUserByKey(String userKey) Returns anApplicationUserbased on user key.getUserByKeyEvenWhenUnknown(String userKey) Returns anApplicationUserbased on user key.getUserByName(String userName) Returns anApplicationUserbased on user name.getUserByNameEvenWhenUnknown(String userName) Returns anApplicationUserbased on user name.Returns an identity of the user with the specified id.Returns an identity of the user with the specified key.getUserIdentityByUsername(String username) Returns an identity of the user with the specified username.getUserState(ApplicationUser user) This convenience method is equivalent togetUserState(user.getUsername(), user.getDirectoryId())except that anulluser is permitted and returnsUserManager.UserState.INVALID_USER.getUserState(String username, long directoryId) Checks for the existence of this user across all directories to determine whether or not the user exists in the specified directory and whether or not it is shadowing or shadowed by a user with the same username in another active user directory.List<com.atlassian.crowd.embedded.api.Directory>Returns an ordered list of directories that have "read-write" permission.booleanReturns true if any of the directories have permission to update groups.booleanReturns true if any of the directories have permission to update user passwords, false if otherwise.booleanReturns true if at least one User Directory has "read-write" permission.booleanisUserDeleted(ApplicationUser user) Checks if given user is deleted user.booleanChecks if given user is existing uservoidupdateUser(ApplicationUser user) Updates theApplicationUser.booleanCheck if this user is allowed to update their own user details.
-
Method Details
-
getTotalUserCount
int getTotalUserCount()Returns the total number of users defined in JIRA, regardless of whether they are active or not.- Returns:
- the total number of users defined in JIRA
- Since:
- v4.0
-
getAllApplicationUsers
Deprecated.Since v7.0. Only retrieve the users you really need. SeeUserSearchServiceReturns all users defined in JIRA, regardless of whether they are active or not.- Returns:
- the set of all users
- Since:
- v6.0
-
getUserById
Returns a user based in id.- Parameters:
id- user id- Returns:
- user if found or none
-
getUserByKey
Returns anApplicationUserbased on user key.- Parameters:
userKey- the key of the user- Returns:
- the ApplicationUser object
- Since:
- v5.1.1
-
getUserByName
Returns anApplicationUserbased on user name.- Parameters:
userName- the user name of the user- Returns:
- the ApplicationUser object
- Throws:
IllegalStateException- if theCrowdServiceis able to resolveuserNameto aUser, but theUserKeyServicedoes not have a key mapped for it. This is not a valid configuration.- Since:
- v5.1.1
-
getUserByKeyEvenWhenUnknown
Returns anApplicationUserbased on user key.If you want to check if given user is known user - please use
isUserExisting(com.atlassian.jira.user.ApplicationUser)- Parameters:
userKey- the key of the user- Returns:
- the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null if the key is null).
- Since:
- v6.0
-
getUserByNameEvenWhenUnknown
Returns anApplicationUserbased on user name.If you want to check if given user is known user - please use
isUserExisting(com.atlassian.jira.user.ApplicationUser)- Parameters:
userName- the user name of the user- Returns:
- the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null iff the username is null).
- Throws:
IllegalStateException- if theCrowdServiceis able to resolveuserNameto aUser, but theUserKeyServicedoes not have a key mapped for it. This is not a valid configuration.- Since:
- v6.0
-
findUserInDirectory
Returns aUserbased on user name and directoryId- Parameters:
userName- the user name of the userdirectoryId- the Directory to look in- Returns:
- the User object, or null if the user cannot be found including null userName.
- Since:
- v4.3.2
-
canUpdateUser
Test if this user can be updated, i.e. is in a writable directory. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user to be updated.- Parameters:
user- The user to update.- Returns:
- true if the user can be updated.
-
userCanUpdateOwnDetails
Check if this user is allowed to update their own user details.Returns true if the given user is in a read-write directory AND the "External user management" setting is off.
- Parameters:
user- The user- Returns:
- true if the given user is in a read-write directory AND the "External user management" setting is off.
- Since:
- 6.4
-
canRenameUser
Test if this user can be renamed. In addition to the constraints ofcanUpdateUser(ApplicationUser), renaming a user is only allowed when:- The user is in either an
INTERNALorDELEGATINGuser directory; AND - Either JIRA is not configured as a crowd server, or
APKeys.JIRA_OPTION_USER_CROWD_ALLOW_RENAMEis enabled to bypass this check.
- Parameters:
user- The user to rename.- Returns:
- true if the user is not
nulland can be renamed. - Since:
- v6.0
- The user is in either an
-
updateUser
Updates theApplicationUser. The user must have non-null names and email address. If the user's name does not match the name that is currently associated with thekey, then this is implicitly treated as a request to rename the user.- Parameters:
user- The user to update.- Throws:
com.atlassian.crowd.exception.runtime.UserNotFoundException- If the supplied user does not exist in thedirectory.com.atlassian.crowd.exception.runtime.OperationFailedException- If the underlying directory implementation failed to execute the operation.IllegalArgumentException- If something is wrong with the provided user object- Since:
- v6.0
-
canUpdateUserPassword
Test if this user's password can be updated, i.e. is in a writable directory which is not a Delegated LDAP directory. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user to be updated.If the "External user management", or "External password management" setting is on, then you cannot update the password.
- Parameters:
user- The user to update.- Returns:
- true if the user is not
nulland the user's password can be updated.
-
canUpdateGroupMembershipForUser
Test if this user's group membership can be updated, i.e. is in a writable directory or a directory with Local Group support. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user membership to be updated.- Parameters:
user- The user to update.- Returns:
- true if the user is not
nulland can be updated.
-
getGroup
@IncompatibleReturnType(since="5.0", was="com.opensymphony.user.User") com.atlassian.crowd.embedded.api.Group getGroup(@Nullable String groupName) Returns aGroupbased on user name.Warning: previous incarnations of this method returned
com.opensymphony.user.User. This class has now been removed from the JIRA API, meaning that the 5.0 version is not binary or source compatible with earlier versions.- Parameters:
groupName- the user name of the group- Returns:
- the Group object, or null if the group cannot be found including null groupName.
- Since:
- v4.0
-
getGroupObject
Returns aGroupbased on user name.Legacy synonym for
getGroup(String).- Parameters:
groupName- the user name of the group- Returns:
- the Group object, or null if the group cannot be found including null groupName.
- Since:
- v4.3
- See Also:
-
getWritableDirectories
Returns an ordered list of directories that have "read-write" permission. ie those directories that we can add a user to.- Returns:
- an ordered list of directories that have "read-write" permission.
- See Also:
-
getDefaultCreateDirectory
Get theDirectoryin which users will be created by default- Returns:
DirectoryorOption.none()in case there is no writable directories
-
hasWritableDirectory
boolean hasWritableDirectory()Returns true if at least one User Directory has "read-write" permission.This is equivalent to:
getWritableDirectories().size() > 0- Returns:
- true if at least one User Directory has "read-write" permission.
- See Also:
-
hasPasswordWritableDirectory
boolean hasPasswordWritableDirectory()Returns true if any of the directories have permission to update user passwords, false if otherwise.Note that this is not quite the same as
hasWritableDirectory()because of "Internal with LDAP Authentication" directories. These directories are generally read-write but passwords are read-only.- Returns:
- true if any of the directories have permission to update user passwords, false if otherwise.
- See Also:
-
hasGroupWritableDirectory
boolean hasGroupWritableDirectory()Returns true if any of the directories have permission to update groups.Note that this will not always return the same results as
hasWritableDirectory()because you can set "Read-Only with Local Groups" to LDAP directories. These directories are generally read-only but you can create local gropus and assign users to them.- Returns:
- true if any of the directories have permission to update groups, false if otherwise.
- See Also:
-
canDirectoryUpdateUserPassword
boolean canDirectoryUpdateUserPassword(@Nullable com.atlassian.crowd.embedded.api.Directory directory) Checks if the given directory is able to update user passwords.- Parameters:
directory- the Directory- Returns:
- true if the directory can update user passwords, false if otherwise.
-
getDirectory
-
isUserExisting
Checks if given user is existing user- Parameters:
user- possible existing user object - i.e. received fromgetUserByKeyEvenWhenUnknown(String)orgetUserByNameEvenWhenUnknown(String)- Returns:
trueif given user is real user,falseotherwise (also when given object isnull)- See Also:
-
isUserDeleted
Checks if given user is deleted user. Deleted user exists in jira app_users DB table (has user key and username) but does not exist in crowd (no user data eg. Full name, email etc.).- Parameters:
user- possible deleted user object - i.e. received fromgetUserByKeyEvenWhenUnknown(String)orgetUserByNameEvenWhenUnknown(String)- Returns:
trueif given user is user existing in app_users DB table but does not exist in crowd,falseotherwise (also when given object isnull)- Since:
- 8.10
- See Also:
-
generateRandomPassword
Generates a random password that can be used when the admin has entered a blank password.The password is guaranteed to contain at least one upper-case letter, lower-case letter and number in case the backend user Directory has password restrictions.
- Returns:
- a random password.
- Since:
- 6.4
-
getUserState
@ExperimentalApi @Nonnull UserManager.UserState getUserState(@Nonnull String username, long directoryId) Checks for the existence of this user across all directories to determine whether or not the user exists in the specified directory and whether or not it is shadowing or shadowed by a user with the same username in another active user directory.- Parameters:
username- the username to checkdirectoryId- the directory ID of the user directory that the user came from- Returns:
- the shadowing state of the specified user
-
getUserState
This convenience method is equivalent togetUserState(user.getUsername(), user.getDirectoryId())except that anulluser is permitted and returnsUserManager.UserState.INVALID_USER.- Parameters:
user- the user to check- Returns:
- the shadowing state of the specified user
-
getDuplicatedUserMapping
This method returns a mapping of duplicated users to the directories they have their accounts in together with information on whether the accounts are active. Duplicated means that the user has an account in more than one directory and either more than one account is active or the only active account does not belong to the directory with the highest priority.- Returns:
- map of users who have duplicated accounts and their directories.
- Since:
- 8.19
-
createUser
@Nonnull @ExperimentalApi ApplicationUser createUser(@Nonnull UserDetails userData) throws CreateException, PermissionException Creates a user in the specified directory (userDirectoryId). If the directory isOption.none(), the user is created in the default directory (usually an Embedded Crowd internal directory).- Parameters:
userData- the user request containing user details.- Returns:
- the newly created user.
- Throws:
CreateException- unable to create user.PermissionException- unable to create user due to permission error.- Since:
- v7.0
-
getUserIdentityById
Returns an identity of the user with the specified id.- Parameters:
id- user id- Returns:
- user identity or none if no user with the specified key exists.
-
getUserIdentityByKey
Returns an identity of the user with the specified key.- Parameters:
key- user key- Returns:
- user identity or none if no user with the specified key exists.
-
getUserIdentityByUsername
Returns an identity of the user with the specified username.- Parameters:
username- user name- Returns:
- user identity or none if no user with the specified username exists.
-