JIRA finding users for a given directory

Robert G. Nadon
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.
November 10, 2015

Hi all,

I have what I thought would be a very easy operation, but I am a little stuck.  We have 2 users directories:

  1. JIRA Internal
  2. LDAP

The JIRA internal should be just used for my administration and the like, but I just stumbled across a user who was internal.  So I need to find all users who are internal so I can get them to start using ldap ID instead.  I go to user and there is no directory filter.  Also I cannot click on the column title to sort by Directory.  

All I need is to find all users who are part of the JIRA internal directory.  Is there a way to do this?

(I did find this https://confluence.atlassian.com/jira/migrating-users-between-user-directories-426116517.html on migrating users but I do not have the option Migrate users from one directory to another under User Directories)

Thanks in advance!

Robert

 

6 answers

2 accepted

7 votes
Answer accepted
Jordan Packer November 10, 2015

Only way I know of is to query the database directly.... something like this ought to do the trick:

SELECT * FROM cwd_user
WHERE directory_id = 1
Robert G. Nadon
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.
November 10, 2015

Really? interacting directly with the database? Wow. I think I will submit that as a feature request as it seems very easy and I could really see the usage. Thanks! Robert

Like Espen Sandall likes this
Robert G. Nadon
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.
November 10, 2015

BTW that worked great. Thanks again.

Martin Cleaver
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 3, 2016

Robert: did you find or submit a feature request for this?

Robert G. Nadon
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 3, 2016

No, I used Jordan's database query and that gave me what I needed.

Robert G. Nadon
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.
November 16, 2016

Using the JIRA internal database is very dangerous.  I strongly recommend using a separate mysql database.   However here is how: https://confluence.atlassian.com/jirakb/running-sql-commands-in-a-hsql-database-685900390.html 

Kristin Bitler May 18, 2017

Something via the UI would be nice.

Like Espen Sandall likes this
1 vote
Answer accepted
Salim Morgan July 2, 2018

I found a macro on-line and modified it a little. It gets the KEY for the user directory. I haven't been able to get the name, but no biggie. Look at the user to see the actual user directory and learn what the two numbers mean. Here's the template:

## Macro title: Last Login
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Modified by: Michael Seager [Atlassian Support]
## Mofified by: Salim Morgan (STCS, Riyadh)
## Date created: 11/02/2012
## Installed by: <your name>
## Macro to display the last login date of users who have access to the current space
## @noparams

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($loginManager = $containerContext.getComponent('loginManager'))
#set($users = $userAccessor.getUsers())


<table class="confluenceTable">
<tr>
<th class="confluenceTh">Count</th>
<th class="confluenceTh">User</th>
<th class="confluenceTh">Login Name</th>
<th class="confluenceTh">Last Successful Login</th>
<th class="confluenceTh">Directory</th>
</tr>

#set($count = 0)

#foreach($user in $users)
## list the last login date of users who can view the current space
#if ($permissionHelper.canView($user, $space))
#set($count = $count + 1)
<tr>
<td class="confluenceTd">$count</td>
<td class="confluenceTd">#usernameLink($user.name)</td>
<td class="confluenceTd">$user.name</td>
<td class="confluenceTd">$action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user.name).lastSuccessfulLoginDate)</td>
<td class="confluenceTd">$user.directoryId</td>
#end
#end
</table>

Grigory Salnikov
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.
November 8, 2018

Thanks!

It worked for our Confluence server.

7 votes
Joachim Brechtel June 27, 2019

You can also look them up using scriptrunner script console

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def userManager = ComponentAccessor.userManager

def allUsers = userManager.allUsers

List<ApplicationUser> results = []

allUsers.each {
if (it.directoryId == 1L) {
results.add(it)
}
}

def prettyPrint = ""

results.each {
prettyPrint += it.displayName + "(" + it.name + ") - Active: " + it.active + "<br>"
}

prettyPrint
Tim_C January 9, 2020

Hi @Joachim Brechtel 

I'm trying to adapt your scriptrunner script above to additionally include "email address" in the prettyPrint results of the Jira user directory. It's already working fine and showing displayname, username and active flag. Any advice would be much appreciated.

Thanks,

Tim

Joachim Brechtel January 9, 2020

Hi @Tim_C ,

you can use

prettyPrint += it.displayName + "(" + it.name + ") - Active: " + it.active + ", Email: " + it.emailAddress + "<br>"

The result contains a list of com.atlassian.jira.user.ApplicationUser. You can find the API reference here: https://docs.atlassian.com/software/jira/docs/api/7.1.0/com/atlassian/jira/user/ApplicationUser.html

Best, Joachim

Tim_C January 10, 2020

Hi @Joachim Brechtel - perfect, thanks for your very quick response. 

Marc Jason Mutuc
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 28, 2020

@Joachim Brechtel , thank you! I took you script to use for mine as well. Here is my final script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def userManager = ComponentAccessor.userManager

def allUsers = userManager.allUsers

List<ApplicationUser> results = []

allUsers.each {
if (it.directoryId == 1L && it.emailAddress ==~ /(?s).*kambi.*/ && it.active == true) {
results.add(it)
}
}

def prettyPrint = ""

results.each {
prettyPrint += it.displayName + "(" + it.name + ") - Email: " + it.emailAddress + "<br>"
}

prettyPrint

 Just one question, this line

def allUsers = userManager.allUsers

Is showing a warning saying not to pull allusers if not needed. What should be the fix? 

Joachim Brechtel May 28, 2020

Hi @marco@Marc Jason Mutuc ,

the warning just indicates that this method may cause performance impact (it is also deprecated, so it might not work in future).

The solution would be to take com.atlassian.jira.bc.user.search.UserSearchService and build a query which includes all users. But as long as Atlassian keeps the method, I would continue to use it.

2 votes
Avinash Singh November 3, 2016

Can this functionality be added to the UI so that was can easily search users from a particular user directory (Internal, LDAP, Crowd)

Kristin Bitler May 18, 2017

I guess this is a no and we can't vote on it, since no one ever answered. It would make my life far easier to manage the 2000+ users we have.

Like Espen Sandall likes this
0 votes
Richard Burstiner August 25, 2017

Submitted JRASERVER-65844 to add a filter on the "user management" screen.

0 votes
Florian Schmidt June 6, 2017

Is there an update on this issue or do we still have to do this with SQL?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events