Interface UserAdminService
Many of the queries provided by this service are also provided by UserService. The queries provided here
are specifically geared toward administration, retrieving detailed groups and
detailed groups. For non-administrative usages, like group and user pickers, the "normal"
queries from UserService should be used instead.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddMembersToGroup(String groupName, Set<String> usernames) Adds one or more users to a group.voidaddUserToGroups(String username, Set<String> groupNames) Adds a user to one or more groups.booleanRetrieves a flag indicating whether it is possible to create a group.booleanRetrieves a flag indicating whether it is possible to create a user.booleanRetrieves a flag indicating whether it is possible to delete a group.booleanRetrieves a flag indicating whether it is possible to update groups.voidclearCaptchaChallenge(String username) Clears any CAPTCHA challenge that may constrain the user with the supplied username when they authenticate.createGroup(String groupName) Creates a new group.createServiceUser(ServiceUserCreateRequest userRequest) Creates a newserviceuser.voidcreateUser(String username, String password, String displayName, String emailAddress) Creates a new user and adds them to the default group, if it exists.voidcreateUser(String username, String password, String displayName, String emailAddress, boolean addToDefaultGroup) Creates a new user and optionally adds them to the default group, if it exists.voidcreateUserWithGeneratedPassword(String username, String displayName, String emailAddress) Creates a new user with a randomly-generated password.deleteGroup(String groupName) Deletes a group.deleteUser(String username) Deletes a user.Erases personally identifying user data for a deleted user.findGroups(PageRequest pageRequest) Retrieves a page of groups with fulldetails.findGroupsByName(String groupName, PageRequest pageRequest) Retrieves a page of groups with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName.findGroupsWithoutUser(String username, String groupName, PageRequest pageRequest) Retrieves a page of groups which the specified user is not a member of, with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName.findGroupsWithUser(String username, String groupName, PageRequest pageRequest) Retrieves a page of groups which the specified user is a member of, with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName.Find a password reset request using the token generated byrequestPasswordReset(String).findUsers(PageRequest pageRequest) Retrieves a page of users with fulldetails.findUsersByName(String username, PageRequest pageRequest) Retrieves a page of users, optionally filtering the returned results to those containing the specifiedusername.findUsersWithGroup(String groupName, String username, PageRequest pageRequest) Find the users within a group that match the page request.findUsersWithoutGroup(String groupName, String username, PageRequest pageRequest) Find the users outside a group that match the page request.getUserDetails(String username) booleanRetrieves a flag indicating whether the new user is able to set a password or notvoidremoveUserFromGroup(String groupName, String username) Removes a user from a group.renameUser(String currentUsername, String newUsername) Change the name of a uservoidrequestPasswordReset(String username) Generates a unique token which can be used to perform apassword resetfor the specified user and e-mails it to the address associated with their account.voidresetPassword(String token, String password) Resets the password for theuserassociated with the specified token to the provided value.voidupdatePassword(String username, String newPassword) Updates the password of the specified user.Updates the details of the specifieduserupdateUser(String username, String displayName, String emailAddress) Updates thedisplay nameande-mail addressof the specified user.voidvalidateErasable(String username) Validate if a username can be erased.
-
Method Details
-
addUserToGroups
void addUserToGroups(@Nonnull String username, @Nonnull Set<String> groupNames) throws ForbiddenException, LicenseLimitException, NoSuchGroupException, NoSuchUserException Adds a user to one or more groups.- Parameters:
username- name of the user who will receive the new group membershipsgroupNames- names of the groups to add to the user- Throws:
ForbiddenException- if one of the groups would grantSYS_ADMINpermission and the current user isn't a SYS_ADMIN; only SYS_ADMINs can grant SYS_ADMIN permissionLicenseLimitException- if one of the groups would grantLICENSED_USERpermission to more users than the active license allowsNoSuchGroupException- if any of the specified groups does not existNoSuchUserException- if the specified user does not exist
-
addMembersToGroup
void addMembersToGroup(@Nonnull String groupName, @Nonnull Set<String> usernames) throws ForbiddenException, LicenseLimitException, NoSuchGroupException, NoSuchUserException Adds one or more users to a group.- Parameters:
groupName- names of the group to which the users will be addedusernames- names of the users who will receive the new group membership- Throws:
ForbiddenException- if the group would grantSYS_ADMINpermission and the current user isn't a SYS_ADMIN; only SYS_ADMINs can grant SYS_ADMIN permissionLicenseLimitException- if the additions would grantLICENSED_USERpermission to more users than the active license allowsNoSuchGroupException- if the specified group does not existNoSuchUserException- if any of the specified users does not exist
-
canCreateGroups
boolean canCreateGroups()Retrieves a flag indicating whether it is possible to create a group.- Returns:
trueif any directory exists in which a group can be created; otherwise,false
-
canUpdateGroups
boolean canUpdateGroups()Retrieves a flag indicating whether it is possible to update groups.- Returns:
trueif any directory exists in which a group can be updated; otherwise,false
-
canCreateUsers
boolean canCreateUsers()Retrieves a flag indicating whether it is possible to create a user.- Returns:
trueif any directory exists in which a user can be created; otherwise,false
-
canDeleteGroups
boolean canDeleteGroups()Retrieves a flag indicating whether it is possible to delete a group.- Returns:
trueif any directory exists in which a group can be deleted; otherwisefalse
-
newUserCanResetPassword
boolean newUserCanResetPassword()Retrieves a flag indicating whether the new user is able to set a password or not- Returns:
trueif user is able to set a password; otherwisefalse
-
clearCaptchaChallenge
Clears any CAPTCHA challenge that may constrain the user with the supplied username when they authenticate. Additionally any counter or metric that contributed towards the user being issued the CAPTCHA challenge (for instance too many consecutive failed logins) will also be reset.- Parameters:
username- the user whose CAPTCHA challenge should be cleared
-
createGroup
Creates a new group.- Parameters:
groupName- the name for the new group- Returns:
- the new group
- Throws:
IntegrityException- if a group with the same already exists
-
createServiceUser
@Nonnull ServiceUser createServiceUser(@Nonnull ServiceUserCreateRequest userRequest) throws IntegrityException Creates a newserviceuser. Service users cannot be added to any groups. The user is created without any permissions.It is suggested that consumers use the
IDof the user created as the foreign key for related content because their name, slug and other properties can be updated.- Parameters:
userRequest- the user's details- Returns:
- the newly created service user
- Throws:
IntegrityException- if a service user with the provided username already exists
-
createUser
void createUser(@Nonnull String username, @Nonnull String password, @Nonnull String displayName, @Nonnull String emailAddress) throws IntegrityException, LicenseLimitException Creates a new user and adds them to the default group, if it exists. If the user should be created without being added to the default group, usecreateUser(String, String, String, String, boolean)instead.A non-
null, non-blankpasswordmust be provided. It may be further vetted by the user store, for example by applying complexity restrictions. Alternatively, if an e-mail server has been configured, new users can be createdwith generated passwords, allowing new users to set their own password when they first access the system.- Parameters:
username- theusernamefor the new userpassword- the user's initial password, which may not benullor emptydisplayName- thedisplay namefor the new useremailAddress- thee-mail addressfor the new user- Throws:
IntegrityException- if a user with the same username already existsLicenseLimitException- if the new user can not be added to the default group because it would grantLICENSED_USERpermission to more users than the active license allows- See Also:
-
createUser
void createUser(@Nonnull String username, @Nonnull String password, @Nonnull String displayName, @Nonnull String emailAddress, boolean addToDefaultGroup) throws IntegrityException, LicenseLimitException Creates a new user and optionally adds them to the default group, if it exists.A non-
null, non-blankpasswordmust be provided. It may be further vetted by the user store, for example by applying complexity restrictions. Alternatively, if an e-mail server has been configured, new users can be createdwith generated passwords, allowing new users to set their own password when they first access the system.This method is not intended to be exposed via services like REST for general consumption. It exists to satisfy specific use cases where the system, or a plugin, may wish to create a user without adding them to the default group. Generally it is expected that new users should be added to the default group, as it defines the set of "common" permissions for all users of the system.
- Parameters:
username- theusernamefor the new userpassword- the user's initial password, which may not benullor emptydisplayName- thedisplay namefor the new useremailAddress- thee-mail addressfor the new useraddToDefaultGroup- true if the new user should be added to the default group- Throws:
IntegrityException- if a user with the same username already existsLicenseLimitException- if the new user can not be added to the default group because it would grantLICENSED_USERpermission to more users than the active license allows- See Also:
-
createUserWithGeneratedPassword
void createUserWithGeneratedPassword(@Nonnull String username, @Nonnull String displayName, @Nonnull String emailAddress) throws IntegrityException, LicenseLimitException, MailException Creates a new user with a randomly-generated password. An e-mail notification will be sent to the new user's e-mail address with instructions on how to reset their password and finish activating their account.- Parameters:
username- theusernamefor the new userdisplayName- thedisplay namefor the new useremailAddress- thee-mail addressfor the new user- Throws:
IntegrityException- if a user with the same username already exists or if the user will be created in a directory that does not allow passwords to be resetLicenseLimitException- if the new user can not be added to the default group because it would grantLICENSED_USERpermission to more users than the active license allowsMailException- if the e-mail notification could not be sent to the created user to allow them to set their initial passwordNoMailHostConfigurationException- if no e-mail server has been configured
-
deleteGroup
@Nonnull DetailedGroup deleteGroup(@Nonnull String groupName) throws ForbiddenException, IntegrityException, NoSuchGroupException Deletes a group. Deleting a group will also revoke all permissions which had been granted to that group.Note: Future releases may remove the return value from this method. For best portability across versions, the return value for this method should not be used.
- Parameters:
groupName- the name of the group to delete- Returns:
- details for the deleted group
- Throws:
ForbiddenException- if the group grantsSYS_ADMINpermission but the current user is not a SYS_ADMINIntegrityException- if deleting the group would revoke theADMINorSYS_ADMINpermissions of the current userNoSuchGroupException- if the group does not exist
-
deleteUser
@Nonnull DetailedUser deleteUser(@Nonnull String username) throws ForbiddenException, IntegrityException, NoSuchUserException Deletes a user. Deleting a user will also revoke all permissions which had been granted to that user, as well as invalidating any cached authentication tokens they may have.Note: Future releases may remove the return value from this method. For best portability across versions, the return value for this method should not be used.
- Parameters:
username- theusernameof the user to delete- Returns:
- details for the deleted user
- Throws:
ForbiddenException- if the user to delete is aSYS_ADMINand the current user is notIntegrityException- if the user to delete is the current userNoSuchUserException- if the user does not exist
-
eraseUser
@Nonnull String eraseUser(@Nonnull String username) throws IllegalUserStateException, NoSuchUserException, UserErasureException Erases personally identifying user data for a deleted user. References in the application to the original username will be either removed or updated to a new non-identifying username.A
UserErasedEventis then raised once erasure has completed.Erasing user data is irreversible and may lead to a degraded user experience. This method should not be used as part of a standard user deletion and cleanup process.
- Parameters:
username- theusernameof the user to erase data for- Returns:
- the new identifier for the erased user
- Throws:
IllegalUserStateException- if the suppliedusernameis the username of a non-deleted userNoSuchUserException- if the suppliedusernamedoes not existUserErasureException- if some of the delegated user erasure operations failed- Since:
- 5.16
- See Also:
-
findGroups
Retrieves a page of groups with fulldetails.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<DetailedGroup> findGroupsByName(@Nullable String groupName, @Nonnull PageRequest pageRequest) Retrieves a page of groups with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName. If the providedgroupNameisnull, 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:
-
findGroupsWithUser
@Nonnull Page<DetailedGroup> findGroupsWithUser(@Nonnull String username, @Nullable String groupName, @Nonnull PageRequest pageRequest) Retrieves a page of groups which the specified user is a member of, with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName. If the providedgroupNameisnullor empty groups will not be filtered. If no user exists with the specifiedusername, no groups will be returned.- Parameters:
username- the exact name of the user to retrieve groups forgroupName- 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, which may be empty but never
null - See Also:
-
findGroupsWithoutUser
@Nonnull Page<DetailedGroup> findGroupsWithoutUser(@Nonnull String username, @Nullable String groupName, @Nonnull PageRequest pageRequest) Retrieves a page of groups which the specified user is not a member of, with fulldetails, optionally filtering the returned results to those containing the specifiedgroupName. If the providedgroupNameisnullor empty groups will not be filtered. If no user exists with the specifiedusername, no groups will be returned.- Parameters:
username- the exact name of the user to retrieve groups forgroupName- 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, which may be empty but never
null - See Also:
-
findUserByPasswordResetToken
Find a password reset request using the token generated byrequestPasswordReset(String).- Parameters:
token- token identifying the password reset request- Returns:
- the user matching the password reset request or
nullif no request matches the token or if the request has expired - See Also:
-
findUsers
Retrieves a page of users with fulldetails.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<DetailedUser> findUsersByName(@Nullable String username, @Nonnull PageRequest pageRequest) Retrieves a page of users, optionally filtering the returned results to those containing the specifiedusername. If the providedusernameisnull, this method behaves identically tofindUsers(PageRequest). Otherwise, theusernameis 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:
-
findUsersWithGroup
@Nonnull Page<DetailedUser> findUsersWithGroup(@Nonnull String groupName, @Nullable String username, @Nonnull PageRequest pageRequest) Find the users within a group that match the page request.- Parameters:
groupName- name of the group the users must belong tousername- 0 or more characters to apply as a filter on returned userspageRequest- page request- Returns:
- page of users matching search criteria
-
findUsersWithoutGroup
@Nonnull Page<DetailedUser> findUsersWithoutGroup(@Nonnull String groupName, @Nullable String username, @Nonnull PageRequest pageRequest) Find the users outside a group that match the page request.- Parameters:
groupName- name of the group the users must not belong tousername- 0 or more characters to apply as a filter on returned userspageRequest- page request- Returns:
- a page of
ApplicationUser
-
getUserDetails
- Parameters:
username- the exact username of the user to retrieve- Returns:
- full
detailsfor the specified user, ornullif no user
-
getUserDetails
Retrieves fulldetailsfor the specifieduser. This method is intended to "promote" from aApplicationUserto aDetailedUser, providing access to mutability details and other information for the user.- Parameters:
user- the user to retrieve details for- Returns:
- full
detailsfor the specified user - Throws:
NoSuchUserException- if the specifieduserdoes not exist in the underlying user store
-
removeUserFromGroup
void removeUserFromGroup(@Nonnull String groupName, @Nonnull String username) throws ForbiddenException, IntegrityException, NoSuchGroupException, NoSuchUserException Removes a user from a group.- Parameters:
groupName- name of the group the user will be removed fromusername- name of the user to remove from the group- Throws:
ForbiddenException- if the group grantsSYS_ADMINpermission but the current user is not a SYS_ADMINIntegrityException- if the current user belongs to the specified group and removing them from the group would revoke theirSYS_ADMINorADMINpermissionNoSuchGroupException- if the specified group does not existNoSuchUserException- if the specified user does not exist
-
renameUser
Change the name of a user- Parameters:
currentUsername- the current name of the usernewUsername- the new name of the user- Returns:
- the newly renamed user
- Throws:
NoSuchUserException- if the specified user does not existIntegrityException- if a user already exists in the directory with the new nameForbiddenException- if renaming is not supported by the directory the target user belongs to
-
requestPasswordReset
Generates a unique token which can be used to perform apassword resetfor the specified user and e-mails it to the address associated with their account.- Parameters:
username- username of the user- Throws:
MailException- if the e-mail notification could not be sent to the user (ex: the mail server is down)NoMailHostConfigurationException- if no e-mail server has been configuredNoSuchUserException- if the user does not exist
-
resetPassword
void resetPassword(@Nonnull String token, @Nonnull String password) throws InvalidPasswordResetTokenException, NoSuchEntityException Resets the password for theuserassociated with the specified token to the provided value.- Parameters:
token- the token identifying the user whose password should be resetpassword- the new password for the user- Throws:
InvalidPasswordResetTokenException- if no user matches the specified tokenNoSuchEntityException
-
updatePassword
Updates the password of the specified user.- Parameters:
username- the user's usernamenewPassword- the user's new password
-
updateServiceUser
Updates the details of the specifieduser- Parameters:
request- the user's new details- Returns:
- the updated user
-
updateUser
@Nonnull DetailedUser updateUser(@Nonnull String username, @Nonnull String displayName, @Nonnull String emailAddress) Updates thedisplay nameande-mail addressof the specified user.- Parameters:
username- the user's usernamedisplayName- the user's new display nameemailAddress- the user's new email address- Returns:
- the updated user
-
validateErasable
void validateErasable(@Nonnull String username) throws IllegalUserStateException, NoSuchUserException Validate if a username can be erased.A username is only valid for erasure if it exists as the username of a deleted user. This method will throw an appropriate exception if the user for the supplied username is invalid for erasure.
- Parameters:
username- theusernameof the user to validate erasability for- Throws:
IllegalUserStateException- if the suppliedusernameis the username of a non-deleted userNoSuchUserException- if the suppliedusernamedoes not exist- Since:
- 5.16
-