Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security Java Config for LDAP

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");
}
like image 287
Stephen Dillon Avatar asked Jan 10 '23 12:01

Stephen Dillon


1 Answers

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");
}
like image 145
DB5 Avatar answered Jan 12 '23 02:01

DB5