Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get value of LDAP "division" value via Script Runner

Trang Ngoc Nguyen
Contributor
April 17, 2023

I want to create a REST API to get the LDAP "division" value for a Jira user, but cannot find any way to do it.

What I have done so far:

1. I have created a LDAP connection in Script Runner resources and it works well.

2. I use the following code to retrieve the attribute value:

import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.ldap.core.AttributesMapper

import javax.naming.directory.SearchControls
import static org.springframework.ldap.query.LdapQueryBuilder.query;

def cnList = LdapUtil.withTemplate('LDAP') { template ->

def searchControls = new SearchControls()
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE)

searchControls.setReturningAttributes(new String[] { "*" })

template.search("", "sAMAccountName=xxxx", searchControls, { attributes ->
log.warn(attributes)

def manager = attributes.get('manager')?.get()
def division = attributes.get('division')?.get()
log.warn(division)

//attributes.get('cn').get()
} as AttributesMapper<String>)
}

3. With this code, I am able to retrieve all the standard attributes, for example distinguishedName, manager, directreports, even extensionAttribute11 etc. But I am unable to get the value for "division" attribute, even though there is existing the attribute, and the value can be well retrieved by using Elements Connect (can also be retrieved by using Script Runner to query an Elements Connect field and that field queries for the "division" attribute). The only difference I notice is that other attribute is available in grouped AD tab, while "division" can only be found in "Attribute Editor" in AD. The above code gives me back 53 attributes, but not all of them.

 

I have tried setting returningAttributes to include "division" or search for entries that have "division" but all failed. I would assume that it is because the template search has already limit the search to maybe standard attributes?, but I can't really find anything from the documentation to change that default behavior.

 

Any suggestion would be a great help! Thank you very much!

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events