Get a list of users in JIRA from within a JIRA plugin

John Smith June 29, 2017

I'm writing a JIRA plugin which needs to present a list of Users to an Admin user. I'm using UserManager to check that the admin user has logged in but the UserManager appears to only have methods for a single user.

I have tried the REST API but using this from within the plugin requires credentials (e.g. BASIC AUTH) to be added to the request header and unless there are 'service' accounts, how can I retrieve the admin user's name and password to inject into the request header.

I'm using JIRA v 7.2.1 and can find no way to just get the list of users. Or do I need to call the database directly with a sql query?

Thanks.

4 answers

1 vote
somethingblue
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 29, 2017

Hi John,

There is an open Suggestion that may provide some hints on how to do this that you can find at JRASERVER-29069.  I was able to get the existing users in my instance using the suggestions in JRASERVER-29069:

  • /rest/api/latest/user/search?username="" (double quotes)
  • /rest/api/latest/user/search?username='' (single quotes)
  • /rest/api/latest/user/search?username=. (dot)

If JRASERVER-29069 helps please vote on the ticket and let us know.

Cheers,

Branden

John Smith June 29, 2017

Hi Brandon,

I came up with the (dot) trick on my own and I can use the REST API if I paste the url into a browser after I have logged into JIRA. But the issue is I need to call it from Java code (within the plugin) and there's no way I can get the logged in user's credentials so that I can add them to the plugin's request - without them, it returns 0 users.

0 votes
Aleksandr Zuevich
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 30, 2017

Hi John, it's deprecated, but UserManager contains 

Collection<ApplicationUser> getAllApplicationUsers()

 Or try to use UserSearchService#findUsersAllowEmptyQuery with query passed is null or empty.

0 votes
Lars Olav Velle
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 30, 2017

Perhaps a better place to ask i at the developers community:

https://community.developer.atlassian.com

 

Cheers,
Lars, Kantega Single Sign-on

John Smith June 30, 2017

Thanks Lars, I didn't realise the difference.

0 votes
MattS
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 29, 2017

I usually get the jira-users group and then page through it to get all the users. Not perfect but the best. Using the REST API to do this you have to query for all a*, b*, c*

 

John Smith June 29, 2017

Hi Matt,

'I usually get the jira-users group' - how do you do this exactly? What class or service are you using?

Thanks.

MattS
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 29, 2017

https://docs.atlassian.com/jira/REST/server/#api/2/group-getGroup in Server but I see that is deprecated since 7.1 in favour of GET /rest/api/2/group/member

MattS
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 29, 2017

Ah, I see you are writing an add-on so you have access to the whole JIRA Java API.

 

MattS
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 29, 2017

I'd start with https://docs.atlassian.com/jira/7.0.7/com/atlassian/jira/bc/user/search/UserSearchService.html and check the findUSer methods and what those string params are for.

 

Suggest an answer

Log in or Sign up to answer