Как добавить мой пользовательский ProviderManager в AuthenticationManagerBuilder - PullRequest
0 голосов
/ 21 февраля 2020

В моем приложении Spring Boot я вывел свой пользовательский MyProviderManager, где я хотел бы управлять логическим c внутренним методом 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;
    }

Тем не менее, теперь мне трудно внедрить мой пользовательский MyProviderManager с AuthenticationManagerBuilder , так что метод performBuild () в AuthenticationManagerBuilder вернется MyProviderManager вместо используемого по умолчанию в Spring Security

Я даже пытался выдать свой пользовательский MyAuthenticationManagerBuilder exends AuthenticationManagerBuilder и переопределить performBuild () , но я столкнулся с той же проблемой, как внедрить мой пользовательский AuthenticationManagerBuilder в Spring Boot

Очень важно, если кто-то может пролить свет на проблемы здесь или есть лучшие альтернативные идеи для решения моих особых требований

1 Ответ

1 голос
/ 26 февраля 2020

Если у вас есть пользовательская реализация AuthenticationManager, вы больше не используете AuthenticationManagerBuilder (это то, что могло бы создать AuthenticationManager, но у вас уже есть такой). Вместо этого выставьте AuthenticationManager как компонент и не используйте AuthenticationManagerBuilder.

@Bean
CustomAuthenticationManager customAuthenticationManager() {
    return new CustomAuthenticationManager();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...