Script runner : Access LDAP attributes

Julien REBILLARD May 25, 2022

Hello,

In a script runner, I am trying to access LDAP attributes.
I have this piece of code that works if I use the phone attribute :

import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.ldap.core.AttributesMapper
import javax.naming.directory.SearchControls
import javax.naming.directory.Attributes

def cnList = LdapUtil.withTemplate('LDAP') { template ->
template.search("", "(cn=123456)", SearchControls.SUBTREE_SCOPE, { Attributes attributes ->
attributes.get('telephoneNumber').get()
} as AttributesMapper<String>)

}

But if I try to retrieve the department attribute, I have this error message:

java.lang.NullPointerException: Cannot invoke method get() on null object
at Script209$_run_closure1$_closure2.doCall(Script209.groovy:8)
at com.sun.proxy.$Proxy6509.mapFromAttributes(Unknown Source)
at org.springframework.ldap.core.AttributesMapperCallbackHandler.getObjectFromNameClassPair(AttributesMapperCallbackHandler.java:62)
at org.springframework.ldap.core.CollectingNameClassPairCallbackHandler.handleNameClassPair(CollectingNameClassPairCallbackHandler.java:50)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:367)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:328)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:604)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:594)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:482)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:498)
at Script209$_run_closure1.doCall(Script209.groovy:7)
at com.sun.proxy.$Proxy6283.apply(Unknown Source)
at java_util_function_Function$apply.call(Unknown Source)
at com.onresolve.scriptrunner.ldap.DefaultLdapConnectionManager$_withTemplate_closure2.doCall(DefaultLdapConnectionManager.groovy:50)
at com.onresolve.scriptrunner.ldap.DefaultLdapConnectionManager$_withTemplate_closure2.doCall(DefaultLdapConnectionManager.groovy)
at com.atlassian.plugin.util.ContextClassLoaderSwitchingUtil.runInContext(ContextClassLoaderSwitchingUtil.java:48)
at com.onresolve.scriptrunner.ldap.DefaultLdapConnectionManager.withTemplate(DefaultLdapConnectionManager.groovy:49)
at com.onresolve.scriptrunner.ldap.LdapConnectionManager$withTemplate$0.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.ldap.DefaultLdapConnectionManager.withTemplateTracked(DefaultLdapConnectionManager.groovy:66)
at com.onresolve.scriptrunner.ldap.LdapConnectionManager$withTemplateTracked.call(Unknown Source)
at com.onresolve.scriptrunner.ldap.LdapUtil.withTemplate(LdapUtil.groovy:13)
at Script209.run(Script209.groovy:6)

Could you help me so that I can retrieve the department attribute in a script

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.2
TAGS
AUG Leaders

Atlassian Community Events