Interface UserService
users
. This service also offers limited ability to update
the current user.
A note about user stores and deleted users: the system uses Crowd to provide access to LDAP servers, other Crowd
servers, or Jira (which is able to serve as a central user store for other Atlassian products). Crowd maintains
a local cache of users, which is termed the "user store" by this service. The system also maintains a secondary
table of users, outside Crowd, allowing it to decorate Crowd users with additional properties as well as to anchor
relationships between users and their data, such as comments
and
pull requests
.
Because the Crowd user store is a cache of users managed elsewhere, be they in LDAP, Jira, etc., it is possible
for users to be deleted from that user store but still exist in the system's secondary user table. Such users are
termed "deleted", and, when retrieved, will only offer a minimal set of data. Generally, after deletion, only a
user's username
is still available. Display names, e-mail addresses and other data
are managed by Crowd and are lost when the user is deleted.
In addition to deleted users, Crowd has the concept of an inactive user. These users cannot log in and
may or may not have an associated ApplicationUser
. Inactive users are handled consistently as deleted and
both are taken into consideration when determining ApplicationUser.isActive()
.
Groups are reported as strings. When persisting or displaying groups, it is recommended to store the group name as reported by the API; when performing tests for equality on groups, it is recommended to ignore case.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteAvatar
(ApplicationUser user) Delete the avatar associated with a user.boolean
existsGroup
(String groupName) Retrieves a flag indicating whether the specified group exists.findGroups
(PageRequest pageRequest) Retrieves a page of groups.findGroupsByName
(String groupName, PageRequest pageRequest) Retrieves a page of groups, optionally filtering the returned results to those containing the specifiedgroupName
.findGroupsByPrefix
(String groupPrefix, PageRequest pageRequest) Retrieves a page of groups, optionally filtering the returned results to those beginning with the specifiedgroupPrefix
.findGroupsByUser
(String username, PageRequest pageRequest) Retrieves a page of groups which the specified user is a member of.findUserByEmail
(String value) findUserByNameOrEmail
(String value) findUsers
(PageRequest pageRequest) findUsersByGroup
(String groupName, PageRequest pageRequest) Retrieves a page ofactive
users which are members of the specified group.findUsersByName
(String username, PageRequest pageRequest) getAvatar
(ApplicationUser user, int size) Retrieves the current avatar for the specified user at a requested size.getServiceUserByName
(String username) getServiceUserByName
(String username, boolean inactive) Retrieves aServiceUser
by itsusername
, optionally returning the user even if it has been marked inactive.getServiceUserBySlug
(String slug) getServiceUsersByName
(Set<String> usernames) getServiceUsersByName
(Set<String> usernames, boolean inactive) Retrieves a set ofServiceUser
s by theirusernames
, optionally including deleted service users.Retrieves the service user used for system activity.getUserById
(int id) Retrieves aApplicationUser
by itsID
.getUserById
(int id, boolean inactive) Retrieves aApplicationUser
by itsID
.getUserByName
(String username) getUserByName
(String username, boolean inactive) Retrieves aApplicationUser
by itsusername
, optionally returning the user even if it has been removed from the underlying user store.getUserBySlug
(String slug) getUsersById
(Set<Integer> ids) getUsersById
(Set<Integer> ids, boolean inactive) Retrieves a set ofApplicationUser
s by theirIDs
, optionally including users who have been removed from the underlying user store.getUsersByName
(Set<String> usernames) getUsersByName
(Set<String> usernames, boolean inactive) Retrieves a set ofApplicationUser
s by theirusernames
, optionally including users who have been removed from the underlying user store.boolean
isUserActive
(ApplicationUser user) Retrieves the active state of the user.boolean
isUserActive
(ApplicationUser user, boolean checkDirectory) Retrieves the active state of the user.boolean
isUserInGroup
(ApplicationUser user, String groupName) Retrieves a flag indicating whether the specified user is a member of the specified group.boolean
isUserInGroup
(String username, String groupName) Retrieves a flag indicating whether the specified user is a member of the specified group.search
(UserSearchRequest request, PageRequest pageRequest) void
updateAvatar
(ApplicationUser user, AvatarSupplier supplier) Updates the specified user's avatar, replacing it with the one contained in the providedsupplier
.void
updateAvatar
(ApplicationUser user, String uri) Updates the specified user's avatar, replacing it with the one contained in the provided data URI.void
updatePassword
(String currentPassword, String newPassword) Updates the password for the current user.updateUser
(String displayName, String emailAddress) Deprecated.in 9.4 for removal in 10.0.updateUser
(String displayName, String emailAddress, String currentPassword) Updates thedisplay name
ande-mail address
for the current user.
-
Method Details
-
deleteAvatar
Delete the avatar associated with a user.This will revert the avatar of the user in the UI to their Gravatar image (if the Gravatar integration is enabled) or to the default user avatar (if the Gravatar integration is disabled)
- Parameters:
user
- the user whose (local) avatar will be removed
-
existsGroup
Retrieves a flag indicating whether the specified group exists.- Parameters:
groupName
- the group name- Returns:
true
if a group with the specified name exists in any directory; otherwise,false
-
findGroups
Retrieves a page of groups.Note: To filter the retrieved groups by name, use
findGroupsByName(String, PageRequest)
instead.- Parameters:
pageRequest
- defines the page of groups to retrieve- Returns:
- the requested page of groups, which may be empty but never
null
- See Also:
-
findGroupsByName
@Nonnull Page<String> findGroupsByName(@Nullable String groupName, @Nonnull PageRequest pageRequest) Retrieves a page of groups, optionally filtering the returned results to those containing the specifiedgroupName
. If the providedgroupName
isnull
, this method behaves identically tofindGroups(PageRequest)
.- Parameters:
groupName
- 0 or more characters to apply as a filter on returned groupspageRequest
- defines the page of groups to retrieve- Returns:
- the requested page of groups, potentially filtered, which may be empty but never
null
- See Also:
-
findGroupsByPrefix
@Nonnull Page<String> findGroupsByPrefix(@Nullable String groupPrefix, @Nonnull PageRequest pageRequest) Retrieves a page of groups, optionally filtering the returned results to those beginning with the specifiedgroupPrefix
. If the providedgroupPrefix
isnull
, this method behaves identically tofindGroups(PageRequest)
.This method varies slightly from
findGroupsByName(String, PageRequest)
, which will match the specified name at the beginning of any word boundary in the group. For example, "test-group" will match "group". With this method, a prefix of "group" will not match "test-group".- Parameters:
groupPrefix
- 0 or more characters defining a prefix which returned group names must start withpageRequest
- defines the page of groups to retrieve- Returns:
- the requested page of groups, potentially filtered by prefix, which may be empty but never
null
- See Also:
-
findGroupsByUser
Retrieves a page of groups which the specified user is a member of. Theusername
provided must match exactly in order for any results to be returned.- Parameters:
username
- the exact name of the user to retrieve groups forpageRequest
- defines the page of groups to retrieve- Returns:
- the requested page of groups, which may be empty but never
null
- See Also:
-
findUserByEmail
- Parameters:
value
- the value to match against e-mail addresses- Returns:
- a user whose e-mail address matches the specified value, or
null
if no matching user was found - Since:
- 5.1
-
findUserByNameOrEmail
Retrieve the firstactive
normal
user whose username or e-mail address exactly matches the providedvalue
.Usernames are the preferred match, so they will be tested first. If no user exists with a username matching the value, e-mail addresses will then be checked.
- Parameters:
value
- the value to match, first against usernames and then against e-mail addresses- Returns:
- a user whose username or e-mail address matches the specified value, or
null
if no matching user was found
-
findUsers
Retrieves a page ofactive
normal
users.Note: To filter the retrieved users by name, use
findUsersByName(String, PageRequest)
instead.- Parameters:
pageRequest
- defines the page of users to retrieve- Returns:
- the requested page of users, which may be empty but never
null
- See Also:
-
findUsersByName
@Nonnull Page<ApplicationUser> findUsersByName(@Nullable String username, @Nonnull PageRequest pageRequest) Retrieves a page ofactive
normal
users, optionally filtering the returned results to those containing the specifiedusername
. If the providedusername
isnull
, this method behaves identically tofindUsers(PageRequest)
. Otherwise, theusername
is matched against:- Parameters:
username
- 0 or more characters to apply as a filter on returned userspageRequest
- defines the page of users to retrieve- Returns:
- the requested page of users, potentially filtered, which may be empty but never
null
- See Also:
-
findUsersByGroup
@Nonnull Page<ApplicationUser> findUsersByGroup(@Nonnull String groupName, @Nonnull PageRequest pageRequest) Retrieves a page ofactive
users which are members of the specified group. ThegroupName
provided must match exactly in order for any results to be returned.- Parameters:
groupName
- the exact name of the group to retrieve members forpageRequest
- defines the page of users to retrieve- Returns:
- the requested page of users, which may be empty but never
null
- See Also:
-
getAvatar
Retrieves the current avatar for the specified user at a requested size. Avatars are square, so the size provided here is used as both height and width for the avatar.The requested size will be normalised to fall within a well-defined set sizes. The supported sizes are:
- 256
- 128
- 96
- 64
- 48
- Parameters:
user
- the user whose avatar should be retrievedsize
- the desired height and width for the avatar- Returns:
- a supplier which can be used to access the requested avatar
-
getServiceUserByName
Retrieves anactive
ServiceUser
by itsusername
.This method will not return inactive users; use
getServiceUserByName(String, boolean)
instead if inactive users are desired.- Parameters:
username
- the username of the user to retrieve- Returns:
- the user with the specified username, or
null
if no matching user exists or the matching user has been deleted from the user store
-
getServiceUserByName
Retrieves aServiceUser
by itsusername
, optionally returning the user even if it has been marked inactive.If requested, this method will return inactive users.
- Parameters:
username
- the username of the user to retrieveinactive
-true
if inactive users should be returned,false
otherwise.- Returns:
- the user with the specified username, or
null
if no matching user exists or the matching user is inactive and inactive users were not requested
-
getServiceUserBySlug
Retrieves anactive
ServiceUser
by its exact (case-sensitive)slug
.This method will not return inactive users.
- Parameters:
slug
- the slug of the user to retrieve- Returns:
- the user with the specified slug, or
null
if no matching user exists or the matching user is inactive
-
getServiceUsersByName
Retrieves a set ofactive
ServiceUser
s by theirusernames
.This method will not return inactive users; use
getServiceUsersByName(Set, boolean)
instead if inactive users are desired.- Parameters:
usernames
- the usernames of the users to retrieve- Returns:
- users matching usernames from the specified set, if any
- Since:
- 5.13
-
getServiceUsersByName
Retrieves a set ofServiceUser
s by theirusernames
, optionally including deleted service users.If requested, this method will return deleted users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
usernames
- the usernames of the users to retrieveinactive
-true
if deleted and inactive users should be returned,false
otherwise- Returns:
- users matching usernames from the specified set, if any
- Since:
- 5.13
-
getSystemServiceUser
Retrieves the service user used for system activity.- Returns:
- the system service user
- Since:
- 9.0
-
getUserById
Retrieves aApplicationUser
by itsID
.This method will not return deleted or inactive users; use
getUserById(int, boolean)
instead if deleted users are desired. See the class documentation for more details about what "deleted" means in this context.- Parameters:
id
- the ID of the user to retrieve- Returns:
- the user with the specified ID, or
null
if no matching user exists
-
getUserById
Retrieves aApplicationUser
by itsID
.If requested, this method will return deleted or inactive users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
id
- the ID of the user to retrieveinactive
-true
if deleted and inactive users should be returned,false
otherwise.- Returns:
- the user with the specified ID, or
null
if no matching user exists
-
getUserByName
Retrieves anactive
ApplicationUser
by itsusername
.This method will not return deleted or inactive users; use
getUserByName(String, boolean)
instead if deleted users are desired. See the class documentation for more details about what "deleted" means in this context.- Parameters:
username
- the username of the user to retrieve- Returns:
- the user with the specified username, or
null
if no matching user exists or the matching user has been deleted from the user store
-
getUserByName
Retrieves aApplicationUser
by itsusername
, optionally returning the user even if it has been removed from the underlying user store.If requested, this method will return deleted or inactive users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
username
- the username of the user to retrieveinactive
-true
if deleted and inactive users should be returned,false
otherwise.- Returns:
- the user with the specified username, or
null
if no matching user exists or the matching user has been deleted from the user store and deleted users were not requested
-
getUsersById
Retrieves a set ofactive
ApplicationUser
s by theirIDs
.This method will not return deleted or inactive users; use
getUsersById(Set, boolean)
instead if deleted users are desired. See the class documentation for more details about what "deleted" means in this context.- Parameters:
ids
- the IDs of the users to retrieve- Returns:
- a set of non-deleted users
-
getUsersById
Retrieves a set ofApplicationUser
s by theirIDs
, optionally including users who have been removed from the underlying user store.If requested, this method will return deleted users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
ids
- the IDs of the users to retrieveinactive
-true
if deleted and inactive users should be returned,false
otherwise- Returns:
- users matching IDs from the specified set, if any
-
getUserBySlug
Retrieves anactive
ApplicationUser
by its exact (case-sensitive)slug
.This method will not return deleted or inactive users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
slug
- the slug of the user to retrieve- Returns:
- the user with the specified slug, or
null
if no matching user exists or the matching user has been deleted or is inactive
-
getUsersByName
Retrieves a set ofactive
ApplicationUser
s by theirusernames
.This method will not return deleted or inactive users; use
getUsersByName(Set, boolean)
instead if deleted users are desired. See the class documentation for more details about what "deleted" means in this context.- Parameters:
usernames
- the usernames of the users to retrieve- Returns:
- users matching usernames from the specified set, if any
-
getUsersByName
Retrieves a set ofApplicationUser
s by theirusernames
, optionally including users who have been removed from the underlying user store.If requested, this method will return deleted users. See the class documentation for more details about what "deleted" means in this context.
- Parameters:
usernames
- the usernames of the users to retrieveinactive
-true
if deleted and inactive users should be returned,false
otherwise- Returns:
- users matching usernames from the specified set, if any
-
isUserActive
Retrieves the active state of the user. Returning true if the user can be found in the authoritative directory in which they're stored, and the user is active within that directory.- Parameters:
user
- the user to query activity state for- Returns:
- true if the user has been found and is active
- Since:
- 4.10
-
isUserActive
Retrieves the active state of the user. Returning true if the user can be found in the directory in which they're stored, and the user is active within that directory. Checks their authorative remote directory if one exists andcheckDirectory
is true.- Parameters:
user
- the user to query activity state forcheckDirectory
- whether to check the users authoriative directory to confirm their active state- Returns:
- true if the user has been found and is active
- Since:
- 4.14
-
isUserInGroup
Retrieves a flag indicating whether the specified user is a member of the specified group. If the provided user does not exist in the user store, or if the group does not exist,false
is returned in preference to throwing an exception.- Parameters:
user
- the user to query group membership forgroupName
- the exact name of the group to query membership in- Returns:
true
if the specified user is a member of the specified group; otherwise,false
if the user does not exist in the backing store, the group does not exist or the user is not a member of the group
-
isUserInGroup
Retrieves a flag indicating whether the specified user is a member of the specified group. If the user or group does not exist,false
is returned in preference to throwing an exception.- Parameters:
username
- the exact name of the user to query group membership forgroupName
- the exact name of the group to query membership in- Returns:
true
if the specified user is a member of the specified group; otherwise,false
if the user does not exist, the group does not exist or the user is not a member of the group
-
search
@Nonnull Page<ApplicationUser> search(@Nonnull UserSearchRequest request, @Nonnull PageRequest pageRequest) -
updateAvatar
Updates the specified user's avatar, replacing it with the one contained in the providedsupplier
. Updating a user's avatar also updates the avatar for theirpersonal project
.Previous avatars are not retained. When a user's avatar is updated, the previous avatar is removed. To reuse a previous avatar, it must be provided again.
- Parameters:
user
- the user to update the avatar forsupplier
- a supplier providing access to the new avatar to use
-
updateAvatar
Updates the specified user's avatar, replacing it with the one contained in the provided data URI. Updating a user's avatar also updates the avatar for theirpersonal project
.The data URI is required to contain Base64-encoded image data, and should be in the format:
data:(content type, e.g. image/png);base64,(data)
If the data is not Base64-encoded, or if a character set is defined in the URI, it will be rejected.Previous avatars are not retained. When a project's avatar is updated, the previous avatar is removed. To reuse a previous avatar, it must be provided again.
- Parameters:
user
- the user to update the avatar foruri
- a data URI containing a Base64-encoded avatar image
-
updatePassword
void updatePassword(@Nonnull String currentPassword, @Nonnull String newPassword) throws IncorrectPasswordAuthenticationException, ServerException Updates the password for the current user.The current user always has permission to modify their own password. However, the underlying user store may not support the operation, or it may apply specific requirements to the complexity of the new password. If the user store is read-only, or the password does not meet complexity requirements, a
ServerException
is thrown.- Parameters:
currentPassword
- the current user's current passwordnewPassword
- the current user's desired new password- Throws:
IncorrectPasswordAuthenticationException
- if the current password provided does not match the user's current passwordServerException
- if the underlying user store does not support updating users' passwords
-
updateUser
@Deprecated @Nonnull ApplicationUser updateUser(@Nonnull String displayName, @Nonnull String emailAddress) throws ServerException Deprecated.in 9.4 for removal in 10.0. UseupdateUser(String, String, String)
instead.Updates thedisplay name
ande-mail address
for the current user.The current user always has permission to modify their own details. However, the underlying user store may not support the operation. A
ServerException
will be thrown if the user store is read-only.- Parameters:
displayName
- the new display name for the current useremailAddress
- the new e-mail address for the current user- Returns:
- the current user, with the updated details
- Throws:
ServerException
- if the underlying user store does not support updating users' details
-
updateUser
@Nonnull ApplicationUser updateUser(@Nonnull String displayName, @Nonnull String emailAddress, @Nullable String currentPassword) throws IncorrectPasswordAuthenticationException, ServerException Updates thedisplay name
ande-mail address
for the current user.The current user always has permission to modify their own details. However, the underlying user store may not support the operation. A
ServerException
will be thrown if the user store is read-only.When updating the email address, the user's current password also needs to be provided, unless the
StandardFeature.ENFORCE_PASSWORD_USER_EMAIL_UPDATE
feature is disabled.- Parameters:
displayName
- the new display name for the current useremailAddress
- the new e-mail address for the current usercurrentPassword
- the current user's current password- Returns:
- the current user, with the updated details
- Throws:
IncorrectPasswordAuthenticationException
- if the system requires users to provide their password when updating their email, and the password provided does not match the user's current passwordArgumentValidationException
- if the user's current password was required, but not providedServerException
- if the underlying user store does not support updating users' passwords- Since:
- 9.4
-