Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,124
Community Members
 
Community Events
168
Community Groups

Run behaviour as admin user

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

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

0 votes
Answer accepted

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

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
Community showcase
Published in Apps & Integrations

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

120 views 0 9
Read article

Atlassian Community Events