Skip to content

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

Merged
Artur- merged 3 commits into
mainfrom
docs/keycloak-role-mapping
Sep 22, 2026
Merged

Artur- merged 3 commits into
mainfrom
docs/keycloak-role-mapping

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Documents the new opt-in Keycloak role mapping added in Vaadin 25.4. Keycloak puts user roles into the access token, so Spring Security ignores them and role checks fail silently; the docs now explain how to turn the mapping on.

What changed

Documentation only — no code, no behavior change.

OAuth2 guide (articles/flow/integrations/spring/oauth2.adoc): new "Keycloak Role Mapping" section that explains why Keycloak roles don't match by default, shows how to enable keycloakRoleMapping() on VaadinSecurityConfigurer, and lists the authorities the mapping grants (realm roles, client roles for the current client ID, SCOPE_ scopes, and the OidcUserAuthority). It also covers the role prefix, the JWKS requirement for decoding the access token, the fallback when no roles can be read, and the shared OidcUserService. A subsection shows how to use KeycloakOidcUserMapper directly when the application builds its own OidcUserService.

Configurer reference (articles/flow/security/vaadin-security-configurer.adoc): adds keycloakRoleMapping() to the configuration methods, and lists ClientRegistrationRepository and OidcUserService among the 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

github-actions Bot commented Sep 18, 2026

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 d21e154

@Artur-
Artur- requested a review from heruan September 18, 2026 13:26

@heruan heruan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches the Flow PR. Two wording points inline.

Step 6 of the SSO Kit migration guide (#5950, still open) explains the same thing. Once both are in, that step should link here instead of repeating it.

Comment thread articles/flow/integrations/spring/oauth2.adoc Outdated
Comment thread articles/flow/integrations/spring/oauth2.adoc Outdated
Keycloak puts the roles into the access token by default, not always: a
client scope mapper can add them to the ID token too. Without the
mapping, users are not rejected altogether, only the views and methods
that check a role deny access. The role prefix can also come from the
servletApi() configuration of the filter chain.

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

Copy link
Copy Markdown
Contributor Author

@heruan Agreed on the overlap with the migration guide. The section has a stable explicit anchor, keycloak-role-mapping, so once both are merged Step 6 can drop its explanation and xref <<{articles}/flow/integrations/spring/oauth2#keycloak-role-mapping,Keycloak Role Mapping>> instead. Leaving that change to the migration guide PR so this one stays self-contained.

@heruan heruan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on vaadin/flow#25627

@Artur-
Artur- merged commit 1c66232 into main Sep 22, 2026
10 checks passed
@Artur-
Artur- deleted the docs/keycloak-role-mapping branch September 22, 2026 10:32
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.

2 participants