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 Summary
ConstructorDescriptionDefaultAuthorizationExceptionHandler
(io.micronaut.http.server.exceptions.response.ErrorResponseProcessor<?> errorResponseProcessor, RedirectConfiguration redirectConfiguration, RedirectService redirectService, @Nullable PriorToLoginPersistence priorToLoginPersistence) -
Method Summary
Modifier and TypeMethodDescriptionprotected String
getRedirectUri
(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception) io.micronaut.http.MutableHttpResponse<?>
handle
(io.micronaut.http.HttpRequest request, AuthorizationException exception) protected io.micronaut.http.MutableHttpResponse<?>
httpResponseWithStatus
(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception) protected io.micronaut.http.MutableHttpResponse<?>
httpResponseWithStatus
(URI location) Builds a HTTP Response redirection to the supplied location.protected boolean
shouldRedirect
(io.micronaut.http.HttpRequest<?> request, AuthorizationException exception) Decides whether the request should be handled with a redirect.
-
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 APIredirectConfiguration
- Redirect configurationredirectService
- Redirection ServicepriorToLoginPersistence
- 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 interfaceio.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 requestexception
- 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 Requestexception
- 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 requestexception
- The exception- Returns:
- The URI to redirect to
-
httpResponseWithStatus
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
-