To test ma LDAP service. I set up the embedded LDAP config like that:
spring:
ldap:
base: OU=Internals,DC=int,DC=springboot,DC=dev
username: uid=admin
password: secret
urls: ldap://localhost:8389/
embedded:
base-dn: DC=springboot,DC=dev
credential:
username: uid=admin
password: secret
ldif: classpath:export2-ldap.ldif
port: 8389
validation:
enabled: false
I notice that the ldaptemplate
base is not correctly set:
I've dug into the EmbeddedLdapAutoConfiguration
and LdapAutoConfiguration
code, and I've noticed that the EmbeddedLdapAutoConfiguration
creates a bean LdapContextSource
, without the base, before the LdapAutoConfiguration class.
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ContextSource.class)
static class EmbeddedLdapContextConfiguration {
@Bean
@DependsOn("directoryServer")
@ConditionalOnMissingBean
LdapContextSource ldapContextSource(Environment environment, LdapProperties properties,
EmbeddedLdapProperties embeddedProperties) {
LdapContextSource source = new LdapContextSource();
if (embeddedProperties.getCredential().isAvailable()) {
source.setUserDn(embeddedProperties.getCredential().getUsername());
source.setPassword(embeddedProperties.getCredential().getPassword());
}
source.setUrls(properties.determineUrls(environment));
return source;
}
}
Is it normal, is not possible to use both spring.ldap.base and spring.ldap.embedded.* ? Or maybe something is not correctly set in my projet.
I got around this with the following:
@Bean
public LdapContextSource createLdapConfig(LdapProperties properties, Environment environment,
ObjectProvider<DirContextAuthenticationStrategy> dirContextAuthenticationStrategy) {
LdapAutoConfiguration config = new LdapAutoConfiguration();
return config.ldapContextSource(properties, environment, dirContextAuthenticationStrategy);
}
As @Saikat noted, it appears both spring, and the unboundid embedded LDAP server are configured to create a LdapContextSource
if it doesn't exist already... Sounds like the embedded LDAP server is winning the race, and screwing things up for everyone else.
The above code gets around the problem by just forcing the creation / configuration of a LdapContextSource
, and thus not letting Spring nor the embedded ldap server try to create a LdapContextSource
.