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");
}
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With