Package net.shibboleth.oidc.jwk
Class RemoteJwkSetCache
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent
Stores fetched remote key set values for a desired period of time.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe context name in theStorageService.private org.apache.hc.client5.http.classic.HttpClientTheHttpClientto use.private HttpClientSecurityParametersHTTP client security parameters.private final org.slf4j.LoggerLogger.private StorageServiceBacking storage for the remote JWK set contents. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidReturns remote JWK set if found from the cache, otherwise fetches and stores it.Returns remote JWK set if found from the cache, otherwise fetches and stores it.Returns remote JWK set if found from the cache, otherwise fetches and stores it.Returns remote JWK set if found from the cache, otherwise fetches and stores it.private JWKSetfetchAndStore(String context, String cacheKey, URI uri, Instant expires) Fetches the remote JWK set from the given URI and stores it in the storage service.Get the backing store for the remote JWK set contents.voidsetHttpClient(org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.voidSet the optional client security parameters.voidsetStorage(StorageService storageService) Set the backing store for the remote JWK set contents.Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getId
-
Field Details
-
CONTEXT_NAME
The context name in theStorageService.- See Also:
-
log
private final org.slf4j.Logger logLogger. -
storage
Backing storage for the remote JWK set contents. -
httpClient
TheHttpClientto use. -
httpClientSecurityParameters
HTTP client security parameters.
-
-
Constructor Details
-
RemoteJwkSetCache
public RemoteJwkSetCache()
-
-
Method Details
-
getStorage
Get the backing store for the remote JWK set contents.- Returns:
- the backing store.
-
setStorage
Set the backing store for the remote JWK set contents.- Parameters:
storageService- backing store to use
-
setHttpClient
public void setHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.- Parameters:
client- client to use
-
setHttpClientSecurityParameters
Set the optional client security parameters.- Parameters:
params- the new client security parameters
-
doInitialize
- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-
fetch
Returns remote JWK set if found from the cache, otherwise fetches and stores it. If the JWK set is from the cache check it contains the keyId and if not, refresh the JWK set in the cache. Uses the default CONTEXT_NAME. Delegates tofetch(String, URI, String, Instant)for the actual implementation.- Parameters:
uri- value to checkkeyId- the identifier of the key to check exists in a cached version of the keyset documentexpires- time for disposal of value from cache- Returns:
- JWK set, null if not found from the cache and cannot be fetched.
- Since:
- 2.2.0
-
fetch
Returns remote JWK set if found from the cache, otherwise fetches and stores it.- Parameters:
uri- value to checkexpires- time for disposal of value from cache- Returns:
- JWK set, null if not found from the cache and cannot be fetched.
-
fetch
@Nullable public JWKSet fetch(@Nonnull @NotEmpty String context, @Nonnull URI uri, @Nonnull Instant expires) Returns remote JWK set if found from the cache, otherwise fetches and stores it.- Parameters:
context- a context label to subdivide the cacheuri- value to checkexpires- time (in milliseconds since beginning of epoch) for disposal of value from cache- Returns:
- JWK set, null if not found from the cache and cannot be fetched.
-
fetchAndStore
@Nullable private JWKSet fetchAndStore(@Nonnull @NotEmpty String context, @Nonnull String cacheKey, @Nonnull URI uri, @Nonnull Instant expires) Fetches the remote JWK set from the given URI and stores it in the storage service.- Parameters:
context- a context label to subdivide the cachecacheKey- the key to store the JWK set under in the storage serviceuri- value to fetch the JWK set fromexpires- time (in milliseconds since beginning of epoch) for disposal of value from cache- Returns:
- the JWK set document if fetched successfully,
nullotherwise. - Since:
- 2.2.0
-
fetch
@Nullable public JWKSet fetch(@Nonnull @NotEmpty String context, @Nonnull URI uri, @Nonnull String keyId, @Nonnull Instant expires) Returns remote JWK set if found from the cache, otherwise fetches and stores it. If the JWK set is retrieved from the cache, checks it contains the JWK keyId input, if not it re-fetches the JWK set even if the set has not expired. This allows keys to be returned when the JWK Set has been updated but has not yet expired e.g. during key rotation.- Parameters:
context- a context label to subdivide the cacheuri- value to checkkeyId- the identifier of the key to check exists in a cached version of the keyset documentexpires- time (in milliseconds since beginning of epoch) for disposal of value from cache- Returns:
- JWK set, null if not found from the cache and cannot be fetched.
- Since:
- 2.2.0
-