Skip to content

docs: document the public route check phase for access checkers - #6730

Open
totally-not-ai[bot] wants to merge 5 commits into
mainfrom
docs/navigation-access-public-route-check
Open

totally-not-ai[bot] wants to merge 5 commits into
mainfrom
docs/navigation-access-public-route-check

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Navigation access checkers also run when Spring Security asks whether a route is public, with a context that has no user. The Navigation Access Control reference didn't explain this, nor NavigationContext.getPhase() and the NavigationContext.Phase values, so authors of custom checkers had no documented way to tell this check apart from a check of the current user.

What changed

  • Navigation Access Control: new "Public Route Check Phase" section (with a since badge) under Customization.
  • A table of the NAVIGATION, EVALUATION and PUBLIC_ROUTE_CHECK phases returned by getPhase().
  • Says that the check during error handling has the NAVIGATION phase and is detected with isErrorHandling().
  • Explains that the public-route request matcher in defaultPermitMatcher() runs the check before the request reaches Vaadin, that only an ALLOW decision makes the route public, and that navigation still checks the actual user.
  • Explains that the context has no principal and no roles, that the triggering request may come from a signed-in user, and that a checker shouldn't look up the user elsewhere. It can return NEUTRAL instead, as shown in a short snippet in the style of the error-handling one.
  • Says that a DENY in this phase makes the route non-public, and that if another checker allows the view, the mixed result is a REJECT, which throws an exception outside production mode so the request fails before it reaches Vaadin.
  • Building Apps, Protect Views: the sentence saying that the context contains the principal of the current user now notes the exception and links to the new section.

Test summary

  • Behavior checked against NavigationContext, RequestUtil.isAnonymousRoute(), VaadinSecurityConfigurer.defaultPermitMatcher(), NavigationAccessControl, DefaultAccessCheckDecisionResolver and the built-in checkers in Flow
  • Vale clean on changed lines (the only finding is the SourceCode suggestion for the inline snippet, the same as the existing error-handling snippet on the page)

Working on behalf of @Artur-

Navigation access checkers are also run when Spring Security asks
whether a route is public, with a context that has no user. The
reference did not explain this, nor NavigationContext.getPhase() and
its Phase values, so custom checkers had no documented way to tell
this check apart from a check of the current user.
The check during error handling has the NAVIGATION phase, and the
Building Apps guide said the context always holds the principal, which
isn't the case during the public route check.
@peholmst
peholmst marked this pull request as ready for review December 2, 2026 08:51

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the changes — left 1 comment.

Finding
💬 The section doesn't say what happens when a checker denies during the public route check.


In a Spring application, the request matcher for public routes runs the public route check. This matcher is part of [methodname]`defaultPermitMatcher()`, described in <<../spring/security-configuration#request-matchers,Request Matchers>>. Spring Security calls it for a request to a route path before the request reaches Vaadin. The matcher permits the request without authentication only if the final decision is `ALLOW`. Navigation access control still checks the access of the actual user when the view is opened.

In this phase, the context has no user: [methodname]`getPrincipal()` returns `null`, and [methodname]`hasRole()` returns `false` for every role. The request that triggers the check can come from a signed-in user. The result mustn't depend on who sent it. Therefore, a checker shouldn't look up the user anywhere else, such as in the security context of the request. A checker whose decision depends on the user can return a `NEUTRAL` result, and leave it to the other checkers to decide whether the view is public.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💬 The section doesn't say what happens when a checker denies during the public route check.

The guidance is phrased as an option: "A checker whose decision depends on the user can return a NEUTRAL result". A reader who instead denies on an @AnonymousAllowed view gets a mixed result (AnnotatedViewAccessChecker allows, the custom checker denies), which DefaultAccessCheckDecisionResolver turns into REJECT (DefaultAccessCheckDecisionResolver.java:141). NavigationAccessControl.checkAccess then throws IllegalStateException outside production mode (NavigationAccessControl.java:304-307), and because the call comes from the Spring Security request matcher, the request fails before it reaches Vaadin.

Consider adding one sentence after the NEUTRAL advice:

A DENY from a checker makes the route non-public. If another checker allows it, the mixed result is a REJECT, which throws an exception in development mode.

navigation-access-control.adoc:165 · clarity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the sentence after the NEUTRAL advice. It says that DENY makes the route non-public. If another checker allows the view, for example AnnotatedViewAccessChecker for an @AnonymousAllowed view, the mixed result is a REJECT, as described in the Decision Resolver section. Outside production mode, this throws an exception and the request fails before it reaches Vaadin. I checked this against DefaultAccessCheckDecisionResolver, NavigationAccessControl.checkAccess() and RequestUtil.isAnonymousRoute(), which passes the real production-mode flag.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

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

Changed pages

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

Built from 006868d

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.

1 participant