During the process of writing a listener for Jira, I found myself encountering a strange error.  The error looked like this:

com.atlassian.servicedesk.api.AuthorizationException: The action performed required a logged in user. Please log in and try again.

This was strange for two reasons. First, I am a Jira administrator with total access to the entire instance. Second, my script had explicitly supplied the logged-in user (myself) as the account under which to run the script.

What gives?

The code I used to supply my own account to the script looks like so:

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

This solution had been more than sufficient previously.   I searched and I searched and I couldn’t find anything related to my issue.  If you search the text of the error, three results are returned, and they’re about REST API permissions. Not applicable here.

In the end I accidentally stumbled on the answer, by trying different solutions for the action I was trying to take.  What I was trying to do was get the Request Type of the issue in question.

The solution was to explicitly provide an account to the script, under which the method could run.   That is, I changed the code to:

def user = userManager.getUserByName("ken_mcclean")

It’s a small change, but it made all the difference.  For whatever reason, querying the Request Type requires that your code be this specific.

After making this change, I stopped getting permissions errors, and proceeded to set up the rest of the listener.   I’m going to leave the full text of the error message below, in case anyone is searching for a solution to this issue in the future:

 

2022-05-07 08:18:28,609 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2022-05-07 08:18:28,610 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
com.atlassian.servicedesk.api.AuthorizationException: The action performed required a logged in user. Please log in and try again.
at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.httpStatusCodeToException(EitherExceptionUtils.java:89)
at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.lambda$anErrorEitherToException$0(EitherExceptionUtils.java:36)
at io.atlassian.fugue.Either$Left.fold(Either.java:586)
at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.anErrorEitherToException(EitherExceptionUtils.java:32)
at com.atlassian.servicedesk.internal.feature.customer.request.requesttype.RequestTypeServiceImpl.getRequestTypes(RequestTypeServiceImpl.java:44)
at com.atlassian.servicedesk.api.requesttype.RequestTypeService$getRequestTypes$0.call(Unknown Source)
at Script6663.run(Script6663.groovy:125)

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>