SpringSecurity3.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();
...
}
各例外でcutom応答コードを送信したいと思います。たとえば、UsernameNotFoundExceptionの場合は404、DisabledExceptionの場合は403などです。今のところ、Springセキュリティ構成にauthentication-failure-urlがあるので、authenticateの各例外でリダイレクトされます。 ()。