Problem with JiraAuthenticationContext.getLoggedInUser()

In ScriptRunner, I am using the line 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()

which works just fine, but is flagged as deprecated. When I use the suggested replacement

def currentUser = JiraAuthenticationContext.getLoggedInUser()

the code is no longer flagged so it should work. However when actually executing the code, I get a strange error message:

2016-06-14 08:44:28,651 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-06-14 08:44:28,651 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: DM-4391, actionId: 1, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.security.JiraAuthenticationContext.getLoggedInUser() is applicable for argument types: () values: []
	at Script18.run(Script18.groovy:22)

The JIRA version is 7.1.2, the ScriptRunner version is 4.3.1 (latest). The function JiraAuthenticationContext.getLoggedInUser() belongs to the JIRA 7 API so it should be available to ScriptRunner. Also all interfaces are included:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.security.JiraAuthenticationContext

def currentUser = JiraAuthenticationContext.getLoggedInUser()

I have no idea why this line fails. Please advise.

1 answer

1 accepted

Are you trying ,

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() ?? 
or  

JiraAuthenticationContext.getLoggedInUser()  ??

I was using the latter, but I now see the error.... for some reason I thought it was a static function, but it is actually not.

I am now using ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()  which works.

Thanks a lot.

I am still confused why the ScriptRunner did not flag the original code as illegal though.

It seems to not be checking whether methods are called statically. But:

> the code is no longer flagged so it should work

this is a wrong inference. It just means (or it should mean) that the methods/properties exist and are of the correct type.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

352 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you