4

How do i set the URL for spring security LDAP configuration? There are plenty of xml based examples but i cannot find a java config example to replication the below xml line. I assume it is configured in the below java code block taken from the spring guide for using a embedded ldap but how do we set a external url?

<ldap-server id="ldapServer" url="ldap://example.com:PORT/dc=example,dc=com" />
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
    auth.ldapAuthentication()
            .userDnPatterns("uid={0},ou=people")
            .groupSearchBase("ou=groups")
            .contextSource()
                .ldif("classpath:test-server.ldif");
}

1 Answer 1

9

You simply use the url() method of the LdapAuthenticationProviderConfigurer.ContextSourceBuilder

So you would simple extend your code as follows:

@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
    auth.ldapAuthentication()
            .userDnPatterns("uid={0},ou=people")
            .groupSearchBase("ou=groups")
            .contextSource()
                .ldif("classpath:test-server.ldif")
                .url("ldap://example.com:PORT/dc=example,dc=com");
}
Sign up to request clarification or add additional context in comments.

1 Comment

Giving examples that use .ldif() is pretty useless to anyone. Every tutorial falls back on it and it does not solve anyone's problem.

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.