Repository navigation
docs: fix the role names in the Secure React Views guide - #6623
Merged
Merged
Conversation
The role example in Secure React Views stripped the ROLE_ prefix in getRoles and wrote rolesAllowed: ["ADMIN"]. Client-side navigation worked, but Spring Security checks rolesAllowed against the granted authorities as they are when the page of a view with loginRequired loads, so an administrator who reloaded the view got 403 Forbidden. The guide now writes ROLE_ADMIN in rolesAllowed and hasAccess(), and keeps the authorities as they are, which agrees with the Role Names section of the View Access Control reference. The UserInfo record also generated Array<string | undefined>, so the getRoles example didn't type-check. The record now has a roles property in a @NullMarked package, which configureAuth() reads by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vaadin-review-bot
left a comment
There was a problem hiding this comment.
✅ Nothing to flag — the changes look good.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the role-based access example in Secure React Views (
articles/building-apps/react/security.adoc), a follow-up to #6622.Problems
ROLE_prefix ingetRolesand wroterolesAllowed: [ "ADMIN" ]. Client-side navigation and the menu worked. But when the page of a view withloginRequired: trueloads, Spring Security comparesrolesAllowedwith the granted authorities exactly, so an administrator who reloaded the view, or came back to it after logging in, got403 Forbidden. The underlying mismatch is reported as Page load of a React view checks rolesAllowed without the role prefix flow#26962. Related but separate: No redirect to /login if a user's role has no privileges flow#22280.getRolesexample didn't type-check.@NonNull Collection<String> authorities, in a package without@NullMarked, generatesauthorities: Array<string | undefined>, sos.startsWith(...)fails withTS18048: 's' is possibly 'undefined'. In dev mode the type-check overlay also covers the login form.Changes
UserInfois nowrecord UserInfo(String name, List<String> roles), plus apackage-info.javastep with@NullMarkedand a link to Type Nullability. The redundant@NonNullongetUserInfo()is gone.getRolescode:configureAuth()reads therolesproperty by default. The section links to the Authentication Context reference for user information that keeps its roles elsewhere.rolesAllowedandhasAccess()useROLE_ADMIN. The callout says what goes wrong without the prefix and links to Role Names in View Access Control, which recommends the same approach.The guide stays a how-to: the details are in the Flow reference pages it links to.
Testing
A scratch app on Vaadin 25.4.0-alpha5 and Spring Boot 4.1.2 (Spring Security 7), built from the guide's snippets as written. In-memory users:
admin(ADMIN, USER) anduser(USER).tsc --noEmitauth.tsroles: Array<string>,Promise<UserInfo>/admin/admin, then 403/admin?continue, view renders/admin/adminhasAccess()in account view/admin/login/adminhasAccess()in account viewVale reports nothing on the changed lines.
Not included
No
target/v25.3label. v25.3 has the same example, but the reference pages this change links to (flow/security/react-views/..., Type Nullability) don't exist there, since #6622 wasn't picked to v25.3. A v25.3 fix needs its own links, and verification on 25.3.🤖 Generated with Claude Code