Spring Java Security Configuration for LDAP

How to set url to configure LDAP spring security? There are many XML based examples, but I cannot find a java configuration example for replication below the xml line. I assume it is configured in the bottom block of java code taken from the spring manual to use the built-in ldap, but how do we set the 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");
}
+4
source share
1 answer

You just use the method url() LdapAuthenticationProviderConfigurer.ContextSourceBuilder

Thus, you would simply expand 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");
}
+9
source

All Articles