Class JwtBundle
java.lang.Object
io.spiffe.bundle.jwtbundle.JwtBundle
- All Implemented Interfaces:
BundleSource<JwtBundle>
Represents a collection of trusted JWT authorities (Public Keys) for a trust domain.
-
Constructor Summary
ConstructorsConstructorDescriptionJwtBundle(@NonNull TrustDomain trustDomain) Creates a new JWT bundle for a trust domain.JwtBundle(@NonNull TrustDomain trustDomain, @NonNull Map<String, PublicKey> jwtAuthorities) Creates a new JWT bundle for a trust domain with JWT Authorities (public keys associated to keyIds). -
Method Summary
Modifier and TypeMethodDescriptionfindJwtAuthority(String keyId) Finds the JWT key with the given key id from the bundle.getBundleForTrustDomain(TrustDomain trustDomain) Returns the JWT bundle for a trust domain.Returns the JWT authorities in the bundle, keyed by key ID.booleanhasJwtAuthority(String keyId) Looks for a JWT authority id in the JWT bundle.static JwtBundleload(@NonNull TrustDomain trustDomain, @NonNull Path bundlePath) Loads a JWT bundle from a file on disk.static JwtBundleparse(@NonNull TrustDomain trustDomain, @NonNull byte[] bundleBytes) Parses a JWT bundle from a byte array.voidputJwtAuthority(@NonNull String keyId, @NonNull PublicKey jwtAuthority) Adds a JWT authority to the bundle.voidremoveJwtAuthority(String keyId) Removes the JWT authority identified by the key ID from the bundle.
-
Constructor Details
-
JwtBundle
Creates a new JWT bundle for a trust domain.- Parameters:
trustDomain- aTrustDomainto associate to the JwtBundle
-
JwtBundle
public JwtBundle(@NonNull @NonNull TrustDomain trustDomain, @NonNull @NonNull Map<String, PublicKey> jwtAuthorities) Creates a new JWT bundle for a trust domain with JWT Authorities (public keys associated to keyIds).- Parameters:
trustDomain- aTrustDomainto associate to the JwtBundlejwtAuthorities- a Map of public Keys
-
-
Method Details
-
load
public static JwtBundle load(@NonNull @NonNull TrustDomain trustDomain, @NonNull @NonNull Path bundlePath) throws KeyException, JwtBundleException Loads a JWT bundle from a file on disk. The file must contain a standard RFC 7517 JWKS document.Key Types supported are EC and RSA.
- Parameters:
trustDomain- aTrustDomainto associate to the JWT bundle.bundlePath- a path to a file containing the JWT authorities (public keys).- Returns:
- an instance of a
JwtBundle - Throws:
JwtBundleException- if there is an error reading or parsing the file, or if a keyId is emptyKeyException- if the bundle file contains a key type that is not supported
-
parse
public static JwtBundle parse(@NonNull @NonNull TrustDomain trustDomain, @NonNull @NonNull byte[] bundleBytes) throws JwtBundleException Parses a JWT bundle from a byte array.- Parameters:
trustDomain- aTrustDomainbundleBytes- an array of bytes representing the JWT bundle.- Returns:
- an instance of a
JwtBundle - Throws:
JwtBundleException- if there is an error reading or parsing the file, or if a keyId is empty
-
getBundleForTrustDomain
Returns the JWT bundle for a trust domain.- Specified by:
getBundleForTrustDomainin interfaceBundleSource<JwtBundle>- Parameters:
trustDomain- aTrustDomain- Returns:
- a
JwtBundlefor the trust domain - Throws:
BundleNotFoundException- if there is no bundle for the given trust domain
-
getJwtAuthorities
-
findJwtAuthority
Finds the JWT key with the given key id from the bundle.- Parameters:
keyId- the Key ID- Returns:
PublicKeyrepresenting the Authority associated to the KeyID.- Throws:
AuthorityNotFoundException- if no Authority is found associated to the Key ID
-
hasJwtAuthority
Looks for a JWT authority id in the JWT bundle.- Parameters:
keyId- id of a JWT Authority- Returns:
- true if the bundle has a JWT authority with the given key ID.
-
putJwtAuthority
public void putJwtAuthority(@NonNull @NonNull String keyId, @NonNull @NonNull PublicKey jwtAuthority) Adds a JWT authority to the bundle. If a JWT authority already exists under the given key ID, it is replaced. A key ID must be specified.- Parameters:
keyId- Key ID to associate to the jwtAuthorityjwtAuthority- a PublicKey
-
removeJwtAuthority
Removes the JWT authority identified by the key ID from the bundle.- Parameters:
keyId- The key id of the JWT authority to be removed
-