Class OAuthIntrospectionValidator.Builder
- Enclosing class:
- OAuthIntrospectionValidator
OAuthIntrospectionValidator.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds expected audience values (RFC 7662aud) that a token must carry to be accepted.build()Builds the validator.Sets the cache TTL.Sets the OAuth client ID used for HTTP Basic auth against the introspection endpoint.clientSecret(String value) Sets the OAuth client secret as a literal string.clientSecretSupplier(Supplier<String> value) Sets the OAuth client secret via a supplier (useful for rotating secrets).Overrides theClockused for cache expiry.httpRequestConfigurator(Consumer<com.nimbusds.oauth2.sdk.http.HTTPRequest> value) Sets a callback that customizes the NimbusHTTPRequestbefore it is sent.introspectionEndpoint(URI value) Sets the introspection endpoint URL.requiredScopes(String... scopes) Adds required scopes (scope enforcement lives on the validator, not the filter).Adds expected resource-indicator values (RFC 8707).tokenCache(TokenCache value) Sets a custom token cache.
-
Constructor Details
-
Builder
protected Builder()Constructor.
-
-
Method Details
-
introspectionEndpoint
Sets the introspection endpoint URL. Required.Each introspection call transmits the client secret (HTTP Basic) and the access token under validation to this endpoint, so the URL must use
"https" or target a loopback host; a plaintext transport to a non-loopback host is rejected.- Parameters:
value- The endpoint URL. Must not benull and must use HTTPS or target a loopback host.- Returns:
- This object.
-
clientId
Sets the OAuth client ID used for HTTP Basic auth against the introspection endpoint.- Parameters:
value- The client ID. Must not benull or blank.- Returns:
- This object.
-
clientSecret
Sets the OAuth client secret as a literal string.Mutually exclusive with
clientSecretSupplier(Supplier).- Parameters:
value- The client secret. Must not benull or blank.- Returns:
- This object.
-
clientSecretSupplier
Sets the OAuth client secret via a supplier (useful for rotating secrets).- Parameters:
value- The supplier. Must not benull .- Returns:
- This object.
-
tokenCache
Sets a custom token cache. Defaults to aBoundedLruTokenCachewith 1000 entries.- Parameters:
value- The cache. Must not benull .- Returns:
- This object.
-
cacheTtl
Sets the cache TTL. Defaults to5 minutes; capped at1 hour. Capped by the token's ownexpwhen shorter.- Parameters:
value- The TTL. Must be positive and not exceed 1 hour.- Returns:
- This object.
-
requiredScopes
Adds required scopes (scope enforcement lives on the validator, not the filter).If any required scope is missing from the introspection response's
scopeclaim, the validator throwsAuthenticationExceptionwithWWW-Authenticate: Bearer error="insufficient_scope".- Parameters:
scopes- The required scopes. Must contain at least one non-blank entry.- Returns:
- This object.
-
audience
Adds expected audience values (RFC 7662aud) that a token must carry to be accepted.When at least one value is configured here (via this method or
resource(String...)), the introspection response'saudclaim must contain at least one matching value, or the token is rejected asinvalid_token— even whenactive=trueand required scopes match. This binds the token to the resource server it was minted for, so a token issued for a different API cannot be replayed against this one.When left unset (the default), no audience/resource check is performed: today's
active+ optional-required-scopes behavior is preserved unchanged.- Parameters:
values- The expected audience values. Must contain at least one non-blank entry.- Returns:
- This object.
-
resource
Adds expected resource-indicator values (RFC 8707).Alias for
audience(String...): RFC 8707 resource indicators are echoed back by conformant authorization servers in the same introspectionaudclaim as RFC 7662 audiences, so both methods add to the same expected-value set.- Parameters:
values- The expected resource values. Must contain at least one non-blank entry.- Returns:
- This object.
-
clock
Overrides theClockused for cache expiry. Useful in tests.- Parameters:
value- The clock. Must not benull .- Returns:
- This object.
-
httpRequestConfigurator
public OAuthIntrospectionValidator.Builder httpRequestConfigurator(Consumer<com.nimbusds.oauth2.sdk.http.HTTPRequest> value) Sets a callback that customizes the NimbusHTTPRequestbefore it is sent.This is the escape hatch for custom HTTP behavior (proxies, TLS overrides, timeouts). The callback is invoked on every introspection call.
- Parameters:
value- The configurator callback. Must not benull .- Returns:
- This object.
-
build
Builds the validator.- Returns:
- A new
OAuthIntrospectionValidator.
-