Class DefaultJWSMinter<C extends SecurityContext>

    • Constructor Detail

      • DefaultJWSMinter

        public DefaultJWSMinter()
    • Method Detail

      • mint

        public JWSObject mint​(JWSHeader header,
                              Payload payload,
                              C context)
                       throws JOSEException
        Creates a new JSON Web Signature (JWS) object using the provided JWSHeader and Payload. To create a signed JSON Web Token (JWT) use the JWTClaimsSet.toPayload() method to obtain a Payload representation of the JWT claims.

        Derives the signing key from the JWSHeader as well as any application-specific context.

        If multiple keys are matched against the header's criteria, the first will be used to sign the object. To customise the key selection you can set a custom JWKSource like so:

         public static class MyJWKSource implements JWKSource<SecurityContext> {
             private final JWKSource<SecurityContext> delegate;
        
             public List<JWK> get(final JWKSelector jwkSelector, final SecurityContext context)
                 throws KeySourceException {
                 List<JWK> jwks = this.delegate.get(jwkSelector, context);
                 return jwks.get(jwks.size() - 1); // get last one instead
             }
         }
        
         minter.setJWKSource(new MyJWKSource(jwkSource));
         

        or you can select your own JWK and do:

         JWK jwk = findJWK();
         minter.mint(header, claims, new JWKSecurityContext(jwks));
         

        Once the key is discovered, adds any headers related to the discovered signing key, including kid, x5u, x5c, and x5t#256.

        All other headers and claims remain as-is. This method expects the caller to add the typ, alg, and any other needed headers.

        Specified by:
        mint in interface JWSMinter<C extends SecurityContext>
        Parameters:
        header - The JWSHeader to use, less any key-identifying headers, which this method will derive.
        payload - The Payload.
        context - A SecurityContext, null if not specified.
        Returns:
        The signed JWS object.
        Throws:
        JOSEException - If the instance is improperly configured, if no appropriate JWK could be found, or if signing failed.