Class TokenAuthenticationFetcher
java.lang.Object
io.micronaut.security.token.TokenAuthenticationFetcher
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, AuthenticationFetcher<io.micronaut.http.HttpRequest<?>>
@Requires(classes=io.micronaut.http.HttpRequest.class) @Requires(beans=io.micronaut.http.server.util.HttpHostResolver.class)
@Singleton
public class TokenAuthenticationFetcher
extends Object
implements AuthenticationFetcher<io.micronaut.http.HttpRequest<?>>
Attempts to retrieve a token form the
HttpRequest and if existing validated.
It uses a TokenResolver and the list of TokenValidator registered in the ApplicationContext.
Token validators are consulted sequentially in order. The first validator which authenticates the token wins and the token is not handed to the remaining validators. Validators which perform remote calls, such as the OpenID provider UserInfo endpoint validator, should therefore have the lowest precedence so that they only receive tokens no local validator accepted.
- Since:
- 1.0
- Author:
- Sergio del Amo, Graeme Rocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.micronaut.http.server.util.HttpHostResolverprotected final io.micronaut.http.server.util.locale.HttpLocaleResolverstatic final IntegerThe order of the fetcher.protected final io.micronaut.context.event.ApplicationEventPublisher<TokenValidatedEvent> protected final Collection<TokenValidator<io.micronaut.http.HttpRequest<?>>> Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionTokenAuthenticationFetcher(List<TokenValidator<io.micronaut.http.HttpRequest<?>>> tokenValidators, TokenResolver<io.micronaut.http.HttpRequest<?>> tokenResolver, io.micronaut.context.event.ApplicationEventPublisher<TokenValidatedEvent> tokenValidatedEventPublisher, io.micronaut.http.server.util.HttpHostResolver httpHostResolver, io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver) -
Method Summary
Modifier and TypeMethodDescriptionorg.reactivestreams.Publisher<Authentication> fetchAuthentication(io.micronaut.http.HttpRequest<?> request) Attempts to read anAuthenticationfrom an HTTP Request being executed.intgetOrder()
-
Field Details
-
ORDER
The order of the fetcher. -
tokenValidators
-
httpHostResolver
protected final io.micronaut.http.server.util.HttpHostResolver httpHostResolver -
httpLocaleResolver
protected final io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver -
tokenValidatedEventPublisher
protected final io.micronaut.context.event.ApplicationEventPublisher<TokenValidatedEvent> tokenValidatedEventPublisher
-
-
Constructor Details
-
TokenAuthenticationFetcher
public TokenAuthenticationFetcher(List<TokenValidator<io.micronaut.http.HttpRequest<?>>> tokenValidators, TokenResolver<io.micronaut.http.HttpRequest<?>> tokenResolver, io.micronaut.context.event.ApplicationEventPublisher<TokenValidatedEvent> tokenValidatedEventPublisher, io.micronaut.http.server.util.HttpHostResolver httpHostResolver, io.micronaut.http.server.util.locale.HttpLocaleResolver httpLocaleResolver) - Parameters:
tokenValidators- The list ofTokenValidatorwhich attempt to validate the requesttokenResolver- TheTokenResolverwhich returns the first found token in the request.tokenValidatedEventPublisher- Application event publisher forTokenValidatedEvent.httpHostResolver- The http host resolverhttpLocaleResolver- The http locale resolver- Since:
- 4.7.0
-
-
Method Details
-
fetchAuthentication
public org.reactivestreams.Publisher<Authentication> fetchAuthentication(io.micronaut.http.HttpRequest<?> request) Description copied from interface:AuthenticationFetcherAttempts to read anAuthenticationfrom an HTTP Request being executed.- Specified by:
fetchAuthenticationin interfaceAuthenticationFetcher<io.micronaut.http.HttpRequest<?>>- Parameters:
request- an HTTP Request being executed.- Returns:
Authenticationif found
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered
-