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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

183 views 0 4
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