Announcement Announcement Module
Collapse
No announcement yet.
@ExceptionHandler and AuthenticationExceptions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ExceptionHandler and AuthenticationExceptions

    Hi,

    I have an MVC controller with a @PreAuthorize annotation. If the authorization fail for whatever reason, I'd like to return a particular view. I was thinking of using an @ExceptionHandler(AuthenticationException.class) which returns the view name. But that doesn't work, I'm guessing because the @PreAuthorize proxy is upstream of the @ExceptionHandler proxy.

    Any suggestions on how to achieve my use case without hand-coding SecurityContextHolder checks within the handler method?

    Thanks,
    Emerson

  • #2
    You could plug an AuthenticationFailureHandler into your AuthenticationFilter. We have ExceptionMappingAuthenticationFailureHandler in place and have it redirect to different URL depending on the particular Exception that was raised.

    Comment

    Working...
    X