public 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.
UserAdminService
Modifier and Type | Method and Description |
---|---|
void |
deleteAvatar(ApplicationUser user)
Delete the avatar associated with a user.
|
boolean |
existsGroup(String groupName)
Retrieves a flag indicating whether the specified group exists.
|
Page<String> |
findGroups(PageRequest pageRequest)
Retrieves a page of groups.
|
Page<String> |
findGroupsByName(String groupName,
PageRequest pageRequest)
Retrieves a page of groups, optionally filtering the returned results to those containing the specified
groupName . |
Page<String> |
findGroupsByPrefix(String groupPrefix,
PageRequest pageRequest)
Retrieves a page of groups, optionally filtering the returned results to those beginning with the specified
groupPrefix . |
Page<String> |
findGroupsByUser(String username,
PageRequest pageRequest)
Retrieves a page of groups which the specified user is a member of.
|
ApplicationUser |
findUserByEmail(String value)
|
ApplicationUser |
findUserByNameOrEmail(String value)
|
Page<ApplicationUser> |
findUsers(PageRequest pageRequest)
|
Page<ApplicationUser> |
findUsersByGroup(String groupName,
PageRequest pageRequest)
Retrieves a page of
active users which are members of the specified group. |
Page<ApplicationUser> |
findUsersByName(String username,
PageRequest pageRequest)
|
CacheableAvatarSupplier |
getAvatar(ApplicationUser user,
int size)
Retrieves the current avatar for the specified user at a requested size.
|
ServiceUser |
getServiceUserByName(String username)
|
ServiceUser |
getServiceUserByName(String username,
boolean inactive)
Retrieves a
ServiceUser by its username , optionally returning the user even
if it has been marked inactive. |
ServiceUser |
getServiceUserBySlug(String slug)
|
Set<ServiceUser> |
getServiceUsersByName(Set<String> usernames)
|
Set<ServiceUser> |
getServiceUsersByName(Set<String> usernames,
boolean inactive)
Retrieves a set of
ServiceUser s by their usernames , optionally including
deleted service users. |
ApplicationUser |
getUserById(int id)
Retrieves a
ApplicationUser by its ID . |
ApplicationUser |
getUserById(int id,
boolean inactive)
Retrieves a
ApplicationUser by its ID . |
ApplicationUser |
getUserByName(String username)
|
ApplicationUser |
getUserByName(String username,
boolean inactive)
Retrieves a
ApplicationUser by its username , optionally returning the user even
if it has been removed from the underlying user store. |
ApplicationUser |
getUserBySlug(String slug)
|
Set<ApplicationUser> |
getUsersById(Set<Integer> ids)
|
Set<ApplicationUser> |
getUsersById(Set<Integer> ids,
boolean inactive)
Retrieves a set of
ApplicationUser s by their IDs , optionally including users who
have been removed from the underlying user store. |
Set<ApplicationUser> |
getUsersByName(Set<String> usernames)
|
Set<ApplicationUser> |
getUsersByName(Set<String> usernames,
boolean inactive)
Retrieves a set of
ApplicationUser s by their usernames , 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.
|
Page<ApplicationUser> |
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 provided
supplier . |
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.
|
ApplicationUser |
updateUser(String displayName,
String emailAddress)
Updates the
display name and e-mail address for the current user. |
void deleteAvatar(@Nonnull ApplicationUser 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)
user
- the user whose (local) avatar will be removedboolean existsGroup(String groupName)
groupName
- the group nametrue
if a group with the specified name exists in any directory; otherwise, false
@Nonnull Page<String> findGroups(@Nonnull PageRequest pageRequest)
Note: To filter the retrieved groups by name, use findGroupsByName(String, PageRequest)
instead.
pageRequest
- defines the page of groups to retrievenull
findGroupsByName(String, PageRequest)
@Nonnull Page<String> findGroupsByName(@Nullable String groupName, @Nonnull PageRequest pageRequest)
groupName
. If the provided groupName
is null
, this method behaves identically to
findGroups(PageRequest)
.groupName
- 0 or more characters to apply as a filter on returned groupspageRequest
- defines the page of groups to retrievenull
findGroups(PageRequest)
@Nonnull Page<String> findGroupsByPrefix(@Nullable String groupPrefix, @Nonnull PageRequest pageRequest)
groupPrefix
. If the provided groupPrefix
is null
, this method behaves identically to
findGroups(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".
groupPrefix
- 0 or more characters defining a prefix which returned group names must start withpageRequest
- defines the page of groups to retrievenull
findGroups(PageRequest)
@Nonnull Page<String> findGroupsByUser(@Nonnull String username, @Nonnull PageRequest pageRequest)
username
provided must match
exactly in order for any results to be returned.username
- the exact name of the user to retrieve groups forpageRequest
- defines the page of groups to retrievenull
findUsersByGroup(String, PageRequest)
@Nullable ApplicationUser findUserByEmail(@Nonnull String value)
value
- the value to match against e-mail addressesnull
if no matching user
was found@Nullable ApplicationUser findUserByNameOrEmail(@Nonnull String value)
active
normal
user whose username or
e-mail address exactly matches the provided value
.
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.
value
- the value to match, first against usernames and then against e-mail addressesnull
if no matching user
was found@Nonnull Page<ApplicationUser> findUsers(@Nonnull PageRequest pageRequest)
active
normal
users.
Note: To filter the retrieved users by name, use findUsersByName(String, PageRequest)
instead.
pageRequest
- defines the page of users to retrievenull
findUsersByName(String, PageRequest)
@Nonnull Page<ApplicationUser> findUsersByName(@Nullable String username, @Nonnull PageRequest pageRequest)
active
normal
users, optionally
filtering the returned results to those containing the specified username
. If the provided
username
is null
, this method behaves identically to findUsers(PageRequest)
.
Otherwise, the username
is matched against:
username
- 0 or more characters to apply as a filter on returned userspageRequest
- defines the page of users to retrievenull
findUsers(PageRequest)
@Nonnull Page<ApplicationUser> findUsersByGroup(@Nonnull String groupName, @Nonnull PageRequest pageRequest)
active
users which are members of the specified group.
The groupName
provided must match exactly in order for any results to be returned.groupName
- the exact name of the group to retrieve members forpageRequest
- defines the page of users to retrievenull
findGroupsByUser(String, PageRequest)
@Nonnull CacheableAvatarSupplier getAvatar(@Nonnull ApplicationUser user, int size)
The requested size will be normalised to fall within a well-defined set sizes. The supported sizes are:
user
- the user whose avatar should be retrievedsize
- the desired height and width for the avatar@Nullable ServiceUser getServiceUserByName(@Nonnull String username)
active
ServiceUser
by its username
.
This method will not return inactive users; use getServiceUserByName(String, boolean)
instead if
inactive users are desired.
username
- the username of the user to retrievenull
if no matching user exists or the matching
user has been deleted from the user store@Nullable ServiceUser getServiceUserByName(@Nonnull String username, boolean inactive)
ServiceUser
by its username
, optionally returning the user even
if it has been marked inactive.
If requested, this method will return inactive users.
username
- the username of the user to retrieveinactive
- true
if inactive users should be returned, false
otherwise.null
if no matching user exists or the matching
user is inactive and inactive users were not requested@Nullable ServiceUser getServiceUserBySlug(@Nonnull String slug)
active
ServiceUser
by its exact (case-sensitive)
slug
.
This method will not return inactive users.
slug
- the slug of the user to retrievenull
if no matching user exists or the matching
user is inactive@Nonnull Set<ServiceUser> getServiceUsersByName(@Nonnull Set<String> usernames)
active
ServiceUser
s by
their usernames
.
This method will not return inactive users; use getServiceUsersByName(Set, boolean)
instead if
inactive users are desired.
usernames
- the usernames of the users to retrieve@Nonnull Set<ServiceUser> getServiceUsersByName(@Nonnull Set<String> usernames, boolean inactive)
ServiceUser
s by their usernames
, 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.
usernames
- the usernames of the users to retrieveinactive
- true
if deleted and inactive users should be returned, false
otherwise@Nullable ApplicationUser getUserById(int id)
ApplicationUser
by its ID
.
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.
id
- the ID of the user to retrievenull
if no matching user exists@Nullable ApplicationUser getUserById(int id, boolean inactive)
ApplicationUser
by its ID
.
If requested, this method will return deleted or inactive users. See the class documentation for more details about what "deleted" means in this context.
id
- the ID of the user to retrieveinactive
- true
if deleted and inactive users should be returned, false
otherwise.null
if no matching user exists@Nullable ApplicationUser getUserByName(@Nonnull String username)
active
ApplicationUser
by its username
.
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.
username
- the username of the user to retrievenull
if no matching user exists or the matching
user has been deleted from the user store@Nullable ApplicationUser getUserByName(@Nonnull String username, boolean inactive)
ApplicationUser
by its username
, 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.
username
- the username of the user to retrieveinactive
- true
if deleted and inactive users should be returned, false
otherwise.null
if no matching user exists or the matching
user has been deleted from the user store and deleted users were not requested@Nonnull Set<ApplicationUser> getUsersById(@Nonnull Set<Integer> ids)
active
ApplicationUser
s by their IDs
.
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.
ids
- the IDs of the users to retrieve@Nonnull Set<ApplicationUser> getUsersById(@Nonnull Set<Integer> ids, boolean inactive)
ApplicationUser
s by their IDs
, 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.
ids
- the IDs of the users to retrieveinactive
- true
if deleted and inactive users should be returned, false
otherwise@Nullable ApplicationUser getUserBySlug(@Nonnull String slug)
active
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.
slug
- the slug of the user to retrievenull
if no matching user exists or the matching
user has been deleted or is inactive@Nonnull Set<ApplicationUser> getUsersByName(@Nonnull Set<String> usernames)
active
ApplicationUser
s by
their usernames
.
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.
usernames
- the usernames of the users to retrieve@Nonnull Set<ApplicationUser> getUsersByName(@Nonnull Set<String> usernames, boolean inactive)
ApplicationUser
s by their usernames
, 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.
usernames
- the usernames of the users to retrieveinactive
- true
if deleted and inactive users should be returned, false
otherwiseboolean isUserActive(@Nonnull ApplicationUser user)
user
- the user to query activity state forboolean isUserActive(@Nonnull ApplicationUser user, boolean checkDirectory)
checkDirectory
is true.user
- the user to query activity state forcheckDirectory
- whether to check the users authoriative directory to confirm their active stateboolean isUserInGroup(@Nonnull ApplicationUser user, @Nonnull String groupName)
false
is returned in preference to
throwing an exception.user
- the user to query group membership forgroupName
- the exact name of the group to query membership intrue
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
groupboolean isUserInGroup(@Nonnull String username, @Nonnull String groupName)
false
is returned in preference to throwing an exception.username
- the exact name of the user to query group membership forgroupName
- the exact name of the group to query membership intrue
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@Nonnull Page<ApplicationUser> search(@Nonnull UserSearchRequest request, @Nonnull PageRequest pageRequest)
request
- a request object describing the users to returnpageRequest
- the bounds of the pageusers
that match the provided
criteria
UserSearchRequest
void updateAvatar(@Nonnull ApplicationUser user, @Nonnull AvatarSupplier supplier)
supplier
. Updating a user's avatar also updates the avatar for their
personal 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.
user
- the user to update the avatar forsupplier
- a supplier providing access to the new avatar to usevoid updateAvatar(@Nonnull ApplicationUser user, @Nonnull String uri)
personal
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.
user
- the user to update the avatar foruri
- a data URI containing a Base64-encoded avatar imagevoid updatePassword(@Nonnull String currentPassword, @Nonnull String newPassword) throws IncorrectPasswordAuthenticationException, ServerException
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.
currentPassword
- the current user's current passwordnewPassword
- the current user's desired new passwordIncorrectPasswordAuthenticationException
- if the current password provided does not match the user's
current passwordServerException
- if the underlying user store does not support updating users' passwords@Nonnull ApplicationUser updateUser(@Nonnull String displayName, @Nonnull String emailAddress) throws ServerException
display name
and e-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.
displayName
- the new display name for the current useremailAddress
- the new e-mail address for the current userServerException
- if the underlying user store does not support updating users' detailsCopyright © 2022 Atlassian. All rights reserved.