Problem with JiraAuthenticationContext.getLoggedInUser()

Arne Schirmacher June 13, 2016

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

0 votes
Answer accepted
Shamith Shankar June 13, 2016

Are you trying ,

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

JiraAuthenticationContext.getLoggedInUser()  ??
Arne Schirmacher June 13, 2016

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.

Arne Schirmacher June 13, 2016

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

JamieA
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.
June 14, 2016

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
TAGS
AUG Leaders

Atlassian Community Events