spring boot 集成了spring security 在做驗證碼的時候用了AuthenticationProvider,在AuthenticationProvider實現(xià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)驗證碼錯誤的時候這個異常卻無法被全局異常處理捕捉到,瀏覽器直接拋出了Whitelabel Error Page,如何才能讓這個異常被全局異常處理捕捉到,求解?CaptchaException 繼承了RuntimeException 如果繼承AuthenticationException異常則無法捕捉,會繼續(xù)下面的賬號密碼驗證。
1 回答
胡子哥哥
TA貢獻(xiàn)1825條經(jīng)驗 獲得超6個贊
ExceptionTranslationFilter應(yīng)該是會捕捉到AccessDeniedException和AuthenticationException的,說說我自己項目中如何使用spring security 做驗證碼校驗的,我們是自定義了一個類,它繼承UsernamePasswordAuthenticationFilter,然后重寫了attemptAuthentication這個方法,我們是在這里面做的驗證碼校驗的。
- 1 回答
- 0 關(guān)注
- 2341 瀏覽
添加回答
舉報
0/150
提交
取消
