gpt4 book ai didi

java - 即使第一个提供程序失败,Spring Security 也会调用另一个身份验证提供程序

转载 作者:行者123 更新时间:2023-12-01 08:54:34 25 4
gpt4 key购买 nike

我在 Spring Security 中使用了身份验证提供程序。我有两个身份验证提供程序:LocalAuthenticationProviderRemoteAuthenticationProvider。认证流程是这样的

  1. 应用程序检查本地数据库的凭据
  2. 如果本地认证通过,需要调用RESTful Web服务进行认证凭证。
  3. 如果本地身份验证失败,则假设身份验证失败并响应 401
@Override
protected void configure(
AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(localProvider).authenticationProvider(remoteProvider);
}
如果凭据失败,

LocalAuthenticationProvider 会抛出 AuthenticationException。如果凭据已传递,则返回null

我的问题是 Spring Security Framework 调用 RemoteAuthenticationProvider,即使 LocalAuthenticationProvider失败

当我从 AuthenticationManagerBuilder 提供程序列表中删除 RemoteAuthenticationProvider 时,即使 LocalAuthenticationProvider 失败它也能工作。

我想知道如何实现此身份验证流程。这两个提供者相互依赖。

最佳答案

查看ProviderManager的Javadoc,似乎如果您的第一个提供程序抛出AccountStatusException,那么身份验证将不会继续到第二个提供程序:

http://docs.spring.io/autorepo/docs/spring-security/4.0.3.RELEASE/apidocs/org/springframework/security/authentication/ProviderManager.html

The exception to this process [providers being invoked in order until one passes] is when a provider throws an AccountStatusException, in which case no further providers in the list will be queried.

关于java - 即使第一个提供程序失败,Spring Security 也会调用另一个身份验证提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42133241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com