我有一个使用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