Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner listener as a different user

Pedro Felgueiras
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2023

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}
}

 

1 answer

0 votes
Pedro Felgueiras
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2023

Figured it out pretty fast 

 

ApplicationUser admin = ComponentAccessor.getUserManager().getUserByName("USERNAME") 
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(admin)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events