Description
Currently, we are able to set standard LDAP provider via:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
final LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationBuilder
= auth.ldapAuthentication();
// ... proceed with additional configuration
}
}
However, the LdapAuthenticationProviderConfigurer
is hardcoded to create LdapAuthenticationProvider
in the build
method (here).
There is no way to setup the configurer to build the ActiveDirectoryLdapAuthenticationProvider
, which uses a different internal logic on top of the same base AbstractLdapAuthenticationProvider
class.
To be able to configure Active Directory the same way we currently can configure classic LDAP, we would like to see either of these options:
Option 1: Own configurer for Active Directory
... providing the following new method:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
final LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationBuilder
= auth.activeDirectoryAuthentication();
// ... proceed with additional configuration
}
}
Option 2: Picking the right class from a registered bean
... instead of creating the class, the configurer could automatically detect a bean:
@Bean
@ConditionalOnProperty(name = "my.props.ldap.security.method", havingValue = "active-directory")
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider(LdapConfiguration configuration) {
final String activeDirectoryDomain = configuration.getActiveDirectoryDomain();
final String ldapUrl = configuration.getLdapUrl();
final String ldapRoot = configuration.getLdapRoot();
return new ActiveDirectoryLdapAuthenticationProvider(activeDirectoryDomain, ldapUrl, ldapRoot);
}
Option 3: Consolidation of LDAP authentication providers
... so that we do not need to handle different providers.
Having ActiveDirectoryLdapAuthenticationProvider
and LdapAuthenticationProvider
that do not inherit from each other seems a bit unexpected. Maybe there could be a strategy pattern used instead to configure behavior of one LdapAuthenticationProvider
class?
Option 4: Allow Builder to construct the abstract class instance
... and probably many more options framework could support it?