Package dev.relism.flash.ext.oidc
Class OidcUser
java.lang.Object
dev.relism.flash.ext.oidc.OidcUser
Type-safe view over the JWT claims stored in
ClaimsHolder.
Obtainable from any protected context via ClaimsHolder.user().
Class-based handlers that extend the SessionHandler hierarchy already
have a provisioned DB user in currentUser; OidcUser complements
that by giving access to the raw OIDC claims when needed, and is the primary
API for lambda routes.
// Lambda route (OidcMiddleware injected):
app.get("/api/whoami", (req, res) -> {
OidcUser u = ClaimsHolder.user();
return Map.of("sub", u.sub(), "email", u.email(), "roles", u.roles("realm_access.roles"), "scopes", u.scopes());
}, oidcMw.protect());
// Class-based handler (currentUser is the DB entity; oidcUser() for raw claims):
protected Object handleAuthenticated(Request req, Response res) throws Exception {
OidcUser u = oidcUser(); // same as ClaimsHolder.user()
return json(res, currentUser); // DB entity — provisioned from OIDC sub
}
-
Method Summary
Modifier and TypeMethodDescriptionReturns the raw claim value, ornullif absent.<T> TReturns the value of any claim, cast toT.claims()Escape hatch — returns the full unmodified claims map.email()User's email address (emailclaim).booleanReturnstrueif the user holdsroleat the given claim path.booleanReturnstrueif the user hasscope, searching default claim pathsscope,scp.booleanReturnstrueif the user hasscopein any ofclaimPaths.name()Full display name (nameclaim).Extracts the roles list by traversing a dot-separated claim path.scopes()Resolves OAuth2 scopes from standard OIDC/OAuth claims using fallback order:scopethenscp.Resolves scopes from comma-separated claim paths (example:"scope,scp,permissions.scopes").sub()Subject identifier — unique, stable user ID issued by the provider.username()Human-readable username (preferred_usernameclaim).
-
Method Details
-
sub
Subject identifier — unique, stable user ID issued by the provider. -
email
User's email address (emailclaim). -
username
Human-readable username (preferred_usernameclaim). -
name
Full display name (nameclaim). -
roles
Extracts the roles list by traversing a dot-separated claim path.Example paths:
"realm_access.roles"— Keycloak realm roles"resource_access.my-client.roles"— Keycloak client roles"groups"— Authelia / generic IdPs
- Returns:
- list of role strings, or an empty list if the path doesn't exist
-
hasRole
Returnstrueif the user holdsroleat the given claim path. -
scopes
Resolves OAuth2 scopes from standard OIDC/OAuth claims using fallback order:scopethenscp. Supports both space-separated string and list forms. -
scopes
Resolves scopes from comma-separated claim paths (example:"scope,scp,permissions.scopes"). -
hasScope
Returnstrueif the user hasscope, searching default claim pathsscope,scp. -
hasScope
Returnstrueif the user hasscopein any ofclaimPaths. -
claim
Returns the value of any claim, cast toT.- Throws:
ClassCastException- if the stored value is not assignable totype
-
claim
Returns the raw claim value, ornullif absent. -
claims
Escape hatch — returns the full unmodified claims map.
-