Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 防止spring security通过下一个身份验证提供程序对具有BadCredentialException的用户进行身份验证_Java_Spring_Spring Security - Fatal编程技术网

Java 防止spring security通过下一个身份验证提供程序对具有BadCredentialException的用户进行身份验证

Java 防止spring security通过下一个身份验证提供程序对具有BadCredentialException的用户进行身份验证,java,spring,spring-security,Java,Spring,Spring Security,I使用多身份验证提供程序配置spring安全性: <security:authentication-manager> <security:authentication-provider> <security:user-service> <security:user name="testUser" password="TestPwd" authorities="ROLE_USER"

I使用多身份验证提供程序配置spring安全性:

<security:authentication-manager>
    <security:authentication-provider>
        <security:user-service>
            <security:user name="testUser" password="TestPwd"
              authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>
    <security:authentication-provider
      ref="customAuthenticationProvider" />
</security:authentication-manager>

如果用户的密码在第一个提供程序中无效,我想阻止通过第二个提供程序对用户进行身份验证。例如,如果用户名为“testUser”的用户无法通过内存提供程序进行身份验证(因此,用户的密码不等于“TestPwd”),customAuthenticationProvider不会再次对用户进行身份验证。

因此,基本上,迭代所有身份验证提供程序并检查身份验证。默认情况下,如果存在AuthenticationException类型的任何错误,spring将检查其他提供程序

但您不想与其他提供商联系。要解决这个问题,您需要有自己的提供者管理器和覆盖方法

我相信重写方法中的整个代码将保持不变,除了。在这里,您只需要添加break语句

它将如何工作

正如您提到的,您有两个提供程序1)在内存中2)自定义身份验证提供程序。两者都将重写公共身份验证(Authentication Authentication)方法,如果凭据不匹配,此方法应引发BadCredentialsException

所以,在(在自定义提供程序管理器中)迭代时,内存中的提供程序将抛出BadCredentialsException,异常将捕获。因为您已经编写了break,所以循环将退出,并且自定义提供程序管理器将不会让另一个提供程序检查身份验证