Class JwtHeaders

java.lang.Object
io.helidon.security.jwt.JwtHeaders

public class JwtHeaders extends Object
Representation of the header section of a JWT. This can be used to partially parse a token to understand what kind of processing should be done further, whether SignedJwt or EncryptedJwt.
See Also:
  • Method Details

    • builder

      public static JwtHeaders.Builder builder()
      Create a new builder for header claims.
      Returns:
      a new builder
    • parseToken

      public static JwtHeaders parseToken(String token)
      Parse a token to retrieve the JWT header. This method only cares about the first section of the token, and ignores the rest (even if not valid). Text before the first dot is considered to be base64 value of the header JSON.
      Parameters:
      token - token, expected to be JWT (encrypted or signed)
      Returns:
      header parsed from the token
      Throws:
      JwtException - in case the token is not valid
    • headerJson

      public JsonObject headerJson()
      Create a JSON header object.
      Returns:
      JsonObject for header
    • headerClaim

      public Optional<JsonValue> headerClaim(String claim)
      Get a claim by its name from header.
      Parameters:
      claim - name of a claim
      Returns:
      claim value if present
    • algorithm

      public Optional<String> algorithm()
      Algorithm claim.
      Returns:
      algorithm or empty if claim is not defined
    • encryption

      public Optional<String> encryption()
      Encryption algorithm claim.
      Returns:
      algorithm or empty if not encrypted
    • contentType

      public Optional<String> contentType()
      Content type claim.
      Returns:
      content type or empty if claim is not defined
    • keyId

      public Optional<String> keyId()
      Key id claim.
      Returns:
      key id or empty if claim is not defined
    • type

      public Optional<String> type()
      Type claim.
      Returns:
      type or empty if claim is not defined
    • subject

      public Optional<String> subject()
      Subject claim.
      Returns:
      subject or empty if claim is not defined
    • issuer

      public Optional<String> issuer()
      Issuer claim.
      Returns:
      Issuer or empty if claim is not defined
    • audience

      public Optional<List<String>> audience()
      Audience claim.
      Returns:
      audience or empty optional if claim is not defined; list would be empty if the audience claim is defined as an empty array
    • decode

      protected static String decode(String base64, Errors.Collector collector, String description)
    • parseJson

      protected static JsonObject parseJson(String jsonString, Errors.Collector collector, String base64, String description)