Class OidcRelyingParty.Builder
- Enclosing class:
- OidcRelyingParty
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticationRequestCustomizer(Consumer<com.nimbusds.openid.connect.sdk.AuthenticationRequest.Builder> value) Sets a NimbusAuthenticationRequest.Buildercustomizer escape hatch (e.g.build()Builds the relying party.Sets the OAuth client id.clientSecret(String value) Sets the client secret.clientSecretSupplier(Supplier<String> value) Sets the client secret via a supplier.Overrides the clock used for session expiry and the login-state store.clockSkewSeconds(int value) Sets the clock-skew tolerance (seconds) for ID-token validation.cookieHttpOnly(boolean value) Sets the cookieHttpOnlyflag.cookieName(String value) Sets the session cookie name.cookieSameSite(String value) Sets the cookieSameSiteattribute.cookieSecure(boolean value) Sets the cookieSecureflag.httpRequestConfigurator(Consumer<com.nimbusds.oauth2.sdk.http.HTTPRequest> value) Sets a NimbusHTTPRequestconfigurator escape hatch (proxy / TLS / timeouts) applied to discovery + token + userinfo calls.idTokenAlgorithms(com.nimbusds.jose.JWSAlgorithm... values) Sets the ID-token signing-algorithm allowlist.Sets the IdP issuer URL.jwkSet(com.nimbusds.jose.jwk.JWKSet value) Injects a fixed JWK set for ID-token / logout-token signature verification, bypassing the JWKS endpoint.jwkSource(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> value) Injects a custom JWK source for ID-token / logout-token signature verification.loginStateStore(LoginStateStore value) Sets an optional customLoginStateStorefor the pending-login (state→nonce/ PKCEcode_verifier/ redirect) association.metadata(OidcMetadata value) Sets the IdP metadata explicitly, bypassing discovery.postLoginRedirect(String value) Sets the default post-login redirect target (when the login request supplied no saferedirectparameter).postLogoutRedirectUri(URI value) Sets the post-logout redirect URI passed to the IdP end-session endpoint.redirectUri(URI value) Sets the redirect URI registered with the IdP.rolesClaim(String value) Sets the claim roles are extracted from.Adds requested scopes.sessionStore(SessionStore value) Sets the session store.sessionTtl(Duration value) Sets the session lifetime (bounded independently of token lifetime).stateNonceTtl(Duration value) Sets the single-use TTL the framework enforces for the login-state (state/nonce/ PKCEcode_verifier) association.userInfoClaims(String... values) Adds claim names to backfill from the UserInfo endpoint when absent from the ID token.
-
Constructor Details
-
Builder
protected Builder()Constructor.
-
-
Method Details
-
issuer
Sets the IdP issuer URL. OIDC discovery resolves the endpoints + JWKS URI lazily. Either this ormetadata(OidcMetadata)is required.The issuer (and every endpoint discovered from it) must use
"https" or target a loopback host; discovery, JWKS, and token exchanges carry trust-anchor key material and client credentials, so a plaintext transport to a non-loopback host is rejected.- Parameters:
value- The issuer URL. Must not benull and must use HTTPS or target a loopback host.- Returns:
- This object.
-
metadata
Sets the IdP metadata explicitly, bypassing discovery. Either this orissuer(URI)is required.- Parameters:
value- The metadata. Must not benull .- Returns:
- This object.
-
clientId
Sets the OAuth client id. Required.- Parameters:
value- The client id. Must not benull or blank.- Returns:
- This object.
-
clientSecret
Sets the client secret. May be omitted for public clients (PKCE-only).- Parameters:
value- The client secret. Must not benull or blank.- Returns:
- This object.
-
clientSecretSupplier
Sets the client secret via a supplier.- Parameters:
value- The supplier. Must not benull .- Returns:
- This object.
-
redirectUri
Sets the redirect URI registered with the IdP. Required.- Parameters:
value- The redirect URI. Must not benull .- Returns:
- This object.
-
postLogoutRedirectUri
Sets the post-logout redirect URI passed to the IdP end-session endpoint.- Parameters:
value- The post-logout redirect URI. Must not benull .- Returns:
- This object.
-
postLoginRedirect
Sets the default post-login redirect target (when the login request supplied no saferedirectparameter). Defaults to"/".- Parameters:
value- The default redirect path. Must not benull or blank.- Returns:
- This object.
-
scope
Adds requested scopes.openidis always included.- Parameters:
values- The scopes.- Returns:
- This object.
-
sessionStore
Sets the session store. Required.- Parameters:
value- The session store. Must not benull .- Returns:
- This object.
-
rolesClaim
Sets the claim roles are extracted from. Defaults to"scope"(whitespace-split); array claims are also accepted. Mirrors theOAuthFilterconvention.- Parameters:
value- The claim name. Must not benull or blank.- Returns:
- This object.
-
stateNonceTtl
Sets the single-use TTL the framework enforces for the login-state (state/nonce/ PKCEcode_verifier) association. Defaults to 5 minutes.This is the RP-enforced policy applied to every consumed record — both the default
InMemoryLoginStateStoreand any custominjected store. The framework mintsexpiresAt = createdAt + stateNonceTtlon the record and re-checks it on consume, so the ceiling holds even for a shared store that fails to expire an entry. The(0,LoginStateStore.MAX_TTL]cap is enforced here (not only in the default impl's constructor, which is skipped when a custom store is injected).- Parameters:
value- The TTL. Must be positive and not exceedLoginStateStore.MAX_TTL(30 minutes).- Returns:
- This object.
-
loginStateStore
Sets an optional customLoginStateStorefor the pending-login (state→nonce/ PKCEcode_verifier/ redirect) association.Optional (unlike
sessionStore(SessionStore)): when omitted the RP uses the shipped per-JVMInMemoryLoginStateStore, and behavior is identical to a single-node deployment. Supply a shared (Redis / JDBC) implementation to support a clustered deployment where/loginand/callbackmay land on different nodes without sticky sessions — the same motivation as a distributedSessionStore.The store is secret-bearing (
code_verifier+nonce); read theLoginStateStoresecurity contract before implementing one (TLS + locked-down ACL floor, encryption-at-rest recommended, never log the payload, atomicGETDEL/Lua single-use consume). The framework retains authority over the security-critical decisions regardless of the store: it re-validatesredirectTargetviasafeRelativePathand re-checksexpiresAtagainst its ownclockon consume, and enforces thestateNonceTtl(Duration)ceiling — the store persists the record and enforces single-use, but is treated as a blob store, not a trusted oracle.- Parameters:
value- The login-state store. Must not benull .- Returns:
- This object.
-
sessionTtl
Sets the session lifetime (bounded independently of token lifetime). Defaults to 8 hours.- Parameters:
value- The session TTL. Must be positive.- Returns:
- This object.
-
cookieName
Sets the session cookie name. Defaults toJUNEAU_OIDC_SESSION.- Parameters:
value- The cookie name. Must not benull or blank.- Returns:
- This object.
-
cookieSecure
Sets the cookieSecureflag. Defaults totrue (fail-closed).- Parameters:
value- The flag.- Returns:
- This object.
-
cookieHttpOnly
Sets the cookieHttpOnlyflag. Defaults totrue (fail-closed).- Parameters:
value- The flag.- Returns:
- This object.
-
cookieSameSite
Sets the cookieSameSiteattribute. Defaults to"Lax".- Parameters:
value- The SameSite value (e.g."Lax"or"Strict"). Must not benull or blank.- Returns:
- This object.
-
httpRequestConfigurator
public OidcRelyingParty.Builder httpRequestConfigurator(Consumer<com.nimbusds.oauth2.sdk.http.HTTPRequest> value) Sets a NimbusHTTPRequestconfigurator escape hatch (proxy / TLS / timeouts) applied to discovery + token + userinfo calls.- Parameters:
value- The callback. Must not benull .- Returns:
- This object.
-
authenticationRequestCustomizer
public OidcRelyingParty.Builder authenticationRequestCustomizer(Consumer<com.nimbusds.openid.connect.sdk.AuthenticationRequest.Builder> value) Sets a NimbusAuthenticationRequest.Buildercustomizer escape hatch (e.g.prompt,max_age,acr_values) applied to the authorization redirect.- Parameters:
value- The callback. Must not benull .- Returns:
- This object.
-
idTokenAlgorithms
Sets the ID-token signing-algorithm allowlist. Defaults to[RS256, ES256].- Parameters:
values- The allowed algorithms.- Returns:
- This object.
-
clockSkewSeconds
Sets the clock-skew tolerance (seconds) for ID-token validation. Defaults to 60.- Parameters:
value- The tolerance in seconds. Must be non-negative.- Returns:
- This object.
-
jwkSet
Injects a fixed JWK set for ID-token / logout-token signature verification, bypassing the JWKS endpoint. Useful for tests and static-key deployments.- Parameters:
value- The JWK set. Must not benull .- Returns:
- This object.
-
jwkSource
public OidcRelyingParty.Builder jwkSource(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> value) Injects a custom JWK source for ID-token / logout-token signature verification.- Parameters:
value- The JWK source. Must not benull .- Returns:
- This object.
-
userInfoClaims
Adds claim names to backfill from the UserInfo endpoint when absent from the ID token.When empty (the default) the UserInfo endpoint is never called — the
Principalis built from ID-token claims only.- Parameters:
values- The claim names to backfill.- Returns:
- This object.
-
clock
Overrides the clock used for session expiry and the login-state store. Useful in tests.The login-state
expiresAtis both minted (onstartLogin) and re-checked (oncompleteLogin) against this clock. In a clustered deployment with a sharedLoginStateStore, the ceiling is therefore only as trustworthy as clock synchronization across nodes; a backendEXPIRE/TTL is a GC hint, not the authoritative expiry decision.- Parameters:
value- The clock. Must not benull .- Returns:
- This object.
-
build
Builds the relying party.- Returns:
- A new
OidcRelyingParty.
-