Package dev.relism.flash.ext.oidc
Class OidcMiddleware
java.lang.Object
dev.relism.flash.ext.oidc.OidcMiddleware
Request-level OIDC middleware. Exposed in the
FlashContext
for manual use on lambda routes; injected automatically for handlers annotated with
Authenticated, RolesAllowed or ScopesAllowed.
Resolution order on each request:
Authorization: Bearer ...header — validated via JWKS (JwtValidator).oidc_sessioncookie — looked up inOidcSessionStore; transparently refreshed if the access token is expired.- Browser clients (no
Accept: application/json) → redirect to{routePrefix}/login?redirect={path}. - API clients → 401.
// Manual use on a lambda route:
OidcMiddleware oidc = app.ctx().require(OidcMiddleware.class);
app.get("/api/me", (req, res) -> ClaimsHolder.claim("sub"), oidc.protect());
app.delete("/admin/users/{id}", handler, oidc.requireRole("admin"));
-
Method Summary
Modifier and TypeMethodDescriptionauthorize(dev.relism.flash.ext.oidc.OidcAuthPolicy policy) Compiled authorization policy path used by annotation-driven mounting.optional()Silently populatesClaimsHolderif a valid bearer token or session cookie is present, but never rejects or redirects unauthenticated requests.protect()Validates the bearer token or session cookie.requireAnyScope(String... scopes) Requires at least one of the listed scopes to be present in the token.requireRole(String... roles) Likeprotect()but also enforces that the caller holds at least one of the given roles (OR semantics).requireScopes(String... scopes) Requires all listed scopes to be present in the token.
-
Method Details
-
protect
Validates the bearer token or session cookie. Browser clients are redirected to the login page on failure; API clients receive 401. -
optional
Silently populatesClaimsHolderif a valid bearer token or session cookie is present, but never rejects or redirects unauthenticated requests. Use this on public routes that want to personalise the response when the user happens to be logged in (e.g. showing a username on a landing page).app.get("/", handler, oidc.optional()); // Inside handler: ClaimsHolder.user() is non-null iff the user is logged in. -
authorize
Compiled authorization policy path used by annotation-driven mounting. The policy is immutable and built once at boot. -
requireRole
Likeprotect()but also enforces that the caller holds at least one of the given roles (OR semantics). Roles are extracted viaOidcConfig.rolesClaimPath(). -
requireScopes
Requires all listed scopes to be present in the token. Scopes are resolved from configured claim paths (default:scope,scp). -
requireAnyScope
Requires at least one of the listed scopes to be present in the token. Scopes are resolved from configured claim paths (default:scope,scp).
-