Class JwksSignature
- java.lang.Object
-
- io.micronaut.security.token.jwt.signature.jwks.JwksSignature
-
- All Implemented Interfaces:
JwksCache,SignatureConfiguration
@EachBean(JwksSignatureConfiguration.class) public class JwksSignature extends java.lang.Object implements JwksCache, SignatureConfiguration
Signature configuration which enables verification of remote JSON Web Key Set. A bean of this class is created for eachJwksSignatureConfiguration.- Since:
- 1.1.0
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_REFRESH_JWKS_ATTEMPTSDeprecated.
-
Constructor Summary
Constructors Constructor Description JwksSignature(JwksSignatureConfiguration jwksSignatureConfiguration, JwkValidator jwkValidator)Deprecated.JwksSignature(JwksSignatureConfiguration jwksSignatureConfiguration, JwkValidator jwkValidator, JwkSetFetcher<com.nimbusds.jose.jwk.JWKSet> jwkSetFetcher)JwksSignature(java.lang.String url, com.nimbusds.jose.jwk.KeyType keyType, JwkValidator jwkValidator)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Clears the JWK Set cache.com.nimbusds.jose.jwk.JWKSetgetJwkSet()Deprecated.JwkValidatorgetJwkValidator()Deprecated.java.util.Optional<java.util.List<java.lang.String>>getKeyIds()com.nimbusds.jose.jwk.KeyTypegetKeyType()Deprecated.intgetRefreshJwksAttempts()Deprecated.java.lang.StringgetUrl()Deprecated.booleanisExpired()booleanisPresent()protected com.nimbusds.jose.jwk.JWKSetloadJwkSet(java.lang.String url)Instantiates a JWKSet for a given url.protected java.util.List<com.nimbusds.jose.jwk.JWK>matches(com.nimbusds.jwt.SignedJWT jwt, com.nimbusds.jose.jwk.JWKSet jwkSet)Deprecated.protected java.util.List<com.nimbusds.jose.jwk.JWK>matches(com.nimbusds.jwt.SignedJWT jwt, com.nimbusds.jose.jwk.JWKSet jwkSet, int refreshKeysAttempts)Deprecated.Usematches(SignedJWT, JWKSet)insteadjava.lang.StringsupportedAlgorithmsMessage()booleansupports(com.nimbusds.jose.JWSAlgorithm algorithm)Whether this signature configuration supports this algorithm.booleanverify(com.nimbusds.jwt.SignedJWT jwt)Verify a signed JWT.protected booleanverify(java.util.List<com.nimbusds.jose.jwk.JWK> matches, com.nimbusds.jwt.SignedJWT jwt)returns true if any JWK match is able to verify the JWT signature.
-
-
-
Field Detail
-
DEFAULT_REFRESH_JWKS_ATTEMPTS
@Deprecated public static final int DEFAULT_REFRESH_JWKS_ATTEMPTS
Deprecated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JwksSignature
@Inject public JwksSignature(JwksSignatureConfiguration jwksSignatureConfiguration, JwkValidator jwkValidator, JwkSetFetcher<com.nimbusds.jose.jwk.JWKSet> jwkSetFetcher)
- Parameters:
jwksSignatureConfiguration- JSON Web Key Set configuration.jwkValidator- JWK Validator to be used.jwkSetFetcher- Json Web Key Set fetcher
-
JwksSignature
@Deprecated public JwksSignature(JwksSignatureConfiguration jwksSignatureConfiguration, JwkValidator jwkValidator)
Deprecated.- Parameters:
jwksSignatureConfiguration- JSON Web Key Set configuration.jwkValidator- JWK Validator to be used.
-
JwksSignature
@Deprecated public JwksSignature(java.lang.String url, @Nullable com.nimbusds.jose.jwk.KeyType keyType, JwkValidator jwkValidator)Deprecated.- Parameters:
url- The JWK urlkeyType- The JWK key typejwkValidator- JWK Validator to be used.
-
-
Method Detail
-
isExpired
public boolean isExpired()
-
clear
public void clear()
Description copied from interface:JwksCacheClears the JWK Set cache.
-
isPresent
public boolean isPresent()
-
getKeyIds
@NonNull public java.util.Optional<java.util.List<java.lang.String>> getKeyIds()
-
supportedAlgorithmsMessage
public java.lang.String supportedAlgorithmsMessage()
- Specified by:
supportedAlgorithmsMessagein interfaceSignatureConfiguration- Returns:
- A message indicating the supported algorithms.
-
supports
public boolean supports(com.nimbusds.jose.JWSAlgorithm algorithm)
Whether this signature configuration supports this algorithm.- Specified by:
supportsin interfaceSignatureConfiguration- Parameters:
algorithm- the signature algorithm- Returns:
- whether this signature configuration supports this algorithm
-
verify
public boolean verify(com.nimbusds.jwt.SignedJWT jwt) throws com.nimbusds.jose.JOSEExceptionVerify a signed JWT.- Specified by:
verifyin interfaceSignatureConfiguration- Parameters:
jwt- the signed JWT- Returns:
- whether the signed JWT is verified
- Throws:
com.nimbusds.jose.JOSEException- exception when verifying the JWT
-
loadJwkSet
@Nullable protected com.nimbusds.jose.jwk.JWKSet loadJwkSet(java.lang.String url)
Instantiates a JWKSet for a given url.- Parameters:
url- JSON Web Key Set Url.- Returns:
- a JWKSet or null if there was an error.
-
matches
@Deprecated protected java.util.List<com.nimbusds.jose.jwk.JWK> matches(com.nimbusds.jwt.SignedJWT jwt, @Nullable com.nimbusds.jose.jwk.JWKSet jwkSet, int refreshKeysAttempts)Deprecated.Usematches(SignedJWT, JWKSet)insteadCalculates a list of JWK matches for a JWT.- Parameters:
jwt- A Signed JWTjwkSet- A JSON Web Key SetrefreshKeysAttempts- Number of times to attempt refreshing the JWK Set- Returns:
- a List of JSON Web Keys
-
matches
@Deprecated protected java.util.List<com.nimbusds.jose.jwk.JWK> matches(com.nimbusds.jwt.SignedJWT jwt, @Nullable com.nimbusds.jose.jwk.JWKSet jwkSet)Deprecated.Calculates a list of JWK matches for a JWT.- Parameters:
jwt- A Signed JWTjwkSet- A JSON Web Key Set- Returns:
- a List of JSON Web Keys
-
verify
protected boolean verify(java.util.List<com.nimbusds.jose.jwk.JWK> matches, com.nimbusds.jwt.SignedJWT jwt)returns true if any JWK match is able to verify the JWT signature.- Parameters:
matches- A List of JSON Web key matches.jwt- A JWT to be verified.- Returns:
- true if the JWT signature could be verified.
-
getRefreshJwksAttempts
@Deprecated public int getRefreshJwksAttempts()
Deprecated.Returns the number of attempts to refresh the cached JWKS.- Returns:
- Number of attempts to refresh the cached JWKS.
-
getJwkValidator
@Deprecated public JwkValidator getJwkValidator()
Deprecated.- Returns:
- A JSON Web Key Validator.
-
getJwkSet
@Deprecated public com.nimbusds.jose.jwk.JWKSet getJwkSet()
Deprecated.- Returns:
- a JSON Web Key Set.
-
getKeyType
@Deprecated public com.nimbusds.jose.jwk.KeyType getKeyType()
Deprecated.- Returns:
- the Key Type.
-
getUrl
@Deprecated public java.lang.String getUrl()
Deprecated.- Returns:
- The JSON Web Key Set (JWKS) URL.
-
-