Results 1 to 2 of 2

Thread: @ExceptionHandler and AuthenticationExceptions

  1. #1
    Join Date
    Jul 2007
    Posts
    27

    Default @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. #2
    Join Date
    Jan 2010
    Posts
    6

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •