spring-attic / top-spring-security-architecture

Spring Security Architecture:: Topical guide to Spring Security, how the bits fit together and how they interact with Spring Boot
https://spring.io/guides/topicals/spring-security-architecture/
227 stars 90 forks source link

how to inject my custom ProviderManager with Spring security #13

Open idavollen opened 4 years ago

idavollen commented 4 years ago

In my Spring Boot application, I've come out my custom MyProviderManager where I'd like to control the logic inside method authenticate

 public Authentication authenticate(Authentication authentication) {
        // instead of iterating in the AuthenticationProvider list one by one
        // I'd rather choose the right AuthenticationProvider based on the currently requested URL path
        RequestDetails requestDetails = authentication.getDetails();
        if ("/ad/sso".equals(requestDetails.getPath())) {
            return adAuthenticationProvider.authenticate(authentication);
        } else if ("/saml/sso".equals(requestDetails.getPath())) {
            return samlAuthenticationProvider.authenticate(authentication);
        } else if ("/oidc/sso".equals(requestDetails.getPath())) {
            return oidcAuthenticationProvider.authenticate(authentication);
        } else  {
            return ldapAuthenticationProvider.authenticate(authentication);
        }
        return null;
    }

However, I'm now having it hard to inject my custom MyProviderManager with AuthenticationManagerBuilder so that the method performBuild() in AuthenticationManagerBuilder will return MyProviderManager instead of the default one from Spring Security

I had even tried to come out my custom MyAuthenticationManagerBuilder exends AuthenticationManagerBuilder and overridden performBuild() method, but I faced the same issue of how to inject my custom AuthenticationManagerBuilder to Spring Boot

It is really appreciate if someone could shed the light on the issues here or have better alternative ideas tackling my special requirements