Class RefreshingHttpsJwks
java.lang.Object
org.apache.kafka.common.security.oauthbearer.secured.RefreshingHttpsJwks
- All Implemented Interfaces:
Closeable,AutoCloseable,Initable
Implementation of
HttpsJwks that will periodically refresh the JWKS cache to reduce or
even prevent HTTP/HTTPS traffic in the hot path of validation. It is assumed that it's
possible to receive a JWT that contains a kid that points to yet-unknown JWK,
thus requiring a connection to the OAuth/OIDC provider to be made. Hopefully, in practice,
keys are made available for some amount of time before they're used within JWTs.
This instance is created and provided to the
HttpsJwksVerificationKeyResolver that is used when using
an HTTP-/HTTPS-based VerificationKeyResolver, which is then
provided to the ValidatorAccessTokenValidator to use in validating the signature of
a JWT.- See Also:
-
HttpsJwksVerificationKeyResolverVerificationKeyResolverValidatorAccessTokenValidator
-
Constructor Summary
ConstructorsConstructorDescriptionRefreshingHttpsJwks(org.apache.kafka.common.utils.Time time, org.jose4j.jwk.HttpsJwks httpsJwks, long refreshMs, long refreshRetryBackoffMs, long refreshRetryBackoffMaxMs) Creates aRefreshingHttpsJwksthat will be used by theRefreshingHttpsJwksVerificationKeyResolverto resolve new key IDs in JWTs. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()List<org.jose4j.jwk.JsonWebKey>Our implementation avoids the blocking call withinHttpsJwks.refresh()that is sometimes called internal toHttpsJwks.getJsonWebKeys().voidinit()Lifecycle method to perform any one-time initialization of the retriever.booleanmaybeExpediteRefresh(String keyId) maybeExpediteRefreshis a public method that will trigger a refresh of the JWKS cache if all of the following conditions are met: The givenkeyIdparameter is <e; theMISSING_KEY_ID_MAX_KEY_LENGTHThe key isn't in the process of being expedited already
-
Constructor Details
-
RefreshingHttpsJwks
public RefreshingHttpsJwks(org.apache.kafka.common.utils.Time time, org.jose4j.jwk.HttpsJwks httpsJwks, long refreshMs, long refreshRetryBackoffMs, long refreshRetryBackoffMaxMs) Creates aRefreshingHttpsJwksthat will be used by theRefreshingHttpsJwksVerificationKeyResolverto resolve new key IDs in JWTs.- Parameters:
time-TimeinstancehttpsJwks-HttpsJwksinstance from which to retrieve the JWKS based on the OAuth/OIDC standardrefreshMs- The number of milliseconds between refresh passes to connect to the OAuth/OIDC JWKS endpoint to retrieve the latest setrefreshRetryBackoffMs- Time for delay after initial failed attempt to retrieve JWKSrefreshRetryBackoffMaxMs- Maximum time to retrieve JWKS
-
-
Method Details
-
init
Description copied from interface:InitableLifecycle method to perform any one-time initialization of the retriever. This must be performed by the caller to ensure the correct state before methods are invoked.- Specified by:
initin interfaceInitable- Throws:
IOException- Thrown on errors related to IO during initialization
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getJsonWebKeys
public List<org.jose4j.jwk.JsonWebKey> getJsonWebKeys() throws org.jose4j.lang.JoseException, IOExceptionOur implementation avoids the blocking call withinHttpsJwks.refresh()that is sometimes called internal toHttpsJwks.getJsonWebKeys(). We want to avoid any blocking I/O as this code is running in the authentication path on the Kafka network thread. The list may be stale up torefreshMs.- Returns:
ListofJsonWebKeyinstances- Throws:
org.jose4j.lang.JoseException- Thrown if a problem is encountered parsing the JSON content into JWKsIOException- Thrown f a problem is encountered making the HTTP request
-
getLocation
-
maybeExpediteRefresh
maybeExpediteRefreshis a public method that will trigger a refresh of the JWKS cache if all of the following conditions are met:- The given
keyIdparameter is <e; theMISSING_KEY_ID_MAX_KEY_LENGTH - The key isn't in the process of being expedited already
This expedited refresh is scheduled immediately.
- Parameters:
keyId- JWT key ID- Returns:
trueif an expedited refresh was scheduled,falseotherwise
- The given
-