Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JiraAuthenticationContext changes to the JIRA SDK 3.7.3

Lars Broden
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.
February 25, 2012

Hi,

from JIRA SDK release 3.7.3 I can see that the following methods has been depreciated

List<String> userGroups = authenticationContext.getUser().getGroups(); //Bold bits depreciated

and as a consequence my code does not work properly for JIRA 5.0.

I can also see that the documentation is referring to use the "getLoggedInUser()" method but there is no "getGroups()" method to call in the hiearchy

I can't see that the "getGroups()" method being depreciated or moved in the documenation, any idea how to get around the problem?

I would prefer to make use of a method that returns a String list of the currently logged in user's groups

Would appreciate some feedback on this

BR

Lars Brodén

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Lars Broden
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.
July 7, 2013

Code reworked with "appreciated" classes for 3.7.3

0 votes
Jobin Kuruvilla [Adaptavist]
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.
February 25, 2012

Use getLoggedInUser. That will return the user name. Then use GroupManager to retrieve the groups.

http://docs.atlassian.com/jira/latest/com/atlassian/jira/security/groups/GroupManager.html#getGroupNamesForUser(java.lang.String)

Lars Broden
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.
February 25, 2012
Thanks Jobin
I have applied your tips, but the usersGroup returns a null value?, any ideas? (See bold)
import com.atlassian.jira.security.groups.GroupManager;
public GroupManager usersGroup;
String currentUser= authenticationContext.getLoggedInUser().toString();
String currentUserGroups = usersGroup.getGroupNamesForUser(currentUser).toString();
return currentUsersGroups.contain("my string expression...")
Jobin Kuruvilla [Adaptavist]
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.
February 26, 2012

You haven't instantiated GroupManager anywhere! Inject it in the cosntructor or use the following:

GroupManager usersGroup = (GroupManager) ComponentManager.getComponentInstanceOfType(GroupManager.class);

Lars Broden
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.
February 26, 2012

Thanks Jobin I got it to work now!!.

On another matter, I have been running my plugin through the Atlassian Plugin Checkup for JIRA 5.0 and I do get some deprecated method calls and other stuff but the are not "striked through" in Eclipse, indicating that they are about to go.

Would you know why this is?, or if they still will work?, I notice while running the "Plugin Checkup" that there was only support for 5.0RC3, does this have anything to do with it?

Cheers

Lars

Jobin Kuruvilla [Adaptavist]
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.
February 26, 2012

I have no idea. Maybe someone from Atlassian will comment on this!

Georgiy Senenkov May 20, 2012

Hello Lars,

I need to get the current user and list of groups where the user belong to and tried to implement it in the was similar to yours described above.

import com.atlassian.jira.security.groups.GroupManager
 
GroupManager usersGroup = (GroupManager) ComponentManager.getComponentInstanceOfType(GroupManager.class);
 
String currentUser= authenticationContext.getLoggedInUser().toString();
String currentUserGroups = usersGroup.getGroupNamesForUser(currentUser).toString();

but i've got following error

2012-05-21 17:10:17,189 http-80-2 ERROR admin 1030x8516x1 18v94zm 10.161.201.37 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: authenticationContext for class: Script24
2012-05-21 17:10:17,189 http-80-2 ERROR admin 1030x8516x1 18v94zm 10.161.201.37 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: authenticationContext for class: Script24

do you know what might be wrong in my code?

Thank you in advance.

Best regards, Georgiy

Dieter
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.
May 20, 2012
The script runner does not provide the property authenticationContext though it would be nice to have. Please use

authenticationContext = ComponentAccessor.getJiraAuthenticationContext()

Georgiy Senenkov May 21, 2012

That helped :) and i had to add extra import

import com.atlassian.jira.component.ComponentAccessor

Thank you very much!

TAGS
AUG Leaders

Atlassian Community Events