Class JwtTokenValidator.Builder
- Enclosing class:
- JwtTokenValidator
JwtTokenValidator.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionalgorithms(com.nimbusds.jose.JWSAlgorithm... values) Sets the signing-algorithm allowlist.Sets the requiredaud(audience) claim value.build()Builds the validator.Sets the clock-skew tolerance forexp/nbfvalidation.Sets the requirediss(issuer) claim value.jwksCacheTtl(Duration value) Sets the JWKS cache TTL.jwksEagerRefreshCooldown(Duration value) Sets the minimum spacing between consecutive eager JWKS refreshes.jwksEagerRefreshOnKidMiss(boolean value) Enables or disables the eager JWKS refresh that fires on a fresh-cachekidmiss.jwkSource(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> value) Sets a customJWKSourcethe validator fetches keys from.Sets the JWKS endpoint URL the validator fetches keys from.
-
Constructor Details
-
Builder
protected Builder()Constructor.
-
-
Method Details
-
jwksUrl
Sets the JWKS endpoint URL the validator fetches keys from.Mutually exclusive with
jwkSource(JWKSource)— set one or the other.The URL must use
"https" or target a loopback host; the signing-key material fetched from this endpoint is the trust anchor for every token, so a plaintext transport to a non-loopback host is rejected.- Parameters:
value- The JWKS URL. Must not benull and must use HTTPS or target a loopback host.- Returns:
- This object.
-
jwkSource
public JwtTokenValidator.Builder jwkSource(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> value) Sets a customJWKSourcethe validator fetches keys from.Mutually exclusive with
jwksUrl(URI)— set one or the other. Useful for HSM-backed signers, multi-issuer federation, or unit tests that want to inject a deterministic key set without binding to a real HTTPS endpoint.- Parameters:
value- The JWK source. Must not benull .- Returns:
- This object.
-
issuer
Sets the requirediss(issuer) claim value.- Parameters:
value- The issuer. Must not benull or blank.- Returns:
- This object.
-
audience
Sets the requiredaud(audience) claim value.- Parameters:
value- The audience. Must not benull or blank.- Returns:
- This object.
-
algorithms
Sets the signing-algorithm allowlist.Replaces (not adds to) the default allowlist. Callers wanting
HS256support must include it explicitly.Algorithm.NONEis rejected at build time and at runtime regardless of what is passed here.- Parameters:
values- The allowed algorithms. Must contain at least one element; must not containAlgorithm.NONE.- Returns:
- This object.
-
clockSkew
Sets the clock-skew tolerance forexp/nbfvalidation.- Parameters:
value- The tolerance. Must be non-negative and not exceed 5 minutes.- Returns:
- This object.
-
jwksCacheTtl
Sets the JWKS cache TTL.- Parameters:
value- The TTL. Must be positive.- Returns:
- This object.
-
jwksEagerRefreshOnKidMiss
Enables or disables the eager JWKS refresh that fires on a fresh-cachekidmiss.When
true(the default), the first request that presents a token whose signing key is not in the current (still-fresh) cache triggers a single out-of-band JWKS refresh. This closes the rotation window where an IdP publishes a new key mid-TTL and clients would otherwise see up tojwksCacheTtlminutes of spurious 401 responses for perfectly valid tokens. The refresh is bounded byjwksEagerRefreshCooldown(Duration)and a single-in-flight guard (no thundering herd).Applies only to
jwksUrl(...)-backed caches. A caller-suppliedjwkSource(...)is unaffected.- Parameters:
value-trueto enable (default);falseto restore pre-10.0.0 behavior.- Returns:
- This object.
-
jwksEagerRefreshCooldown
Sets the minimum spacing between consecutive eager JWKS refreshes.A burst of unknown-
kidtokens (e.g. misconfigured client, replay attack) or a JWKS-endpoint outage will trigger at most one eager refresh per cooldown window. This prevents the eager-refresh path from becoming a vector for amplified JWKS-endpoint load.Must be positive, at most 60 seconds, and at most
jwksCacheTtl(validated atbuild()time).- Parameters:
value- The cooldown. Must not benull.- Returns:
- This object.
-
clock
- Parameters:
value- The clock. Must not benull .- Returns:
- This object.
-
build
Builds the validator.- Returns:
- A new
JwtTokenValidator.
-