I am using Jira ScriptRunner to implement a REST endpoint that does an LDAP look-up. I am using secure LDAP (port 636) and authenticated bind.
The following piece of code throws me a PartialResultException, which is part of the Spring framework and documented here.
try
{
// The variables base, filter, scope and
// the class MyUserAttributesMapper are defined
// elsewhere in the code and not shown here
userInfoList = LdapUtil.withTemplate ("myLDAPPoolName") { template ->
template.search(base, filter, scope, new MyUserAttributesMapper())
}
}
catch (PartialResultException pre)
{
// All our results are lost :( :(
}
I researched this issue and found a couple of workarounds online, none of which are suitable for our environment and/or use case:
java.naming.referral=follow
The Spring Framework documentation suggests suppressing the partial result exception by setting the ignorePartialResultException property (org.springframework.ldap.core.LdapTemplate object) to true. However, the ScriptRunner LdapUtil wrapper doesn't seem to expose this property or provide a way to set it.
I'm hoping someone from Adaptavist will take a look at my request, and:
Many thanks,
Kamran Ansari
You actually can ignore the partial results in the current version.
Here is a sample console script that does this:
import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.ldap.core.AttributesMapper
import org.springframework.ldap.core.LdapTemplate
import javax.naming.directory.Attributes
import javax.naming.directory.SearchControls
LdapUtil.withTemplate('test ldap') { ldapTemplate ->
(ldapTemplate as LdapTemplate).setIgnorePartialResultException(true)
ldapTemplate.search("", "(cn=p6s)", SearchControls.SUBTREE_SCOPE, { Attributes attributes ->
def map = [:]
map.cn = attributes.get('cn').get()
map.memberOf = attributes.get('memberOf').getAll().collect()
map
} as AttributesMapper<String>)
}
You have to explicitly cast the ldapTemplate generated by the scriptrunner LdapUtil to LdapTemplate because by default it's an instance of LdapOperations which is the interface.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.