Repository navigation
docs: document the public route check phase for access checkers - #6730
totally-not-ai[bot] wants to merge 5 commits into
Conversation
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.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
💬 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
DENYfrom a checker makes the route non-public. If another checker allows it, the mixed result is aREJECT, which throws an exception in development mode.
navigation-access-control.adoc:165 · clarity
There was a problem hiding this comment.
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.
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6730.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 006868d |
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 theNavigationContext.Phasevalues, so authors of custom checkers had no documented way to tell this check apart from a check of the current user.What changed
sincebadge) under Customization.NAVIGATION,EVALUATIONandPUBLIC_ROUTE_CHECKphases returned bygetPhase().NAVIGATIONphase and is detected withisErrorHandling().defaultPermitMatcher()runs the check before the request reaches Vaadin, that only anALLOWdecision makes the route public, and that navigation still checks the actual user.NEUTRALinstead, as shown in a short snippet in the style of the error-handling one.DENYin this phase makes the route non-public, and that if another checker allows the view, the mixed result is aREJECT, which throws an exception outside production mode so the request fails before it reaches Vaadin.Test summary
NavigationContext,RequestUtil.isAnonymousRoute(),VaadinSecurityConfigurer.defaultPermitMatcher(),NavigationAccessControl,DefaultAccessCheckDecisionResolverand the built-in checkers in FlowWorking on behalf of @Artur-