2

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: enter image description here

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.