Class JWSTokenSigner

java.lang.Object
net.shibboleth.oidc.security.impl.JWSTokenSigner

public class JWSTokenSigner extends Object
Supports signing a JSON Web Token (JWT) claims set using the JSON Web Signature standard using the algorithm and credential contained inside the SignatureSigningParameters. Any error that occurs signing the JWT will throw an SignatureException.

A signer will need to be created for each new signing operation.

Since:
3.1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.slf4j.Logger
    Class logger.
    The signature signing parameters.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.nimbusds.jose.JWSSigner
    getSigner(com.nimbusds.jose.Algorithm jwsAlgorithm, Credential credential)
    Returns the correct implementation of the JWSSigner based on the algorithm type and credential given.
    protected com.nimbusds.jose.JWSAlgorithm
    resolveAlgorithm(Credential credential, String algorithmString)
    Resolves JWS algorithm from signature signing parameters.
    com.nimbusds.jwt.SignedJWT
    sign(com.nimbusds.jwt.JWTClaimsSet jwtClaims, String typeHeader)
    Sign the given JWT claims set using the signing parameters.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

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

      @Nonnull private final SignatureSigningParameters params
      The signature signing parameters.
  • Constructor Details

    • JWSTokenSigner

      public JWSTokenSigner(@Nonnull SignatureSigningParameters signingParams)
      Constructor.
      Parameters:
      signingParams - the algorithm and credential to use during signing
  • Method Details

    • sign

      @Nonnull public com.nimbusds.jwt.SignedJWT sign(@Nonnull com.nimbusds.jwt.JWTClaimsSet jwtClaims, @Nullable String typeHeader) throws SignatureException
      Sign the given JWT claims set using the signing parameters.
      Parameters:
      jwtClaims - the claims to sign
      typeHeader - the optional JOSE object type to add to the JWS JOSE header
      Returns:
      a signed JWT or null if an error occurs
      Throws:
      SignatureException - if an error occurs
    • getSigner

      @Nonnull protected com.nimbusds.jose.JWSSigner getSigner(@Nonnull com.nimbusds.jose.Algorithm jwsAlgorithm, @Nonnull Credential credential) throws com.nimbusds.jose.JOSEException
      Returns the correct implementation of the JWSSigner based on the algorithm type and credential given.
      Parameters:
      jwsAlgorithm - the JWS algorithm
      credential - the credential
      Returns:
      signer for the given algorithm and credential
      Throws:
      com.nimbusds.jose.JOSEException - if algorithm and credential combinations is not supported
    • resolveAlgorithm

      @Nonnull protected com.nimbusds.jose.JWSAlgorithm resolveAlgorithm(@Nonnull Credential credential, @Nonnull String algorithmString)
      Resolves JWS algorithm from signature signing parameters. Warns if an unsuitable credential and algorithm are found, but the algorithm is still returned.
      Parameters:
      credential - the credential used to sign the JWT claims
      algorithmString - the JWS algorithm as a string
      Returns:
      JWS algorithm