public class DefaultUserService extends Object implements UserService
UserService
interface. Contains methods to create/delete
users hiding UserUtil internals.UserService.AddUserToApplicationValidationResult, UserService.CreateUsernameValidationResult, UserService.CreateUserRequest, UserService.CreateUserValidationResult, UserService.DeleteUserValidationResult, UserService.FieldName, UserService.RemoveUserFromApplicationValidationResult, UserService.UpdateUserValidationResult
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
log |
Constructor and Description |
---|
DefaultUserService(UserUtil userUtil,
UserDeleteVeto userDeleteVeto,
PermissionManager permissionManager,
UserManager userManager,
I18nHelper.BeanFactory i18nFactory,
JiraAuthenticationContext jiraAuthenticationContext,
com.atlassian.event.api.EventPublisher eventPublisher,
PreDeleteUserErrorsManager preDeleteUserErrorsManager,
CreateUserApplicationHelper applicationHelper,
ApplicationRoleManager applicationRoleManager,
UserValidationHelper validationHelper,
GlobalPermissionGroupAssociationUtil globalPermissionGroupAssociationUtil,
GlobalPermissionManager globalPermissionManager) |
Modifier and Type | Method and Description |
---|---|
void |
addUserToApplication(UserService.AddUserToApplicationValidationResult result)
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).
|
ApplicationUser |
createUser(UserService.CreateUserValidationResult result)
Create a new application user if the provided
ServiceResultImpl.isValid() . |
ApplicationUser |
createUserFromSignup(UserService.CreateUserValidationResult result)
Given a valid validation result, this will create the user using the details provided in the validation result.
|
ApplicationUser |
createUserNoNotification(UserService.CreateUserValidationResult result)
Given a valid validation result, this will create the user using the details provided in the validation result.
|
ApplicationUser |
createUserWithNotification(UserService.CreateUserValidationResult result)
Given a valid validation result, this will create the user using the details provided in the validation result.
|
ApplicationUserBuilder |
newUserBuilder(ApplicationUser user)
Allows you to construct
ApplicationUser for UserService.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 |
removeUserFromApplication(UserService.RemoveUserFromApplicationValidationResult result)
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 from
UserService.validateUpdateUser(ApplicationUser) . |
UserService.AddUserToApplicationValidationResult |
validateAddUserToApplication(ApplicationUser user,
com.atlassian.application.api.ApplicationKey applicationKey)
Validates associating a user with an application.
|
UserService.AddUserToApplicationValidationResult |
validateAddUserToApplication(ApplicationUser loggedInUser,
ApplicationUser user,
com.atlassian.application.api.ApplicationKey applicationKey)
Validates associating a user with an application.
|
UserService.CreateUserValidationResult |
validateCreateUser(UserService.CreateUserRequest createUserRequest)
Validate that a new user can be created.
|
UserService.CreateUserValidationResult |
validateCreateUserForAdmin(ApplicationUser loggedInUser,
String username,
String password,
String confirmPassword,
String email,
String fullname)
Validates creating a user for the admin section.
|
UserService.CreateUserValidationResult |
validateCreateUserForAdmin(ApplicationUser loggedInUser,
String username,
String password,
String confirmPassword,
String email,
String fullname,
Long directoryId)
Validates creating a user for the admin section.
|
UserService.CreateUserValidationResult |
validateCreateUserForSetup(ApplicationUser loggedInUser,
String username,
String password,
String confirmPassword,
String email,
String fullname)
Validates creating a user during setup of JIRA.
|
UserService.CreateUserValidationResult |
validateCreateUserForSignup(ApplicationUser loggedInUser,
String username,
String password,
String confirmPassword,
String email,
String fullname)
Validates creating a user during public signup.
|
UserService.CreateUserValidationResult |
validateCreateUserForSignupOrSetup(ApplicationUser loggedInUser,
String username,
String password,
String confirmPassword,
String email,
String fullname)
Validates creating a user during setup of JIRA or during public signup.
|
UserService.CreateUsernameValidationResult |
validateCreateUsername(ApplicationUser loggedInUser,
String username)
Validates the username for a new user.
|
UserService.CreateUsernameValidationResult |
validateCreateUsername(ApplicationUser loggedInUser,
String username,
Long directoryId)
Validates the username for a new user.
|
UserService.DeleteUserValidationResult |
validateDeleteUser(ApplicationUser loggedInUser,
ApplicationUser userForDelete)
Validates removing a user for the admin section.
|
UserService.DeleteUserValidationResult |
validateDeleteUser(ApplicationUser loggedInUser,
String username)
Validates removing a user for the admin section.
|
UserService.RemoveUserFromApplicationValidationResult |
validateRemoveUserFromApplication(ApplicationUser user,
com.atlassian.application.api.ApplicationKey applicationKey)
Validates disassociating a user from an application.
|
UserService.RemoveUserFromApplicationValidationResult |
validateRemoveUserFromApplication(ApplicationUser loggedInUser,
ApplicationUser user,
com.atlassian.application.api.ApplicationKey applicationKey)
Validates disassociating a user from an application.
|
UserService.UpdateUserValidationResult |
validateUpdateUser(ApplicationUser user)
Validates updating a user's details.
|
public DefaultUserService(UserUtil userUtil, UserDeleteVeto userDeleteVeto, PermissionManager permissionManager, UserManager userManager, I18nHelper.BeanFactory i18nFactory, JiraAuthenticationContext jiraAuthenticationContext, com.atlassian.event.api.EventPublisher eventPublisher, PreDeleteUserErrorsManager preDeleteUserErrorsManager, CreateUserApplicationHelper applicationHelper, ApplicationRoleManager applicationRoleManager, UserValidationHelper validationHelper, GlobalPermissionGroupAssociationUtil globalPermissionGroupAssociationUtil, GlobalPermissionManager globalPermissionManager)
@Nonnull public ApplicationUserBuilder newUserBuilder(@Nonnull ApplicationUser user)
UserService
ApplicationUser
for UserService.validateUpdateUser(ApplicationUser)
newUserBuilder
in interface UserService
public UserService.CreateUserValidationResult validateCreateUserForSignup(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname)
UserService
This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
validateCreateUserForSignup
in interface UserService
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 userpublic UserService.CreateUserValidationResult validateCreateUserForSetup(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname)
UserService
This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
validateCreateUserForSetup
in interface UserService
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 userpublic UserService.CreateUserValidationResult validateCreateUserForSignupOrSetup(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname)
UserService
This validation differs from the 'ForAdminPasswordRequired' and 'ForAdmin' validations as follows:
validateCreateUserForSignupOrSetup
in interface UserService
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 userpublic UserService.CreateUserValidationResult validateCreateUser(UserService.CreateUserRequest createUserRequest)
UserService
UserService.CreateUserRequest
.
Typical validations are:
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);
}
This request indicates that the user should be created in the default user directory with access to the default
applications.
validateCreateUser
in interface UserService
createUserRequest
- user creation request containing new user details and validation instructions.public UserService.CreateUserValidationResult validateCreateUserForAdmin(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname)
UserService
This validation differs from the 'ForSetup' and 'ForAdminPasswordRequired' validations as follows:
validateCreateUserForAdmin
in interface UserService
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 userpublic UserService.CreateUserValidationResult validateCreateUserForAdmin(ApplicationUser loggedInUser, String username, String password, String confirmPassword, String email, String fullname, @Nullable Long directoryId)
UserService
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:
validateCreateUserForAdmin
in interface UserService
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 Directorypublic UserService.CreateUsernameValidationResult validateCreateUsername(ApplicationUser loggedInUser, String username)
UserService
validateCreateUsername
in interface UserService
loggedInUser
- The remote user trying to add a new userusername
- The username of the new user. Needs to be lowercase and unique.public UserService.CreateUsernameValidationResult validateCreateUsername(ApplicationUser loggedInUser, String username, Long directoryId)
UserService
validateCreateUsername
in interface UserService
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.public ApplicationUser createUser(@Nonnull UserService.CreateUserValidationResult result) throws PermissionException, CreateException
UserService
ServiceResultImpl.isValid()
. This is typically
called after performing UserService.validateCreateUser(CreateUserRequest)
and verifying that the ServiceResultImpl.isValid()
. If the request is not valid or UserService.validateCreateUser(CreateUserRequest)
was not called prior to this method an IllegalStateException
would get thrown.createUser
in interface UserService
result
- create user validation result returned from UserService.validateCreateUser(CreateUserRequest)
, this contains the user details and instructions used to create new
user.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 existsUserService.validateCreateUser(CreateUserRequest)
public ApplicationUser createUserNoNotification(UserService.CreateUserValidationResult result) throws PermissionException, CreateException
UserService
createUserNoNotification
in interface UserService
result
- The validation resultPermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already existspublic ApplicationUser createUserFromSignup(UserService.CreateUserValidationResult result) throws PermissionException, CreateException
UserService
createUserFromSignup
in interface UserService
result
- The validation resultPermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already existspublic ApplicationUser createUserWithNotification(UserService.CreateUserValidationResult result) throws PermissionException, CreateException
UserService
createUserWithNotification
in interface UserService
result
- The validation resultPermissionException
- If you cannot create users in this directory (it is read-only).CreateException
- if the user could not be created, eg username already existspublic UserService.UpdateUserValidationResult validateUpdateUser(ApplicationUser user)
UserService
validateUpdateUser
in interface UserService
user
- The user details to updatepublic void updateUser(UserService.UpdateUserValidationResult updateUserValidationResult)
UserService
UserService.validateUpdateUser(ApplicationUser)
.updateUser
in interface UserService
updateUserValidationResult
- Result from the validation, which also contains all the user's details.public UserService.DeleteUserValidationResult validateDeleteUser(ApplicationUser loggedInUser, String username)
UserService
See UserService.validateDeleteUser(ApplicationUser, ApplicationUser)
for restrictions.
validateDeleteUser
in interface UserService
loggedInUser
- The remote user trying to remove a userusername
- The username of the user to remove. Needs to be validpublic UserService.DeleteUserValidationResult validateDeleteUser(ApplicationUser loggedInUser, ApplicationUser userForDelete)
UserService
Removing the user is not allowed if:
PreDeleteUserErrors
rejects the requestvalidateDeleteUser
in interface UserService
loggedInUser
- The remote user trying to remove a useruserForDelete
- The user to remove. Needs to be validpublic void removeUser(ApplicationUser loggedInUser, UserService.DeleteUserValidationResult result)
UserService
removeUser
in interface UserService
loggedInUser
- the user performing operationresult
- The validation resultpublic UserService.AddUserToApplicationValidationResult validateAddUserToApplication(ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey)
UserService
validateAddUserToApplication
in interface UserService
user
- the user to be associated with the applicationapplicationKey
- the key of the applicationpublic UserService.AddUserToApplicationValidationResult validateAddUserToApplication(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey)
UserService
validateAddUserToApplication
in interface UserService
loggedInUser
- The logged in useruser
- the user to be associated with the applicationapplicationKey
- the key of the applicationpublic void addUserToApplication(UserService.AddUserToApplicationValidationResult result) throws AddException, PermissionException
UserService
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.
addUserToApplication
in interface UserService
result
- the validation resultAddException
- 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-onlypublic UserService.RemoveUserFromApplicationValidationResult validateRemoveUserFromApplication(ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey)
UserService
Method expects for loggedInUser to be available via JiraAuthenticationContext.getLoggedInUser()
.
validateRemoveUserFromApplication
in interface UserService
user
- the user to be disassociated with the applicationapplicationKey
- the key of the applicationpublic UserService.RemoveUserFromApplicationValidationResult validateRemoveUserFromApplication(ApplicationUser loggedInUser, ApplicationUser user, com.atlassian.application.api.ApplicationKey applicationKey)
UserService
validateRemoveUserFromApplication
in interface UserService
loggedInUser
- application user performing the application access removaluser
- the user to be disassociated with the applicationapplicationKey
- the key of the applicationpublic void removeUserFromApplication(UserService.RemoveUserFromApplicationValidationResult result) throws RemoveException, PermissionException
UserService
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
removeUserFromApplication
in interface UserService
result
- The validation resultRemoveException
- 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-onlyCopyright © 2002-2021 Atlassian. All Rights Reserved.