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

How can I enumerate the groups of a Jira user?

Tobias Rapp April 15, 2013

I have an old plugin for Jira 4.0 that I want to upgrade to Jira 5.2. The plugin uses the obsolete "com.opensymphony.user" classes. For example:

List<String> groups = issue.getReporter().getGroups();

I want to migrate the plugin to the new "com.atlassian.crowd.embedded.api" classes but the "getGroups" method is not available there. How can I enumerate the groups a user belongs to in Jira 5.2?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Chaithra N
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.
April 15, 2013

User reporter = issue.getReporter();

SortedSet<Group> groups = userUtil.getGroupsForUser(reporter.getName());

Tobias Rapp April 16, 2013

That's it, thanks. For getting a reference to UserUtil I used something like

private final UserUtil userUtil;
// ...
userUtil = ComponentAccessor.getUserUtil();

in the class constructor.

0 votes
Thomas Heyne
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.
April 15, 2013
...
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.crowd.embedded.api.Group;
...

        UserManager userManager = ComponentAccessor.getUserManager();
        Set&lt;Group&gt; groups = userManager.getAllGroups();

        for (Group group1 : groups) {
            Group group = group1;
            // you logic here
        }

Tobias Rapp April 15, 2013

This would enumerate all available groups, not the groups of a single user.

Like hamada zerdaoui likes this
Thomas Heyne
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.
April 15, 2013

ah, you are right

as far as I remember correctly I have been using

com.atlassian.crowd.embedded.api.CrowdService

once

TAGS
AUG Leaders

Atlassian Community Events