Package com.nimbusds.jose.jwk
Class JWKMatcher
java.lang.Object
com.nimbusds.jose.jwk.JWKMatcher
JSON Web Key (JWK) matcher. May be used to ensure a JWK matches a set of
application-specific criteria.
Supported key matching criteria:
- Any, unspecified, one or more key types (typ).
- Any, unspecified, one or more key uses (use).
- Any, unspecified, one or more key operations (key_ops).
- Any, unspecified, one or more key algorithms (alg).
- Any, unspecified, one or more key identifiers (kid).
- Private only key.
- Public only key.
- Minimum, maximum or exact key sizes.
- Any, unspecified, one or more curves for EC and OKP keys (crv).
- X.509 certificate SHA-256 thumbprint.
- Has X.509 certificate.
Matching by JWK thumbprint (RFC 7638), X.509 certificate URL and X.509 certificate chain is not supported.
- Version:
- 2022-05-28
- Author:
- Vladimir Dzhuvinov, Josh Cummings, Ben Arena
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing JWK matchers. -
Constructor Summary
ConstructorsConstructorDescriptionJWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly) Deprecated.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves) Deprecated.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves, Set<Base64URL> x5tS256s) Deprecated.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves, Set<Base64URL> x5tS256s, boolean hasX5C) Creates a new JSON Web Key (JWK) matcher.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits) Deprecated.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Curve> curves) Deprecated.JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic JWKMatcherforJWEHeader(JWEHeader jweHeader) Returns aJWKMatcherbased on the givenJWEHeader.static JWKMatcherforJWSHeader(JWSHeader jwsHeader) Returns aJWKMatcherbased on the givenJWSHeader.Returns the JOSE algorithms to match.Returns the curves to match (for EC and OKP keys).Returns the key IDs to match.Returns the key operations to match.Returns the key sizes.Returns the key types to match.Returns the public key uses to match.intReturns the maximum key size.intDeprecated.intReturns the minimum key size.intDeprecated.Returns the X.509 certificate SHA-256 thumbprints to match.booleanhasKeyID()Returnstrueif keys with a set use are matched.booleanReturnstrueif keys with a set use are matched.booleanReturnstrueif keys with a set X.509 certificate chain are matched.booleanReturnstrueif only private keys are matched.booleanReturnstrueif only public keys are matched.booleanReturnstrueif the specified JWK matches.toString()
-
Constructor Details
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Curve> curves) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.curves- The curves to match (for EC keys),nullif not specified.
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.sizesBits- The key sizes in bits,nullif not specified.curves- The curves to match (for EC and OKP keys),nullif not specified.
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.hasUse-trueto match a key with a set use.hasID-trueto match a key with a set ID.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.sizesBits- The key sizes in bits,nullif not specified.curves- The curves to match (for EC and OKP keys),nullif not specified.
-
JWKMatcher
@Deprecated public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves, Set<Base64URL> x5tS256s) Deprecated.Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.hasUse-trueto match a key with a set use.hasID-trueto match a key with a set ID.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.sizesBits- The key sizes in bits,nullif not specified.curves- The curves to match (for EC and OKP keys),nullif not specified.x5tS256s- The X.509 certificate thumbprints to match,nullif not specified.
-
JWKMatcher
public JWKMatcher(Set<KeyType> types, Set<KeyUse> uses, Set<KeyOperation> ops, Set<Algorithm> algs, Set<String> ids, boolean hasUse, boolean hasID, boolean privateOnly, boolean publicOnly, int minSizeBits, int maxSizeBits, Set<Integer> sizesBits, Set<Curve> curves, Set<Base64URL> x5tS256s, boolean hasX5C) Creates a new JSON Web Key (JWK) matcher.- Parameters:
types- The key types to match,nullif not specified.uses- The public key uses to match,nullif not specified.ops- The key operations to match,nullif not specified.algs- The JOSE algorithms to match,nullif not specified.ids- The key IDs to match,nullif not specified.hasUse-trueto match a key with a set use.hasID-trueto match a key with a set ID.privateOnly-trueto match a private key.publicOnly-trueto match a public only key.minSizeBits- The minimum key size in bits, zero implies no minimum size limit.maxSizeBits- The maximum key size in bits, zero implies no maximum size limit.sizesBits- The key sizes in bits,nullif not specified.curves- The curves to match (for EC and OKP keys),nullif not specified.x5tS256s- The X.509 certificate thumbprints to match,nullif not specified.hasX5C-trueto match a key with a set X.509 certificate chain.
-
-
Method Details
-
forJWEHeader
Returns aJWKMatcherbased on the givenJWEHeader.The
JWKMatcheris configured as follows:- The key type to match is determined by the JWE algorithm (alg).
- The key ID to match is set by the JWE header key ID (kid) parameter (if set).
- The key uses to match are set to encryption or not specified.
- The key algorithm to match is set to the JWE algorithm (alg) or not specified.
Other JWE header parameters are not taken into account.
- Parameters:
jweHeader- The header to use.- Returns:
- A
JWKMatcherbased on the given header.
-
forJWSHeader
Returns aJWKMatcherbased on the givenJWSHeader.The
JWKMatcheris configured as follows:- The key type to match is determined by the JWS algorithm (alg).
- The key ID to match is set by the JWS header key ID (kid) parameter (if set).
- The key uses to match are set to signature or not specified.
- The key algorithm to match is set to the JWS algorithm (alg) or not specified.
- The X.509 certificate SHA-256 thumbprint to match is set to the x5t#S256 parameter (if set).
Other JWS header parameters are not taken into account.
- Parameters:
jwsHeader- The header to use.- Returns:
- A
JWKMatcherbased on the given header,nullif the JWS algorithm is not supported.
-
getKeyTypes
Returns the key types to match.- Returns:
- The key types,
nullif not specified.
-
getKeyUses
Returns the public key uses to match.- Returns:
- The public key uses,
nullif not specified.
-
getKeyOperations
Returns the key operations to match.- Returns:
- The key operations,
nullif not specified.
-
getAlgorithms
Returns the JOSE algorithms to match.- Returns:
- The JOSE algorithms,
nullif not specified.
-
getKeyIDs
Returns the key IDs to match.- Returns:
- The key IDs,
nullif not specified.
-
hasKeyUse
Returnstrueif keys with a set use are matched.- Returns:
trueif keys with a set use are matched, elsefalse.
-
hasKeyID
Returnstrueif keys with a set use are matched.- Returns:
trueif keys with a set ID are matched, elsefalse.
-
isPrivateOnly
Returnstrueif only private keys are matched.- Returns:
trueif only private keys are matched, elsefalse.
-
isPublicOnly
Returnstrueif only public keys are matched.- Returns:
trueif only public keys are selected, elsefalse.
-
getMinSize
Deprecated.Returns the minimum key size. UsegetMinKeySize()instead.- Returns:
- The minimum key size in bits, zero implies no minimum size limit.
-
getMinKeySize
Returns the minimum key size.- Returns:
- The minimum key size in bits, zero implies no minimum size limit.
-
getMaxSize
Deprecated.Returns the maximum key size. UsegetMaxKeySize()instead.- Returns:
- The maximum key size in bits, zero implies no maximum size limit.
-
getMaxKeySize
Returns the maximum key size.- Returns:
- The maximum key size in bits, zero implies no maximum size limit.
-
getKeySizes
Returns the key sizes.- Returns:
- The key sizes in bits,
nullif not specified.
-
getCurves
Returns the curves to match (for EC and OKP keys).- Returns:
- The curves,
nullif not specified.
-
getX509CertSHA256Thumbprints
Returns the X.509 certificate SHA-256 thumbprints to match.- Returns:
- The thumbprints,
nullif not specified.
-
hasX509CertChain
Returnstrueif keys with a set X.509 certificate chain are matched.- Returns:
trueif keys with a set X.509 certificate are matched, elsefalse.
-
matches
Returnstrueif the specified JWK matches.- Parameters:
key- The JSON Web Key (JWK). Must not benull.- Returns:
trueif the JWK matches, elsefalse.
-
toString
-