Script to find the logged in user in Jira 6

Shilpa Sanil December 27, 2018

Hi ,

 

The following script works fine in Jira 7.

 

final def authCtxInternal = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext()
def logIn = { com.atlassian.jira.user.ApplicationUser u ->
try {
//Jira 7
authCtxInternal.setLoggedInUser(u)


} catch (Exception ignore) {
// Jira 6
//noinspection GroovyAssignabilityCheck
authCtxInternal.setLoggedInUser(u.getDirectoryUser())
}
}

 

But in Jira 6 its throwing error: 

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: CreateIssue$__clinit__closure1_closure5.call() is applicable for argument types: (com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser) values: [a-4951:3] Possible solutions: any(), any(), doCall(com.atlassian.jira.user.ApplicationUser), each(groovy.lang.Closure), any(groovy.lang.Closure), each(groovy.lang.Closure)

 

I tried to use the code in Catch part in try for jira 6 but no luck.

Can anybody help me with this.

 

Thanks

Shilpa

1 answer

0 votes
Elifcan Cakmak
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.
December 31, 2018

Hello,

Do you want to get the name of the logged in user? Because the script you shared is using setLoggedInUser method and it does something different. Could you try it like this?

import com.atlassian.jira.security.JiraAuthenticationContext;

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

return user

 Regards,

Elifcan

Shilpa Sanil January 1, 2019

Hi Elifcan,

 

I want to set the logged in user to this: final def authCtxInternal = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().

This line: authCtxInternal.setLoggedInUser(u) is not working in Jira 6 whereas works fine in jira 7.

 

Thanks

Shilpa

Elifcan Cakmak
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.
January 1, 2019

Hello,

I don't understand what you mean by:

I want to set the logged in user to this: final def authCtxInternal = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().

This is a line that imports and defines the authentication context on your code.

Anyways, setLoggedInUser is a valid method as far as I can see for Jira version 6. You can check on the docs:

https://docs.atlassian.com/software/jira/docs/api/6.4.9/com/atlassian/jira/security/JiraAuthenticationContext.html

You can use it with application user:

https://docs.atlassian.com/software/jira/docs/api/6.4.9/com/atlassian/jira/user/ApplicationUser.html

Regards,

Elifcan  

Shilpa Sanil January 2, 2019

Hi Elfican,

 

I understand that setLoggedInUser is valid in both Jira 7 & 6 but the variable that you set is what throwing error.

 

def logIn = { com.atlassian.jira.user.ApplicationUser u ->

authCtxInternal.setLoggedInUser(u)

 

The above line is not working in Jira 6.

 

Thanks

Shilpa

Suggest an answer

Log in or Sign up to answer