Class DefaultAuthorizationExceptionHandler

java.lang.Object
io.micronaut.security.authentication.DefaultAuthorizationExceptionHandler
All Implemented Interfaces:
io.micronaut.http.server.exceptions.ExceptionHandler<AuthorizationException,io.micronaut.http.MutableHttpResponse<?>>

@Requires(classes=io.micronaut.http.server.exceptions.ExceptionHandler.class) @Singleton public class DefaultAuthorizationExceptionHandler extends Object implements io.micronaut.http.server.exceptions.ExceptionHandler<AuthorizationException,io.micronaut.http.MutableHttpResponse<?>>
Provides the default behavior for responding to an AuthorizationException.
Since:
1.4.0
Author:
James Kleeh
  • Constructor Details

    • DefaultAuthorizationExceptionHandler

      public DefaultAuthorizationExceptionHandler(io.micronaut.http.server.exceptions.response.ErrorResponseProcessor<?> errorResponseProcessor, RedirectConfiguration redirectConfiguration, RedirectService redirectService, @Nullable @Nullable PriorToLoginPersistence priorToLoginPersistence)
      Parameters:
      errorResponseProcessor - ErrorResponse processor API
      redirectConfiguration - Redirect configuration
      redirectService - Redirection Service
      priorToLoginPersistence - Persistence mechanism to redirect to prior login url
  • Method Details

    • handle

      public io.micronaut.http.MutableHttpResponse<?> handle(io.micronaut.http.HttpRequest request, AuthorizationException exception)
      Specified by:
      handle in interface io.micronaut.http.server.exceptions.ExceptionHandler<AuthorizationException,io.micronaut.http.MutableHttpResponse<?>>
    • httpResponseWithStatus

      protected io.micronaut.http.MutableHttpResponse<?> httpResponseWithStatus(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception)
      Parameters:
      request - The request
      exception - The exception
      Returns:
      The response to be used when a redirect is not appropriate
    • shouldRedirect

      protected boolean shouldRedirect(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception)
      Decides whether the request should be handled with a redirect.
      Parameters:
      request - The HTTP Request
      exception - The authorization exception
      Returns:
      true if the request accepts text/html
    • getRedirectUri

      protected String getRedirectUri(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception)
      Parameters:
      request - The request
      exception - The exception
      Returns:
      The URI to redirect to
    • httpResponseWithStatus

      protected io.micronaut.http.MutableHttpResponse<?> httpResponseWithStatus(URI location)
      Builds a HTTP Response redirection to the supplied location.
      Parameters:
      location - The Uri to redirect to
      Returns:
      an HTTP response with the Uri as location