【发布时间】:2020-06-05 21:42:24
【问题描述】:
在我的 Spring Boot 应用程序中,我已经自定义了 MyProviderManager,我想在其中控制方法内部的逻辑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;
}
但是,我现在很难用 AuthenticationManagerBuilder 注入我的自定义 MyProviderManager,以便 AuthenticationManagerBuilderperformBuild() /em> 将返回 MyProviderManager 而不是 Spring Security 的默认值
我什至尝试过将我的自定义 MyAuthenticationManagerBuilder 扩展为 AuthenticationManagerBuilder 并重写 performBuild() 方法,但我遇到了如何将我的自定义 AuthenticationManagerBuilder 注入 Spring 的相同问题开机
如果有人能阐明这里的问题或有更好的替代想法来解决我的特殊要求,我将不胜感激
【问题讨论】:
-
所有 AuthentictionProviders 包括自定义 AuthenticationProvider 都由 ProviderManager 迭代。我想要一个自定义的 ProviderManager,我可以更好地控制哪个 AuthenticationProvider 将用于哪个 URL 路径