I'm trying to configure a listener that changes some user details when he logs in but i got an error message saying "You do not have the permission to update users."
That is totally valid and I understand why it happens, The user that has made the login doesn't have permission to update users.
My question is if it's possible to execute the listener as a different user ?
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUsers.from(ImmutableUser.newUser(event.getUser().getDirectoryUser()).name("New Name").toUser())
UserService.UpdateUserValidationResult updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
}else{
updateUserValidationResult.getErrorCollection().each{ log.error it}
}
Figured it out pretty fast
ApplicationUser admin = ComponentAccessor.getUserManager().getUserByName("USERNAME")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(admin)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.