@ExceptionHandlerで春のセキュリティ認証例外を処理する
私は春のMVCのを使用しています@ControllerAdviceし、@ExceptionHandlerREST APIをすべての例外を処理します。これは、Web MVCコントローラーによってスローされた例外に対しては正常に機能しますが、コントローラーメソッドが呼び出される前に実行されるため、Spring Securityカスタムフィルターによってスローされた例外に対しては機能しません。 トークンベースの認証を行うカスタムSpring Securityフィルターがあります。 public class AegisAuthenticationFilter extends GenericFilterBean { ... public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { try { ... } catch(AuthenticationException authenticationException) { SecurityContextHolder.clearContext(); authenticationEntryPoint.commence(request, response, authenticationException); } } } このカスタムエントリポイントの場合: @Component("restAuthenticationEntryPoint") public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint{ public void commence(HttpServletRequest request, …