Skip to content

ActiveDirectoryLdapAuthenticationProvider does not implement support for multiple urls #7760

@setu9760

Description

@setu9760

Summary

The javadoc for ActiveDirectoryLdapAuthenticationProvider constructors says the param url supports multiple URLs. The javadoc however does not define how the multiple URLs needs to be supplied (i.e delimiter specification). Upon trying to supply this param as multiple URLs as a comma or pipe separated list this string is used as is during the ldap binding

Actual Behavior

By looking at the code, specifically the constructors of ActiveDirectoryLdapAuthenticationProvider and method bindAsUser it uses the url provided in the constructor as is without checking if multiple URLs are present. Due to this the the line env.put(Context.PROVIDER_URL, bindUrl); in bindAsUser method will inject the list of URLs without splitting in the env which will be incorrect and the ldap bind does not work.

Expected Behavior

The code should check if the supplied param url is a delimited list or URLs and then store it as such. During the authentication if an ldap server is unavailable the remaining URLs should be tried. The javadoc/code should also make it clear that if multiple URLs are to be supplied what format they should be in or there should be an additional constructor/setter that accepts list instead of a string.

Configuration

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Value("${ldap.url:ldap://localhost:389}") private String url;
@Value("${ldap.domain:domain}") private String domain;

@Override
protected void configure(HttpSecurity http) throws Exception
{
    http.authorizeRequests()
          .anyRequest().fullyAuthenticated()
          .httpBasic();
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception
{
    ActiveDirectoryLdapAuthenticationProvider adProvider = 
                new ActiveDirectoryLdapAuthenticationProvider(domain,url);
    adProvider.setConvertSubErrorCodesToExceptions(true);
    adProvider.setUseAuthenticationRequestCredentials(true);
    auth.authenticationProvider(adProvider);
    auth.eraseCredentials(false);
 }
}

Version

spring-security-ldap 4.2.10 and 5.1.5.RELEASE

Sample

Metadata

Metadata

Assignees

Labels

in: ldapAn issue in spring-security-ldaptype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions