I have custom security filter which serves as additional authorization step.
The filter checks if a user can be authorized and throws an exception if the user is not supposed to access the resource.
The problem is that if I throw an exception from the filter - it doesn't get mapped to correct status code (in my case I need HTTP 403).
I can't use @ControllerAdvice
and @ExceptionHandler
because security filters work before controller handling.
I thought may be I'm doing it wrong and I shouldn't throw an exception, or I should throw a very specific one.
Q: Is there any way to automatically map exceptions from filters to proper status codes? Or is there a way to implement the filter without exceptions?
Note: I also read this post, but from debug I see that my filter chain doesn't contain ExceptionTranslationFilter
.