I need synchronize with LDAP few extra attributes for users.
I found that Script Runner 5.7+ you can add resources = ldap.
https://scriptrunner.adaptavist.com/latest/jira/resources.html#_ldap_connection
But I cannot run sample code to get something from LDAP.
My code:
import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.ldap.core.AttributesMapper
import javax.naming.directory.SearchControls
import javax.naming.directory.Attributes
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
def base="DC=ad,DC=net"
def filter="(&(objectCategory=Person)(memberOf=CN=GroupName,OU=Apps,OU=Groups,OU=Tenants,DC=ad,DC=net))"
def cnList = LdapUtil.withTemplate('users') { template ->
template.search(base,filter, SearchControls.SUBTREE_SCOPE, { Attributes attributes ->
attributes.get('cn').get()
} as AttributesMapper<String>)
}
Output:
[LDAP: error code 32 - 0000208D: NameErr: DSID-03100288, problem 2001 (NO_OBJECT), data 0, best match of: 'DC=ad,DC=net' ]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100288, problem 2001 (NO_OBJECT), data 0, best match of: 'DC=ad,DC=net' ]; remaining name 'DC=ad,DC=net'
Base in code is the same as Base in LDAP resource entry.