大佬教程收集整理的这篇文章主要介绍了Spring Security:抛出LockedException而不是BadCredentialsException,为什么?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
AbstractUserDetailsAuthenticationProvIDer.authenticate
。在
说明中,该方法以这种方式工作:
user = retrIEveUser(username, (UsernamepasswordAuthenticationToken) authentication);
...
preAuthenticationchecks.check(user);
additionalAuthenticationchecks(user, (UsernamepasswordAuthenticationToken) authentication);
...
postAuthenticationchecks.check(user);
retrIEveUser
-加载用户preAuthenticationchecks.check(user);
- DefaultPreAuthenticationchecks
:检查锁定…additionalAuthenticationchecks
-检查密码postAuthenticationchecks.check(user);
- DefaultPostAuthenticationchecks
检查未过期的凭证preAuthenticationchecks
并且postAuthenticationchecks
是接口的引用,UserDetailschecker
因此您可以更改它们。只需实现自己的两个UserDetailschecker
,一个用于pre的Null-
Implementation,一个用于检查所有内容的post:
!user.isaccountnonLocked()
!user.isEnabled()
!user.isaccountnonExpired()
!user.isCredentialsnonExpired()
DaoAuthenticationProvider
@H_675_2@当用户尝试使用正确的用户名登录时, 错误的 密码和用户的 帐户已经被锁定 ,那么我希望spring-BadCredentialsException
异常,但是会抛出异常LockedException
@H_675_2@我的问题是
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) {
// invalid login,update user attempts
userDAO.updatepasswordRetryAttempts(authentication.getName(),PropertyUtils.getLoginAttemptsLimit());
throw ex;
} catch (LockedException eX) {
// this user is locked
throw ex;
} catch (AccountexpiredException eX) {
// this user is expired
throw ex;
} catch (Exception eX) {
ex.printStackTrace();
throw ex;
}
}
}
以上是大佬教程为你收集整理的Spring Security:抛出LockedException而不是BadCredentialsException,为什么?全部内容,希望文章能够帮你解决Spring Security:抛出LockedException而不是BadCredentialsException,为什么?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。