Class SignJWTHandler

All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, MessageHandler

public class SignJWTHandler extends AbstractMessageHandler
Message handler that signs a JWT and sets it back to the message context via an update consumer.
  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Class logger.
    • securityParametersLookupStrategy

      @Nonnull private Function<MessageContext,SecurityParametersContext> securityParametersLookupStrategy
      Strategy used to locate the SecurityParametersContext to use for signing.
    • jwtUpdateConsumer

      @NonnullAfterInit private BiConsumer<com.nimbusds.jwt.JWT,MessageContext> jwtUpdateConsumer
      A consumer that takes the Signed JWT and updates the correct object inside the MessageContext.
    • claimsToSignLookupStrategy

      @NonnullAfterInit private Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet> claimsToSignLookupStrategy
      Strategy used to locate the payload to encrypt.
    • signatureSigningParameters

      @Nonnull private SignatureSigningParameters signatureSigningParameters
      The signature signing parameters.
    • credential

      @Nullable private Credential credential
      resolved credential.
    • jwtClaimSetToSign

      @Nullable private com.nimbusds.jwt.JWTClaimsSet jwtClaimSetToSign
      The claims to sign.
    • typeHeader

      @Nullable @NotEmpty private String typeHeader
      "typ" header to insert while signing.
    • logName

      @Nonnull @NotEmpty private String logName
      A friendly name to log as the subject of signing.
  • Constructor Details

    • SignJWTHandler

      public SignJWTHandler()
      Constructor.
  • Method Details

    • setLogName

      public void setLogName(@Nonnull @NotEmpty String name)
      Set the friendly name to log as the subject of signing.
      Parameters:
      name - the friendly name
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractInitializableComponent
      Throws:
      ComponentInitializationException
    • setClaimsToSignLookupStrategy

      public void setClaimsToSignLookupStrategy(@Nonnull Function<MessageContext,com.nimbusds.jwt.JWTClaimsSet> strategy)
      Set the strategy used to locate the JWTClaimsSet to sign.
      Parameters:
      strategy - the strategy
    • setJwtUpdateConsumer

      public void setJwtUpdateConsumer(BiConsumer<com.nimbusds.jwt.JWT,MessageContext> consumer)
      Set the consumer used to update the MessageContext with the supplied EncryptedJWT.
      Parameters:
      consumer - the consumer
    • setTypeHeader

      public void setTypeHeader(@Nullable @NotEmpty String type)
      Sets the value to be inserted as a "typ" header for the JWS.
      Parameters:
      type - header value
    • setSecurityParametersLookupStrategy

      public void setSecurityParametersLookupStrategy(@Nonnull Function<MessageContext,SecurityParametersContext> strategy)
      Set the strategy used to locate the SecurityParametersContext to use.
      Parameters:
      strategy - lookup strategy
    • doPreInvoke

      protected boolean doPreInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
      Overrides:
      doPreInvoke in class AbstractMessageHandler
      Throws:
      MessageHandlerException
    • doInvoke

      protected void doInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
      Specified by:
      doInvoke in class AbstractMessageHandler
      Throws:
      MessageHandlerException
    • getSigner

      private com.nimbusds.jose.JWSSigner getSigner(com.nimbusds.jose.Algorithm jwsAlgorithm) throws com.nimbusds.jose.JOSEException
      Returns correct implementation of signer based on algorithm type.
      Parameters:
      jwsAlgorithm - JWS algorithm
      Returns:
      signer for algorithm and private key
      Throws:
      com.nimbusds.jose.JOSEException - if algorithm cannot be supported
    • resolveAlgorithm

      protected com.nimbusds.jose.JWSAlgorithm resolveAlgorithm()
      Resolves JWS algorithm from signature signing parameters.
      Returns:
      JWS algorithm