spring-projects / spring-projects/spring-security

Allow configuring the ActiveDirectoryLdapAuthenticationProvider in AuthenticationManagerBuilder

Open
#11,448 7 comments 2 reactions 1 assignee View on GitHub

@jzheaux is already working on this.

Since Jul 1, 2022.

in: ldap status: feedback-provided type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.