Run behaviour as admin user

Harald Hiebl February 5, 2021

Hello,

i have a field, which is populated by a behaviour.
The result shows all roles with members of the underlying project. The result is OK for any project administrators, but not for standard users (error in log for getting roles and members).
Is it possible to run the behviour under an admin user?

Best regards,
Harald

2 answers

2 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2021

No, because that would mean the client (the user's browser) would have to log in as an administrator.

0 votes
Answer accepted
Gareth Cantrell
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.
February 6, 2021

@Harald Hiebl you could try setting the authenticated user to a service account user with the correct permissions.

You would need to make sure to set the authentication context back, whatever the outcome.

I haven't tried this with Behaviours specifically, but I have made use of this in workflows and other automations.

import com.atlassian.jira.component.ComponentAccessor

// get the Service Account user
def serviceAccount = ComponentAccessor.userManager.getUserByName('serviceaccount')

// get the currently logged in user
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// set the current user to the service account user
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(serviceAccount)

try {
// perform your processing as user with elevated permissions
} finally {
// make sure to reset the authentication context
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(currentUser)
}

Harald Hiebl February 7, 2021

Hello Gareth,

thank you very much - it works as expected

Harald

Like Gareth Cantrell likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events