Class HttpHeaderTokenPropagator

java.lang.Object
io.micronaut.security.token.propagation.HttpHeaderTokenPropagator
All Implemented Interfaces:
io.micronaut.core.order.Ordered, TokenPropagator

@Requires(property="micronaut.security.token.propagation.header.enabled",notEquals="false") @Requires(classes=io.micronaut.http.HttpRequest.class) @Singleton public class HttpHeaderTokenPropagator extends Object implements TokenPropagator
Propagates a token based off of a header.
Since:
1.4.0
Author:
James Kleeh
  • Field Details

  • Constructor Details

  • Method Details

    • writeToken

      public void writeToken(io.micronaut.http.MutableHttpRequest<?> request, String token)
      Writes the token to the request.
      Specified by:
      writeToken in interface TokenPropagator
      Parameters:
      request - The MutableHttpRequest instance
      token - A token ( e.g. JWT token, basic auth token...)
    • findToken

      public Optional<String> findToken(io.micronaut.http.HttpRequest<?> request)
      Search for a JWT token in a HTTP request.
      Specified by:
      findToken in interface TokenPropagator
      Parameters:
      request - The request to look for the token in
      Returns:
      if the JWT token is found it is returned, empty if not
    • headerValue

      protected String headerValue(String token)
      Parameters:
      token - the token being written
      Returns:
      the value which will be written to an HTTP Header
    • extractTokenFromAuthorization

      protected Optional<String> extractTokenFromAuthorization(String authorization)
      Parameters:
      authorization - Authorization header value
      Returns:
      If prefix is 'Bearer' for 'Bearer XXX' it returns 'XXX'
    • getConfiguration

      public HttpHeaderTokenPropagatorConfiguration getConfiguration()
      Returns:
      The HttpHeaderTokenPropagator Configuration