Package com.nimbusds.jose.jwk.source
Class RemoteJWKSet<C extends SecurityContext>
- java.lang.Object
-
- com.nimbusds.jose.jwk.source.RemoteJWKSet<C>
-
- All Implemented Interfaces:
JWKSource<C>
@ThreadSafe public class RemoteJWKSet<C extends SecurityContext> extends Object implements JWKSource<C>
Remote JSON Web Key (JWK) source specified by a JWK set URL. The retrieved JWK set is cached to minimise network calls. The cache is updated whenever the key selector tries to get a key with an unknown ID or the cache expires.If no
ResourceRetrieveris specified when creating a remote JWK set source thedefault onewill be used, with the following HTTP timeouts and limits:- HTTP connect timeout, in milliseconds: Determined by the
DEFAULT_HTTP_CONNECT_TIMEOUTconstant which can be overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpConnectTimeoutJava system property. - HTTP read timeout, in milliseconds: Determined by the
DEFAULT_HTTP_READ_TIMEOUTconstant which can be overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpReadTimeoutJava system property. - HTTP entity size limit: Determined by the
DEFAULT_HTTP_SIZE_LIMITconstant which can be overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpSizeLimitJava system property.
A failover JWK source can be configured in case the JWK set URL becomes unavailable (HTTP 404) or times out. The failover JWK source can be another URL or some other object.
- Version:
- 2022-01-30
- Author:
- Vladimir Dzhuvinov, Andreas Huber
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_HTTP_CONNECT_TIMEOUTThe default HTTP connect timeout for JWK set retrieval, in milliseconds.static intDEFAULT_HTTP_READ_TIMEOUTThe default HTTP read timeout for JWK set retrieval, in milliseconds.static intDEFAULT_HTTP_SIZE_LIMITThe default HTTP entity size limit for JWK set retrieval, in bytes.
-
Constructor Summary
Constructors Constructor Description RemoteJWKSet(URL jwkSetURL)Creates a new remote JWK set using thedefault HTTP resource retrieverwith the default HTTP timeouts and entity size limit.RemoteJWKSet(URL jwkSetURL, JWKSource<C> failoverJWKSource)Creates a new remote JWK set using thedefault HTTP resource retrieverwith the default HTTP timeouts and entity size limit.RemoteJWKSet(URL jwkSetURL, JWKSource<C> failoverJWKSource, ResourceRetriever resourceRetriever, JWKSetCache jwkSetCache)Creates a new remote JWK set.RemoteJWKSet(URL jwkSetURL, ResourceRetriever resourceRetriever)Creates a new remote JWK set.RemoteJWKSet(URL jwkSetURL, ResourceRetriever resourceRetriever, JWKSetCache jwkSetCache)Creates a new remote JWK set.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<JWK>get(JWKSelector jwkSelector, C context)Retrieves a list of JWKs matching the specified selector.JWKSetgetCachedJWKSet()Returns the cached JWK set.JWKSource<C>getFailoverJWKSource()Returns the optional failover JWK source.protected static StringgetFirstSpecifiedKeyID(JWKMatcher jwkMatcher)Returns the first specified key ID (kid) for a JWK matcher.JWKSetCachegetJWKSetCache()Returns the configured JWK set cache.URLgetJWKSetURL()Returns the JWK set URL.ResourceRetrievergetResourceRetriever()Returns the HTTP resource retriever.static intresolveDefaultHTTPConnectTimeout()Resolves the default HTTP connect timeout for JWK set retrieval, in milliseconds.static intresolveDefaultHTTPReadTimeout()Resolves the default HTTP read timeout for JWK set retrieval, in milliseconds.static intresolveDefaultHTTPSizeLimit()Resolves default HTTP entity size limit for JWK set retrieval, in bytes.
-
-
-
Field Detail
-
DEFAULT_HTTP_CONNECT_TIMEOUT
public static final int DEFAULT_HTTP_CONNECT_TIMEOUT
The default HTTP connect timeout for JWK set retrieval, in milliseconds. Set to 500 milliseconds.- See Also:
- Constant Field Values
-
DEFAULT_HTTP_READ_TIMEOUT
public static final int DEFAULT_HTTP_READ_TIMEOUT
The default HTTP read timeout for JWK set retrieval, in milliseconds. Set to 500 milliseconds.- See Also:
- Constant Field Values
-
DEFAULT_HTTP_SIZE_LIMIT
public static final int DEFAULT_HTTP_SIZE_LIMIT
The default HTTP entity size limit for JWK set retrieval, in bytes. Set to 50 KBytes.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RemoteJWKSet
public RemoteJWKSet(URL jwkSetURL)
Creates a new remote JWK set using thedefault HTTP resource retrieverwith the default HTTP timeouts and entity size limit.- Parameters:
jwkSetURL- The JWK set URL. Must not benull.
-
RemoteJWKSet
public RemoteJWKSet(URL jwkSetURL, JWKSource<C> failoverJWKSource)
Creates a new remote JWK set using thedefault HTTP resource retrieverwith the default HTTP timeouts and entity size limit.- Parameters:
jwkSetURL- The JWK set URL. Must not benull.failoverJWKSource- Optional failover JWK source in case retrieval from the JWK set URL fails,nullif no failover is specified.
-
RemoteJWKSet
public RemoteJWKSet(URL jwkSetURL, ResourceRetriever resourceRetriever)
Creates a new remote JWK set.- Parameters:
jwkSetURL- The JWK set URL. Must not benull.resourceRetriever- The HTTP resource retriever to use,nullto use thedefault onewith the default HTTP timeouts and entity size limit.
-
RemoteJWKSet
public RemoteJWKSet(URL jwkSetURL, ResourceRetriever resourceRetriever, JWKSetCache jwkSetCache)
Creates a new remote JWK set.- Parameters:
jwkSetURL- The JWK set URL. Must not benull.resourceRetriever- The HTTP resource retriever to use,nullto use thedefault onewith the default HTTP timeouts and entity size limit.jwkSetCache- The JWK set cache to use,nullto use thedefault one.
-
RemoteJWKSet
public RemoteJWKSet(URL jwkSetURL, JWKSource<C> failoverJWKSource, ResourceRetriever resourceRetriever, JWKSetCache jwkSetCache)
Creates a new remote JWK set.- Parameters:
jwkSetURL- The JWK set URL. Must not benull.failoverJWKSource- Optional failover JWK source in case retrieval from the JWK set URL fails,nullif no failover is specified.resourceRetriever- The HTTP resource retriever to use,nullto use thedefault onewith the default HTTP timeouts and entity size limit.jwkSetCache- The JWK set cache to use,nullto use thedefault one.
-
-
Method Detail
-
resolveDefaultHTTPConnectTimeout
public static int resolveDefaultHTTPConnectTimeout()
Resolves the default HTTP connect timeout for JWK set retrieval, in milliseconds.- Returns:
- The
static constant, overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpConnectTimeoutJava system property.
-
resolveDefaultHTTPReadTimeout
public static int resolveDefaultHTTPReadTimeout()
Resolves the default HTTP read timeout for JWK set retrieval, in milliseconds.- Returns:
- The
static constant, overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpReadTimeoutJava system property.
-
resolveDefaultHTTPSizeLimit
public static int resolveDefaultHTTPSizeLimit()
Resolves default HTTP entity size limit for JWK set retrieval, in bytes.- Returns:
- The
static constant, overridden by setting thecom.nimbusds.jose.jwk.source.RemoteJWKSet.defaultHttpSizeLimitJava system property.
-
getJWKSetURL
public URL getJWKSetURL()
Returns the JWK set URL.- Returns:
- The JWK set URL.
-
getFailoverJWKSource
public JWKSource<C> getFailoverJWKSource()
Returns the optional failover JWK source.- Returns:
- The failover JWK source,
nullif not specified.
-
getResourceRetriever
public ResourceRetriever getResourceRetriever()
Returns the HTTP resource retriever.- Returns:
- The HTTP resource retriever.
-
getJWKSetCache
public JWKSetCache getJWKSetCache()
Returns the configured JWK set cache.- Returns:
- The JWK set cache.
-
getCachedJWKSet
public JWKSet getCachedJWKSet()
Returns the cached JWK set.- Returns:
- The cached JWK set,
nullif none or expired.
-
getFirstSpecifiedKeyID
protected static String getFirstSpecifiedKeyID(JWKMatcher jwkMatcher)
Returns the first specified key ID (kid) for a JWK matcher.- Parameters:
jwkMatcher- The JWK matcher. Must not benull.- Returns:
- The first key ID,
nullif none.
-
get
public List<JWK> get(JWKSelector jwkSelector, C context) throws RemoteKeySourceException
Description copied from interface:JWKSourceRetrieves a list of JWKs matching the specified selector.- Specified by:
getin interfaceJWKSource<C extends SecurityContext>- Parameters:
jwkSelector- A JWK selector. Must not benull.context- Optional context,nullif not required.- Returns:
- The matching JWKs, empty list if no matches were found.
- Throws:
RemoteKeySourceException
-
-