Class MockUserService
- All Implemented Interfaces:
UserService
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.atlassian.jira.bc.user.UserService
UserService.AddUserToApplicationValidationResult, UserService.CreateUsernameValidationResult, UserService.CreateUserRequest, UserService.CreateUserValidationResult, UserService.DeleteUserValidationResult, UserService.FieldName, UserService.RemoveUserFromApplicationValidationResult, UserService.UpdateUserValidationResult
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Given a valid validation result, this will associate a user with an application by adding that user to all the default groups assigned to that application (regardless of the license).Create a new application user if the providedServiceResultImpl.isValid()
.Given a valid validation result, this will create the user using the details provided in the validation result.Given a valid validation result, this will create the user using the details provided in the validation result.Given a valid validation result, this will create the user using the details provided in the validation result.Allows you to constructApplicationUser
forUserService.validateUpdateUser(ApplicationUser)
void
removeUser
(ApplicationUser loggedInUser, UserService.DeleteUserValidationResult result) Given a valid validation result, this will remove the user and removes the user from all the groups.void
Given a valid validation result, this will disassociate a user from an application by removing that user from all the groups assigned to that application.void
updateUser
(UserService.UpdateUserValidationResult updateUserValidationResult) Execute the update using the validation result fromUserService.validateUpdateUser(ApplicationUser)
.validateAddUserToApplication
(ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Validates associating a user with an application.validateAddUserToApplication
(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Validates associating a user with an application.Validate that a new user can be created.validateCreateUserForAdmin
(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Validates creating a user for the admin section.validateCreateUserForAdmin
(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname, Long directoryId) Validates creating a user for the admin section.validateCreateUserForSetup
(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Validates creating a user during setup of JIRA.validateCreateUserForSignup
(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Validates creating a user during public signup.validateCreateUserForSignupOrSetup
(ApplicationUser user, String username, String password, String confirmPassword, String email, String fullname) Validates creating a user during setup of JIRA or during public signup.validateCreateUsername
(ApplicationUser loggedInUser, String username) Validates the username for a new user.validateCreateUsername
(ApplicationUser loggedInUser, String username, Long directoryId) Validates the username for a new user.validateDeleteUser
(ApplicationUser loggedInUser, ApplicationUser userForDelete) Validates removing a user for the admin section.validateDeleteUser
(ApplicationUser loggedInUser, String username) Validates removing a user for the admin section.validateRemoveUserFromApplication
(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Validates disassociating a user from an application.Validates updating a user's details.
-
Constructor Details
-
MockUserService
public MockUserService() -
MockUserService
-
-
Method Details
-
validateCreateUser
public UserService.CreateUserValidationResult validateCreateUser(UserService.CreateUserRequest request) Description copied from interface:UserService
Validate that a new user can be created. The validation instructions are specified in theUserService.CreateUserRequest
.Typical validations are:
- Validate that specified (or default) application(s) has a seat available for the new user and that the default group(s) has been configured.
- Validate that the specified logged in user is allowed to create a new user.
- Validate that the specified or default user directory exists and is writable.
- Validate that password conforms to password policy.
- Validate that confirm password matches password (optional).
- Validate that the new username is not currently in use.
UserService.createUser(CreateUserValidationResult)
should only be called when the validationResult.isValid().Usage example:
final CreateUserRequest createUserRequest = CreateUserRequest.withUserDetails(currentApplicationUser, username, password, email, displayName) result = userService.validateCreateUser(createUserRequest); if(result.isValid()) { userService.createUser(createUserRequest); }
- Specified by:
validateCreateUser
in interfaceUserService
- Parameters:
request
- user creation request containing new user details and validation instructions.- Returns:
- the result that would contain error messages when validation was not successful.
-
createUser
public ApplicationUser createUser(UserService.CreateUserValidationResult result) throws PermissionException, CreateException Description copied from interface:UserService
Create a new application user if the providedServiceResultImpl.isValid()
. This is typically called after performingUserService.validateCreateUser(CreateUserRequest)
and verifying that theServiceResultImpl.isValid()
. If the request is not valid orUserService.validateCreateUser(CreateUserRequest)
was not called prior to this method anIllegalStateException
would get thrown.- Specified by:
createUser
in interfaceUserService
- Parameters:
result
- create user validation result returned fromUserService.validateCreateUser(CreateUserRequest)
, this contains the user details and instructions used to create new user.- Returns:
- an application user representing the newly created user.
- Throws:
PermissionException
- when the logged in user does not have permissions to perform user creation or when the user directory is read-only.CreateException
- if the user could not be created for any reason, eg username already exists- See Also:
-
newUserBuilder
Description copied from interface:UserService
Allows you to constructApplicationUser
forUserService.validateUpdateUser(ApplicationUser)
- Specified by:
newUserBuilder
in interfaceUserService
-
validateCreateUserForSignup
public UserService.CreateUserValidationResult validateCreateUserForSignup(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Description copied from interface:UserService
Validates creating a user during public signup. This method checks that there is a writable User Directory available. It also validates that all parameters (username, email, fullname, password) have been provided. Email is also checked to ensure that it is a valid email address. The username is required to be lowercase characters only and unique. The confirmPassword has to match the password provided.This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
- Does not require global admin rights
- The password is required
- Specified by:
validateCreateUserForSignup
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.password
- The password for the new user.confirmPassword
- The password confirmation. Needs to match password.email
- The email for the new user. Needs to be a valid email address.fullname
- The full name for the new user- Returns:
- a validation result containing appropriate errors or the new user's details
-
validateCreateUserForSetup
public UserService.CreateUserValidationResult validateCreateUserForSetup(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Description copied from interface:UserService
Validates creating a user during setup of JIRA. This method does not check for a writable User Directory because the embedded crowd subsystem will not be initialised, and we know we will just have an Internal Directory during Setup. It also validates that all parameters (username, email, fullname, password) have been provided. Email is also checked to ensure that it is a valid email address. The username is required to be lowercase characters only and unique. The confirmPassword has to match the password provided.This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
- Does not require global admin rights
- The password is required
- Specified by:
validateCreateUserForSetup
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.password
- The password for the new user.confirmPassword
- The password confirmation. Needs to match password.email
- The email for the new user. Needs to be a valid email address.fullname
- The full name for the new user- Returns:
- a validation result containing appropriate errors or the new user's details
-
validateCreateUserForSignupOrSetup
public UserService.CreateUserValidationResult validateCreateUserForSignupOrSetup(ApplicationUser user, String username, String password, String confirmPassword, String email, String fullname) Description copied from interface:UserService
Validates creating a user during setup of JIRA or during public signup. This method checks that there is a writable User Directory available. It also validates that all parameters (username, email, fullname, password) have been provided. Email is also checked to ensure that it is a valid email address. The username is required to be lowercase characters only and unique. The confirmPassword has to match the password provided.This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
- Does not require global admin rights
- The password is required
- Specified by:
validateCreateUserForSignupOrSetup
in interfaceUserService
- Parameters:
user
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.password
- The password for the new user.confirmPassword
- The password confirmation. Needs to match password.email
- The email for the new user. Needs to be a valid email address.fullname
- The full name for the new user- Returns:
- a validation result containing appropriate errors or the new user's details
-
validateCreateUserForAdmin
public UserService.CreateUserValidationResult validateCreateUserForAdmin(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname) Description copied from interface:UserService
Validates creating a user for the admin section. This method checks that external user management is disabled and that the user performing the operation has global admin rights. It also validates that all parameters (username, email, fullname) except for the password have been provided. Email is also checked to ensure that it is a valid email address. The username is required to be lowercase characters only and unique. The confirmPassword has to match the password provided.This validation differs from the 'ForSetup' and 'ForAdminPasswordRequired' validations as follows:
- Does require global admin rights
- The password is NOT required
- Specified by:
validateCreateUserForAdmin
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.password
- The password for the new user.confirmPassword
- The password confirmation. Needs to match password.email
- The email for the new user. Needs to be a valid email address.fullname
- The full name for the new user- Returns:
- a validation result containing appropriate errors or the new user's details
-
validateCreateUserForAdmin
public UserService.CreateUserValidationResult validateCreateUserForAdmin(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname, @Nullable Long directoryId) Description copied from interface:UserService
Validates creating a user for the admin section. This method checks that external user management is disabled and that the user performing the operation has global admin rights. It also validates that all parameters (username, email, fullname) except for the password have been provided. Email is also checked to ensure that it is a valid email address. The username is required to be lowercase characters only and unique. The confirmPassword has to match the password provided.This method allows the caller to name a directory to create the user in and the directoryId must be valid and represent a Directory with "create user" permission.
This validation differs from the 'ForSetup' and 'ForAdminPasswordRequired' validations as follows:
- Does require global admin rights
- The password is NOT required
- Specified by:
validateCreateUserForAdmin
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.password
- The password for the new user.confirmPassword
- The password confirmation. Needs to match password.email
- The email for the new user. Needs to be a valid email address.fullname
- The full name for the new userdirectoryId
- The User Directory- Returns:
- a validation result containing appropriate errors or the new user's details
-
validateCreateUsername
public UserService.CreateUsernameValidationResult validateCreateUsername(ApplicationUser loggedInUser, String username) Description copied from interface:UserService
Validates the username for a new user. The username is required to be lowercase characters only and unique across all directories.- Specified by:
validateCreateUsername
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.- Returns:
- a validation result containing appropriate errors
-
validateCreateUsername
public UserService.CreateUsernameValidationResult validateCreateUsername(ApplicationUser loggedInUser, String username, Long directoryId) Description copied from interface:UserService
Validates the username for a new user. The username is required to be lowercase characters only and unique in the given directory.- Specified by:
validateCreateUsername
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.directoryId
- The directory which the new user is intended to be created in.- Returns:
- a validation result containing appropriate errors
-
createUserFromSignup
public ApplicationUser createUserFromSignup(UserService.CreateUserValidationResult result) throws PermissionException, CreateException Description copied from interface:UserService
Given a valid validation result, this will create the user using the details provided in the validation result. Email notification will be send to created user - via UserEventType.USER_SIGNUP event.- Specified by:
createUserFromSignup
in interfaceUserService
- Parameters:
result
- The validation result- Returns:
- The new user object that was created
- Throws:
PermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already exists
-
createUserWithNotification
public ApplicationUser createUserWithNotification(UserService.CreateUserValidationResult result) throws PermissionException, CreateException Description copied from interface:UserService
Given a valid validation result, this will create the user using the details provided in the validation result. Email notification will be send to created user - via UserEventType.USER_CREATED event.- Specified by:
createUserWithNotification
in interfaceUserService
- Parameters:
result
- The validation result- Returns:
- The new user object that was created
- Throws:
PermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already exists
-
createUserNoNotification
public ApplicationUser createUserNoNotification(UserService.CreateUserValidationResult result) throws PermissionException, CreateException Description copied from interface:UserService
Given a valid validation result, this will create the user using the details provided in the validation result. No email notification will be send to created user.- Specified by:
createUserNoNotification
in interfaceUserService
- Parameters:
result
- The validation result- Returns:
- The new user object that was created
- Throws:
PermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already exists
-
validateUpdateUser
Description copied from interface:UserService
Validates updating a user's details.- Specified by:
validateUpdateUser
in interfaceUserService
- Parameters:
user
- The user details to update- Returns:
- A validation result containing any errors and all user details
-
updateUser
Description copied from interface:UserService
Execute the update using the validation result fromUserService.validateUpdateUser(ApplicationUser)
.- Specified by:
updateUser
in interfaceUserService
- Parameters:
updateUserValidationResult
- Result from the validation, which also contains all the user's details.
-
validateDeleteUser
public UserService.DeleteUserValidationResult validateDeleteUser(ApplicationUser loggedInUser, String username) Description copied from interface:UserService
Validates removing a user for the admin section. This method checks that external user management is disabled and that the user performing the operation has global admin rights. It also validates that username have been provided.See
UserService.validateDeleteUser(ApplicationUser, ApplicationUser)
for restrictions.- Specified by:
validateDeleteUser
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to remove a userusername
- The username of the user to remove. Needs to be valid- Returns:
- a validation result containing appropriate errors or the user object for delete
-
validateDeleteUser
public UserService.DeleteUserValidationResult validateDeleteUser(ApplicationUser loggedInUser, ApplicationUser userForDelete) Description copied from interface:UserService
Validates removing a user for the admin section. This method checks that external user management is disabled and that the user performing the operation has global admin rights. It also validates that username have been provided.Removing the user is not allowed if:
- Logged in user lacks global admin permissions
- Logged in user and target user are the same user
- Logged in user is not a system administrator but the target user is
- Target user is the assignee for any issue
- Target user is the reporter for any issue
- Target user is the project lead for any project
- A plugin that implements
PreDeleteUserErrors
rejects the request
- Specified by:
validateDeleteUser
in interfaceUserService
- Parameters:
loggedInUser
- The remote user trying to remove a useruserForDelete
- The user to remove. Needs to be valid- Returns:
- a validation result containing appropriate errors or the user object for delete
-
removeUser
Description copied from interface:UserService
Given a valid validation result, this will remove the user and removes the user from all the groups. All components lead by user will have lead cleared.- Specified by:
removeUser
in interfaceUserService
- Parameters:
loggedInUser
- the user performing operationresult
- The validation result
-
validateAddUserToApplication
public UserService.AddUserToApplicationValidationResult validateAddUserToApplication(ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Description copied from interface:UserService
Validates associating a user with an application. This method checks there is an application specified by the application key. It also checks if there are any default groups assigned to that application. It validates if there are any spaces in the application license as well. This also validates if the directory where the user lives is not fully read-only.- Specified by:
validateAddUserToApplication
in interfaceUserService
- Parameters:
user
- the user to be associated with the applicationapplicationKey
- the key of the application- Returns:
- a validation result containing appropriate errors or the details used to associate a user with an application
-
validateAddUserToApplication
public UserService.AddUserToApplicationValidationResult validateAddUserToApplication(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Description copied from interface:UserService
Validates associating a user with an application. This method checks if the logged in user has the permission to add user to application. It then checks if there is an application specified by the application key. It also checks if there are any default groups assigned to that application. It validates if there are any spaces in the application license as well. This also validates if the directory where the user lives is not fully read-only.- Specified by:
validateAddUserToApplication
in interfaceUserService
- Parameters:
loggedInUser
- The logged in useruser
- the user to be associated with the applicationapplicationKey
- the key of the application- Returns:
- a validation result containing appropriate errors or the details used to associate a user with an application
-
addUserToApplication
public void addUserToApplication(UserService.AddUserToApplicationValidationResult result) throws AddException, PermissionException Description copied from interface:UserService
Given a valid validation result, this will associate a user with an application by adding that user to all the default groups assigned to that application (regardless of the license).If the user is already associated with the application but is not the member of all the default groups, that user will be added to the default groups which that user does not belong to yet.
If any of the default groups assigned to this application are also assigned to other application(s), the user will also be associated with those applications as well.
This method is not the exact opposite to
UserService.removeUserFromApplication(com.atlassian.jira.bc.user.UserService.RemoveUserFromApplicationValidationResult)
. While this method only adds user to the default groups assigned to an application, removeUserFromApplication method removes user from all the group assigned to an application.- Specified by:
addUserToApplication
in interfaceUserService
- Parameters:
result
- the validation result- Throws:
AddException
- the underlying directory implementation failed to add user to groupPermissionException
- the underlying directory has been configured to not allow user to be added to group, or the directory/group is read-only
-
validateRemoveUserFromApplication
public UserService.RemoveUserFromApplicationValidationResult validateRemoveUserFromApplication(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey) Description copied from interface:UserService
Validates disassociating a user from an application. This method checks there is an application specified by the application key.- Specified by:
validateRemoveUserFromApplication
in interfaceUserService
- Parameters:
loggedInUser
- application user performing the application access removaluser
- the user to be disassociated with the applicationapplicationKey
- the key of the application- Returns:
- a validation result containing appropriate errors or the details used to disassociate a user from an application
-
removeUserFromApplication
public void removeUserFromApplication(UserService.RemoveUserFromApplicationValidationResult result) throws RemoveException, PermissionException Description copied from interface:UserService
Given a valid validation result, this will disassociate a user from an application by removing that user from all the groups assigned to that application. This also validates if the directory where the user lives is not fully read-only.If the group set assigned to this application is a superset of the group set assigned to other application(s), the user will also be disassociated with those applications as well.
This method is not the exact opposite to
UserService.addUserToApplication(com.atlassian.jira.bc.user.UserService.AddUserToApplicationValidationResult)
. While this method removes user from all the group assigned to an application, addUserToApplication method only adds user to the default groups assigned to an application- Specified by:
removeUserFromApplication
in interfaceUserService
- Parameters:
result
- The validation result- Throws:
RemoveException
- the underlying directory implementation failed to remove user from groupPermissionException
- the underlying directory has been configured to not allow user to be removed from group, or the directory/group is read-only
-