小编Was*_*tar的帖子

Spring Security:抛出LockedException而不是BadCredentialsException,为什么?

使用Spring Security 4.0.2.RELEASE

对于使用spring-security框架的基本用户身份验证,我实现了spring-security DaoAuthenticationProvider

当用户尝试使用正确的用户名登录时,错误的密码和用户的帐户已被锁定,那么我预计spring-security身份验证模块会抛出BadCredentialsException但是它会抛出LockedException

我的问题是

  1. 为什么spring-security正在处理用户进行进一步的身份验证,而凭据特殊密码不正确?
  2. 即使用户的密码无效,在应用程序中显示"用户被锁定"的消息是否良好?
  3. 如何设置生成/捕获BadCredentialsException无效密码和锁定用户?

任何帮助,将不胜感激.身份验证提供程序实现代码

@Component("authenticationProvider")
public class LoginAuthenticationProvider extends DaoAuthenticationProvider {

    @Autowired
    UserDAO userDAO;

    @Autowired
    @Qualifier("userDetailsService")
    @Override
    public void setUserDetailsService(UserDetailsService userDetailsService) {
        super.setUserDetailsService(userDetailsService);
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        try {
            Authentication auth = super.authenticate(authentication);
            // if reach here, means login success, else exception will be thrown

            // reset the user attempts
            userDAO.resetPasswordRetryAttempts(authentication.getName());

            return auth;
        } catch (BadCredentialsException ex) {
            // …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

7
推荐指数
1
解决办法
4947
查看次数

标签 统计

java ×1

spring ×1

spring-security ×1