Example scripts
To homepage
Jira

Get members of an LDAP group
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.14)

ScriptRunner For Jira (6.18.0)
Language |
groovy
import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.LdapDataEntry
import org.springframework.ldap.core.support.AbstractContextMapper
import org.springframework.ldap.query.LdapQueryBuilder
import org.springframework.ldap.query.SearchScope
// Full 'dn' for the group you want to get members from
final groupDn = 'cn=testing_group,ou=Product Testing,dc=example,dc=org'
// LDAP HardcodedFilter that looks for inetOrgPerson objects with the provided memberOf Attribute
final ldapQueryFilter = "(&(objectClass=inetOrgPerson)(memberOf=${groupDn}))"
final resourcePoolName = 'testLdapResource'
LdapUtil.withTemplate(resourcePoolName) { ldap ->
// Create the LDAP query
def query = LdapQueryBuilder.query()
.searchScope(SearchScope.SUBTREE)
.filter(ldapQueryFilter)
// Run the search, get the 'cn' attribute for each entry found and return a `List` of `cn` values
ldap.search(query, {
LdapDataEntry entry ->
entry.attributes.get('cn').get()
} as AbstractContextMapper<Object>)
}
Having an issue with this script?
Report it here