Class JwkSet

java.lang.Object
com.codename1.backend.security.crypto.JwkSet
All Implemented Interfaces:
JwkSource

public final class JwkSet extends Object implements JwkSource

A set of keys, as a JSON Web Key Set publishes one (RFC 7517 5): what a server that signs tokens serves at its jwks_uri, and what a server that verifies them reads from there.

JwkSet keys = JwkSet.of(current, previous);
return HttpServer.Response.json(200, keys.toJson());   // public halves only

The set does not change. A server that rotates its key builds a new set and answers with it from its JwkSource.

  • Constructor Details

    • JwkSet

      public JwkSet(List<Jwk> keys)
  • Method Details

    • of

      public static JwkSet of(Jwk... keys)
      A set of these keys, the one to sign with first.
    • parse

      public static JwkSet parse(String json) throws IOException

      The public keys in a JSON Web Key Set document.

      A key this runtime has no use for -- a type or a curve it does not verify with, an encryption key -- is left out rather than failing the set: a provider adding a key of a new kind must not stop the ones that were working.

      Throws:
      IOException - when the text is not a key set at all
    • getKeys

      public List<Jwk> getKeys()
      Description copied from interface: JwkSource
      The keys, the one to sign with first.
      Specified by:
      getKeys in interface JwkSource
    • get

      public Jwk get(String keyId)
      The key with this id, or null.
    • toPublicJson

      public Map<String,Object> toPublicJson()
      The set as a jwks_uri serves it: the public half of every RSA and EC key. A shared secret is left out.
    • toJson

      public String toJson()
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object