【发布时间】:2012-09-25 17:14:02
【问题描述】:
我有一个使用 Spring Security 3.0.x 的应用程序。我有一个自定义的AuthenticationProvider:
public class AppAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
...
if (!check1()) throw new UsernameNotFoundException();
if (!check2()) throw new DisabledException();
...
}
我想针对每个异常发送自定义响应代码,例如 UsernameNotFoundException 的 404、DisabledException 的 403 等。现在我的 spring 安全配置中只有 authentication-failure-url,所以我在每个异常上都重定向到它authenticate() 中的异常。
【问题讨论】:
标签: authentication exception-handling spring-security