spring boot 集成了spring security 在做验证码的时候用了AuthenticationProvider,在AuthenticationProvider实现中进行了验证码的校验
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
CaptchaWebAuthenticationDetails authenticationDetails= (CaptchaWebAuthenticationDetails) authentication.getDetails();
String inputCaptcha = authenticationDetails.getInputCaptcha();
String sessionCaptcha =authenticationDetails.getSessionCaptcha();
if (!inputCaptcha.equals(sessionCaptcha)){
throw new CaptchaException("erro");
}
return null;
}
但是 throw new CaptchaException("erro");当验证码错误的时候这个异常却无法被全局异常处理捕捉到,浏览器直接抛出了Whitelabel Error Page,如何才能让这个异常被全局异常处理捕捉到,求解?
CaptchaException 继承了RuntimeException 如果继承AuthenticationException异常则无法捕捉,会继续下面的账号密码验证。
暮色呼如
胡子哥哥
随时随地看视频慕课网APP