Class OidcRelyingParty
juneau-rest-server-auth-oauth building blocks.
A single instance wires the login / callback / logout endpoints plus the session SPI for one IdP. The
application mounts the three endpoints as explicit @RestGet methods that delegate to this
facade — there are no auto-mounted servlet routes (URL ownership stays with the app):
Register authFilter() in the servlet filter chain (or AuthFilterChain) so each request
resolves the session cookie into a ClaimsPrincipal for RoleBasedRestGuard /
@Auth Principal.
Security
stateandnonceare single-use and TTL-bounded (default 5 min); a missing / replayed value fails the callback.- PKCE S256 is enforced end-to-end.
- The ID token is validated for signature,
iss,aud/azp,exp, andnonce(seeIdTokenValidatorAdapter). - The session id is freshly generated on login (no pre-auth fixation).
- Auth responses set
Cache-Control: no-store; tokens are never logged. - The session cookie is
HttpOnly+Secure+SameSiteby default.
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns a request-timeAuthFilterthat resolves this RP's session cookie into aClaimsPrincipal.intbackChannelLogout(String logoutToken) Processes an IdP-pushed OpenID Connect back-channel logout token, invalidating the matching server-side session(s).voidcompleteLogin(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Completes the login flow: parses the callback, verifies + consumesstate, exchanges the code (PKCE), validates the ID token (signature /iss/aud/exp/nonce), creates a session, sets the session cookie, and redirects to the application.Returns the session cookie name.static OidcRelyingParty.Buildercreate()Static creator.voidlogout(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Logs the user out: invalidates the session, clears the session cookie, and (when the IdP advertises an end-session endpoint) redirects through it; otherwise redirects to the post-logout target.refresh(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Refreshes the current session's access token using the rotating-refresh-token grant.Returns the configured session store.voidstartLogin(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Begins the login flow: generatesstate+nonce+ PKCE verifier, stores them single-use, and redirects the user-agent to the IdP authorization endpoint.
-
Constructor Details
-
OidcRelyingParty
Constructor.- Parameters:
b- The builder.
-
-
Method Details
-
create
Static creator.- Returns:
- A new builder.
-
startLogin
public void startLogin(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException Begins the login flow: generatesstate+nonce+ PKCE verifier, stores them single-use, and redirects the user-agent to the IdP authorization endpoint.- Parameters:
req- The HTTP request. An optionalredirectquery parameter (a safe relative path) is remembered as the post-login target.res- The HTTP response.- Throws:
IOException- If the redirect cannot be written.
-
completeLogin
public void completeLogin(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, AuthenticationException Completes the login flow: parses the callback, verifies + consumesstate, exchanges the code (PKCE), validates the ID token (signature /iss/aud/exp/nonce), creates a session, sets the session cookie, and redirects to the application.- Parameters:
req- The callback HTTP request (carryingcode+state).res- The HTTP response.- Throws:
IOException- If the redirect cannot be written.AuthenticationException- If the callback is an error, the state is missing / replayed, or ID-token validation fails.
-
logout
public void logout(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException Logs the user out: invalidates the session, clears the session cookie, and (when the IdP advertises an end-session endpoint) redirects through it; otherwise redirects to the post-logout target.- Parameters:
req- The HTTP request.res- The HTTP response.- Throws:
IOException- If the redirect cannot be written.
-
refresh
public Optional<OidcSession> refresh(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Refreshes the current session's access token using the rotating-refresh-token grant.Replaces the stored refresh token with the one the IdP returns; if the IdP rejects the refresh (e.g. a rotated token was reused / revoked), the session is invalidated. Only applies to stores that retain tokens (server-side);
SignedCookieSessionStoresessions carry no tokens and yieldOptional.empty().- Parameters:
req- The HTTP request.res- The HTTP response (a refreshed session resets the cookie).- Returns:
- The refreshed session, or
Optional.empty()if there was nothing to refresh.
-
backChannelLogout
Processes an IdP-pushed OpenID Connect back-channel logout token, invalidating the matching server-side session(s).The logout token is validated via Nimbus's
LogoutTokenValidator(signature against the JWKS,iss,aud, the back-channeleventsclaim, and thesub/sidpresence rule). Sessions are then revoked bysid(preferred, single-session) orsub(all of a subject's sessions).Requires a
server-side-revocablestore — the defaultSignedCookieSessionStorecannot satisfy back-channel logout because a stateless cookie is not server-revocable.- Parameters:
logoutToken- The rawlogout_tokenJWT pushed by the IdP. Must not benull or blank.- Returns:
- The number of sessions invalidated.
- Throws:
AuthenticationException- If the logout token fails validation.IllegalStateException- If the configured session store does not support server-side revocation.
-
authFilter
Returns a request-timeAuthFilterthat resolves this RP's session cookie into aClaimsPrincipal.- Returns:
- A new
OidcSessionAuthFilterbound to this RP's session store + cookie name.
-
sessionStore
Returns the configured session store.- Returns:
- The session store.
-
cookieName
Returns the session cookie name.- Returns:
- The cookie name.
-