spring boot 集成了spring security 在做驗(yàn)證碼的時(shí)候用了AuthenticationProvider,在AuthenticationProvider實(shí)現(xiàn)中進(jìn)行了驗(yàn)證碼的校驗(yàn)@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");當(dāng)驗(yàn)證碼錯(cuò)誤的時(shí)候這個(gè)異常卻無(wú)法被全局異常處理捕捉到,瀏覽器直接拋出了Whitelabel Error Page,如何才能讓這個(gè)異常被全局異常處理捕捉到,求解?CaptchaException 繼承了RuntimeException 如果繼承AuthenticationException異常則無(wú)法捕捉,會(huì)繼續(xù)下面的賬號(hào)密碼驗(yàn)證。
1 回答

胡子哥哥
TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
ExceptionTranslationFilter應(yīng)該是會(huì)捕捉到AccessDeniedException和AuthenticationException的,說(shuō)說(shuō)我自己項(xiàng)目中如何使用spring security 做驗(yàn)證碼校驗(yàn)的,我們是自定義了一個(gè)類,它繼承UsernamePasswordAuthenticationFilter,然后重寫了attemptAuthentication這個(gè)方法,我們是在這里面做的驗(yàn)證碼校驗(yàn)的。
- 1 回答
- 0 關(guān)注
- 2314 瀏覽
添加回答
舉報(bào)
0/150
提交
取消