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:
-
HttpsJwksVerificationKeyResolver
VerificationKeyResolver
ValidatorAccessTokenValidator
-
Constructor Summary
ConstructorDescriptionRefreshingHttpsJwks
(org.apache.kafka.common.utils.Time time, org.jose4j.jwk.HttpsJwks httpsJwks, long refreshMs, long refreshRetryBackoffMs, long refreshRetryBackoffMaxMs) Creates aRefreshingHttpsJwks
that will be used by theRefreshingHttpsJwksVerificationKeyResolver
to resolve new key IDs in JWTs. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
List<org.jose4j.jwk.JsonWebKey>
Our implementation avoids the blocking call withinHttpsJwks.refresh()
that is sometimes called internal toHttpsJwks.getJsonWebKeys()
.void
init()
Lifecycle method to perform any one-time initialization of the retriever.boolean
maybeExpediteRefresh
(String keyId) maybeExpediteRefresh
is a public method that will trigger a refresh of the JWKS cache if all of the following conditions are met: The givenkeyId
parameter is <e; theMISSING_KEY_ID_MAX_KEY_LENGTH
The 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 aRefreshingHttpsJwks
that will be used by theRefreshingHttpsJwksVerificationKeyResolver
to resolve new key IDs in JWTs.- Parameters:
time
-Time
instancehttpsJwks
-HttpsJwks
instance 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:Initable
Lifecycle 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:
init
in interfaceInitable
- Throws:
IOException
- Thrown on errors related to IO during initialization
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:
List
ofJsonWebKey
instances- 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
maybeExpediteRefresh
is a public method that will trigger a refresh of the JWKS cache if all of the following conditions are met:- The given
keyId
parameter 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:
true
if an expedited refresh was scheduled,false
otherwise
- The given
-