Spring Boot ‘LdapTemplate’ with “referral” set as “follow”

Destan Sarpkaya
Kod Gemisi
Published in
1 min readMar 11, 2017

Solving javax.naming.PartialResultException: Unprocessed Continuation Reference(s) exception in Spring Boot without initializing LdapContextSource all by yourself.

In some LDAP setups you may encounter above exception. When you google it you will find out that setting referral property to follow solves it (indeed it does).

It’s not trivial how to set referral in an auto-configured Spring Boot environment. LdapTemplate is auto-configured by Spring Boot. However you need to set referral via LdapContextSource which is auto-configured and set to LdapTemplate as well.

You can customize auto-configured instance of LdapContextSource as follows:

LdapTemplate and LdapContextSource beans are auto-configured by Spring Boot

Of course we could use @Bean to introduce an instance of LdapContextSource as follows:

// You don't want to use this version. Instead prefer using auto-configured version of LdapContextSource instance above!
public LdapContextSource ldapContextSource() {
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setReferral("follow");
ldapContextSource.afterPropertiesSet();
return ldapContextSource;
}

However using auto-configured version of LdapContextSourceinstance enables us to also seamlessly use auto-configured version of LdapTemplateinstance.

--

--