我有一個使用Spring Security 3.0.x的應用程序。在那裏,我有一個自定義AuthenticationProvider
:Spring安全性驗證異常處理
public class AppAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
...
if (!check1()) throw new UsernameNotFoundException();
if (!check2()) throw new DisabledException();
...
}
我想每個異常的發送對自定義響應代碼,例如404 UsernameNotFoundException,403 DisabledException等。現在我只是有認證失敗的URL在我spring安全配置,因此我在authenticate()中的每個異常上重定向到它。
我在SimpleUrlAuthenticationFailureHandler類中找不到showMessage()方法(我正在使用Spring Security版本3.1.x)。你知道你使用的是哪個版本嗎? –
對不起,showMessage方法特定於我的實現,並非來自spring。原始代碼太多了,無法顯示。 – baraber
@baraber如何將異常類型傳遞給控制器方法? – gstackoverflow