为了账号安全,请及时绑定邮箱和手机立即绑定

spring security 如何捕捉AuthenticationProvider接口类中的异常

spring security 如何捕捉AuthenticationProvider接口类中的异常

暮色呼如 2018-08-14 16:10:44
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异常则无法捕捉,会继续下面的账号密码验证。
查看完整描述

1 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

ExceptionTranslationFilter应该是会捕捉到AccessDeniedException和AuthenticationException的,说说我自己项目中如何使用spring security 做验证码校验的,我们是自定义了一个类,它继承UsernamePasswordAuthenticationFilter,然后重写了attemptAuthentication这个方法,我们是在这里面做的验证码校验的。


查看完整回答
反对 回复 2018-09-06
  • 1 回答
  • 0 关注
  • 2212 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信