Package io.micronaut.security.handlers
Class RedirectRejectionHandler
- java.lang.Object
-
- io.micronaut.security.handlers.RedirectRejectionHandler
-
- All Implemented Interfaces:
RejectionHandler
@Singleton @Secondary @Replaces(HttpStatusCodeRejectionHandler.class) @Requires(beans={UnauthorizedRejectionUriProvider.class,ForbiddenRejectionUriProvider.class,RedirectRejectionHandlerConfiguration.class}) @Requires(property="micronaut.security.redirect.enabled",notEquals="false") public class RedirectRejectionHandler extends java.lang.Object implements RejectionHandler
If beansUnauthorizedRejectionUriProvider
andForbiddenRejectionUriProvider
exists provides aRejectionHandler
implementation which performs redirects. It can be used for session based authentication flows or Open ID flows.- Since:
- 1.0
- Author:
- Sergio del Amo
-
-
Constructor Summary
Constructors Constructor Description RedirectRejectionHandler(UnauthorizedRejectionUriProvider unauthorizedRejectionUriProvider, ForbiddenRejectionUriProvider forbiddenRejectionUriProvider, RedirectRejectionHandlerConfiguration redirectRejectionHandlerConfiguration)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.util.Optional<java.lang.String>
getRedirectUri(io.micronaut.http.HttpRequest<?> request, boolean forbidden)
Returns the redirection uri.protected io.micronaut.http.MutableHttpResponse<?>
httpResponseWithUri(java.lang.String uri)
Deprecated.UsehttpResponseWithUri(URI)
insteadprotected io.micronaut.http.MutableHttpResponse<?>
httpResponseWithUri(java.net.URI location)
Builds a HTTP Response redirection to the supplied location.protected io.micronaut.http.HttpStatus
redirectionHttpStatus()
org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>>
reject(io.micronaut.http.HttpRequest<?> request, boolean forbidden)
Handles rejection of a request.protected boolean
shouldHandleRequest(io.micronaut.http.HttpRequest<?> request)
Decides whether the request should be handled with a redirect.
-
-
-
Constructor Detail
-
RedirectRejectionHandler
public RedirectRejectionHandler(UnauthorizedRejectionUriProvider unauthorizedRejectionUriProvider, ForbiddenRejectionUriProvider forbiddenRejectionUriProvider, RedirectRejectionHandlerConfiguration redirectRejectionHandlerConfiguration)
Constructor.- Parameters:
unauthorizedRejectionUriProvider
- URI Provider to redirect to if unauthenticatedforbiddenRejectionUriProvider
- URI Provider to redirect to if authenticated but not enough authorization level.redirectRejectionHandlerConfiguration
- Redirect Rejection Handler Configuration
-
-
Method Detail
-
reject
public org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>> reject(io.micronaut.http.HttpRequest<?> request, boolean forbidden)
Handles rejection of a request.- Specified by:
reject
in interfaceRejectionHandler
- Parameters:
request
-HttpRequest
being processedforbidden
- if true indicates that although the user was authenticated he did not had the necessary access privileges.- Returns:
- A response publisher
-
shouldHandleRequest
protected boolean shouldHandleRequest(io.micronaut.http.HttpRequest<?> request)
Decides whether the request should be handled with a redirect.- Parameters:
request
- The HTTP Request- Returns:
- true if the request accepts text/html
-
httpResponseWithUri
@Deprecated protected io.micronaut.http.MutableHttpResponse<?> httpResponseWithUri(java.lang.String uri) throws java.net.URISyntaxException
Deprecated.UsehttpResponseWithUri(URI)
insteadBuilds a HTTP Response redirection to the supplied location.- Parameters:
uri
- The Uri to redirect to- Returns:
- a 303 HTTP response with the Uri as location
- Throws:
java.net.URISyntaxException
- if the supplied uri String cannot be used with URI.
-
httpResponseWithUri
protected io.micronaut.http.MutableHttpResponse<?> httpResponseWithUri(java.net.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
-
redirectionHttpStatus
protected io.micronaut.http.HttpStatus redirectionHttpStatus()
- Returns:
- return the Http status code which will be used for the redirection
-
getRedirectUri
protected java.util.Optional<java.lang.String> getRedirectUri(io.micronaut.http.HttpRequest<?> request, boolean forbidden)
Returns the redirection uri.- Parameters:
request
-HttpRequest
being processedforbidden
- if true indicates that although the user was authenticated he did not had the necessary access privileges.- Returns:
- the uri to redirect to
-
-