Class HttpHeaderTokenReader

java.lang.Object
io.micronaut.security.token.reader.HttpHeaderTokenReader
All Implemented Interfaces:
io.micronaut.core.order.Ordered, TokenReader<io.micronaut.http.HttpRequest<?>>
Direct Known Subclasses:
BearerTokenReader

public abstract class HttpHeaderTokenReader extends Object implements TokenReader<io.micronaut.http.HttpRequest<?>>
Reads a token from an HTTP request and removes prefix from HTTP Header Value.
Since:
1.0
Author:
Sergio del Amo
  • Constructor Details

    • HttpHeaderTokenReader

      public HttpHeaderTokenReader()
  • Method Details

    • getPrefix

      protected abstract String getPrefix()
      Returns:
      a Prefix before the token in the header value. E.g. Basic
    • getHeaderName

      protected abstract String getHeaderName()
      Returns:
      an HTTP Header name. e.g. Authorization
    • findToken

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

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