Skip to content

docs: document opt-in Keycloak role mapping for OAuth2 login - #6083

Open
totally-not-ai[bot] wants to merge 2 commits into
mainfrom
docs/keycloak-role-mapping
Open

totally-not-ai[bot] wants to merge 2 commits into
mainfrom
docs/keycloak-role-mapping

Conversation

@totally-not-ai

Copy link
Copy Markdown
Contributor

Summary

Keycloak sends user roles in the access token, which Spring Security does not read, so role checks fail for every user. This adds documentation for the new opt-in role mapping in Vaadin 25.4, which reads those roles and turns them into Spring Security authorities.

What changed

Docs only — no code, no behavior change.

  • New "Keycloak Role Mapping" section in the Spring OAuth2 article: why Keycloak roles don't work out of the box, how to turn the mapping on with keycloakRoleMapping(), and what authorities the mapping grants (realm roles, client roles for the current client ID, SCOPE_ authorities, and the OidcUserAuthority).
  • Explains that role names use the application's role prefix (ROLE_ by default, or whatever a GrantedAuthorityDefaults bean sets).
  • Notes the requirements and limits: the mapping needs oauth2LoginPage(), and it needs the provider's JWKS (from issuer-uri or an explicit jwk-set-uri). If the token can't be decoded, login still works but the user gets no roles.
  • New subsection for applications that build their own OidcUserService: use the KeycloakOidcUserMapper converter instead of keycloakRoleMapping(), with an optional custom role prefix.
  • VaadinSecurityConfigurer reference page: documents the keycloakRoleMapping() method and adds ClientRegistrationRepository and OidcUserService to the list of shared beans.

Documents vaadin/flow#25627

totally-not-ai Bot and others added 2 commits September 18, 2026 13:06
Keycloak puts realm and client roles into the access token, so Spring
Security maps neither and role checks silently fail. The new
VaadinSecurityConfigurer.keycloakRoleMapping() method opts a filter chain
in to mapping them, and KeycloakOidcUserMapper does the same for an
application that builds its own OidcUserService.

Documents vaadin/flow#25627

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…pping

The list of granted authorities read as exhaustive but left out the
OidcUserAuthority, which the mapper keeps like the default user service,
so enabling the mapping looked like it drops OIDC_USER. The JWK set URI
can also be configured directly instead of being resolved from the
issuer URI, and the abbreviation for a JSON Web Key Set is JWKS.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6083.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from e07df36

@Artur-
Artur- requested a review from heruan September 18, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants