Class JwtHeaders.Builder

java.lang.Object
io.helidon.security.jwt.JwtHeaders.Builder
All Implemented Interfaces:
Builder<JwtHeaders.Builder,JwtHeaders>, Supplier<JwtHeaders>
Enclosing class:
JwtHeaders

public static class JwtHeaders.Builder extends Object implements Builder<JwtHeaders.Builder,JwtHeaders>
Fluent API builder to create JWT Header.
  • Method Details

    • build

      public JwtHeaders build()
      Description copied from interface: Builder
      Build the instance from this builder.
      Specified by:
      build in interface Builder<JwtHeaders.Builder,JwtHeaders>
      Returns:
      instance of the built type
    • addHeaderClaim

      public JwtHeaders.Builder addHeaderClaim(String claim, Object value)
      Add a header claim.
      Parameters:
      claim - name of the claim
      value - claim value, must be of expected type
      Returns:
      updated builder
      Throws:
      IllegalArgumentException - if a known header (such as iss, aud) is set to a non-string type
    • algorithm

      public JwtHeaders.Builder algorithm(String algorithm)
      The "alg" claim is used to define the signature algorithm. Note that this algorithm should be the same as is supported by the JWK used to sign (or verify) the JWT.
      Parameters:
      algorithm - algorithm to use, Jwk.ALG_NONE for none
      Returns:
      updated builder instance
    • encryption

      public JwtHeaders.Builder encryption(String encryption)
      Encryption algorithm to use.
      Parameters:
      encryption - encryption to use
      Returns:
      updated builder
    • contentType

      public JwtHeaders.Builder contentType(String contentType)
      This header claim should only be used when nesting or encrypting JWT. See RFC 7519, section 5.2.
      Parameters:
      contentType - content type to use, use "JWT" if nested
      Returns:
      updated builder instance
    • keyId

      public JwtHeaders.Builder keyId(String keyId)
      Key id to be used to sign/verify this JWT.
      Parameters:
      keyId - key id (pointing to a JWK)
      Returns:
      updated builder instance
    • type

      public JwtHeaders.Builder type(String type)
      Type of this JWT.
      Parameters:
      type - type definition (JWT, JWE)
      Returns:
      updated builder instance
    • headerSubject

      public JwtHeaders.Builder headerSubject(String subject)
      Subject defines the principal this JWT was issued for (e.g. user id). This configures subject in header claims (usually it is part of payload). See RFC 7519, section 4.1.2.
      Parameters:
      subject - subject of this JWt
      Returns:
      updated builder instance
    • headerIssuer

      public JwtHeaders.Builder headerIssuer(String issuer)
      The issuer claim identifies the principal that issued the JWT. This configures issuer in header claims (usually it is part of payload). See RFC 7519, section 4.1.1.
      Parameters:
      issuer - issuer name or URL
      Returns:
      updated builder instance
    • addHeaderCritical

      public JwtHeaders.Builder addHeaderCritical(String critical)
      The critical claim is used to indicate that certain claims are critical and must be understood (optional). If a recipient does not understand or support any of the critical claims, it must reject the token. Multiple critical claims may be added. This configures critical claims in header claims. See RFC 7519, section 4.1.1.
      Parameters:
      critical - required critical claim to understand
      Returns:
      updated builder instance
    • addHeaderAudience

      public JwtHeaders.Builder addHeaderAudience(String audience)
      Audience identifies the expected recipients of this JWT (optional). Multiple audience may be added. This configures audience in header claims, usually this is defined in payload. See RFC 7515, section 4.1.11.
      Parameters:
      audience - audience of this JWT
      Returns:
      updated builder instance
      See Also:
    • headerAudience

      public JwtHeaders.Builder headerAudience(List<String> audience)
      Audience identifies the expected recipients of this JWT (optional). Replaces existing configured audiences. This configures audience in header claims, usually this is defined in payload. See RFC 7519, section 4.1.3.
      Parameters:
      audience - audience of this JWT
      Returns:
      updated builder instance
    • headerCritical

      public JwtHeaders.Builder headerCritical(List<String> critical)
      The critical claim is used to indicate that certain claims are critical and must be understood (optional). If a recipient does not understand or support any of the critical claims, it must reject the token. Replaces existing configured critical claims. This configures critical claims in header claims. See RFC 7515, section 4.1.11.
      Parameters:
      critical - required critical claims to understand
      Returns:
      updated builder instance