-
Notifications
You must be signed in to change notification settings - Fork 185
feat!: Restrict access by default with Spring Security #21831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Test Results1 237 files ± 0 1 237 suites ±0 1h 14m 53s ⏱️ - 5m 38s Results for commit 38c1104. ± Comparison against base commit 7bc36c6. This pull request removes 1 and adds 14 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
@@ -0,0 +1 @@ | |||
Top secret restricted content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: shouldn't this be labelled feat! instead of chore! so that it's pick-uped by the release notes? It's really frustrating to look at git diff what has really happened between releases.. especially if something so important happens 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! I was just thinking that this change is not "valuable" enough to be called feature, but this is subjective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also call it fix! or include chore! in the release notes templates :) in the end I'm open for all options.. just no information is bad imho
Let's use this as example #21711 I had to bisect the last releases to check if this commit was released in there because it wasn't mentioned 😬
.requestMatchers(new AntPathRequestMatcher("/private")) | ||
.authenticated() | ||
.requestMatchers(new AntPathRequestMatcher("/admin")) | ||
.hasAnyRole(ROLE_ADMIN)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand why these additions are needed after removing authenticated()
from Vaadin web security. This SecurityConfig
is not based on Vaadin class so how changes there affect this configuration...Main question how it worked before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing authenticated()
request matcher, flow's access control is not called unless navigation happens via Flow API (e.g. from menu). Flow should apply authenticated()
request matcher for flow routes annotated with PermitAll
or RolesAllowed
automatically. This needs an update in VaadinSecurityConfigurer and VaadinWebSecurity.
AnonymousAllowed
has a request matcher already. DenyAll
should work already since access is denied by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated PR to do this now, but it might still need to also check parent layout annotations too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added check for parent layouts and auto-layout.
@@ -734,7 +734,9 @@ private AccessDeniedHandler createAccessDeniedHandler() { | |||
|
|||
private void customizeAuthorizeHttpRequests( | |||
AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { | |||
registry.requestMatchers(defaultPermitMatcher()).permitAll(); | |||
registry.requestMatchers(defaultPermitMatcher()).permitAll() | |||
.requestMatchers(getRequestUtil()::isAuthenticatedRoute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this should only be done if enableNavigationAccessControl
returns true. I don't wanna use your access control annotations in my application - wouldn't this require me to add them? (see your test where you had to add @permitAll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't require you to add them. but if you do add them, then they are noticed automatically by this request matcher.
You can also disable all default configuration of authorized requests (including this whole customizeAuthorizeHttpRequests method) with enableAuthorizedRequestsConfiguration
set to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and as isAuthenticatedRoute
is not actually calling navigation access control, we don't need to check enableNavigationAccessControl
here.
vaadin-spring/src/main/java/com/vaadin/flow/spring/security/RequestUtil.java
Outdated
Show resolved
Hide resolved
vaadin-spring/src/main/java/com/vaadin/flow/spring/security/RequestUtil.java
Outdated
Show resolved
Hide resolved
return false; | ||
} | ||
|
||
if (isAuthenticationNeeded(targetView)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method should also use NavigationAccessControl (if enabled) to determine if the route requires authentication. I'd say that at the very end it should return true if the NAC decision is DENY
or REJECT
.
This would take into account out-of-the-box AnnotatedViewAccessChecker
(if used, since checkers can be disabled) and custom access checker as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably simplify this by removing this annotation check and return true here if it's flow view. Then all flow views will go through access control in the end. Just need to test this once more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's rename the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, given that anonymous routes are already allowed before.
However, I think that the check should return true only if NAC is enabled, otherwise we cannot be sure if the view should be protected or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Flow routes with PermitAll or RolesAllowed annotation are checked by default with `.requestMatchers(requestUtil::isAuthenticatedRoute).authenticated()`. checkForBrowserErrors method in AbstractIT allows now 403 error for various tests.
Keeping 'routepathaccesschecker' in purpose using deprecated VaadinWebSecurity for now.
Added check for parent layouts and auto-layout.
All flow views are configured with authenticated() rule, not just PermitAll and RolesAllowed annotated routes. This will ensure that all configured access checkers are triggered for not-annotated views too.
vaadin-spring/src/main/java/com/vaadin/flow/spring/security/RequestUtil.java
Outdated
Show resolved
Hide resolved
|
Denies access to urls that have no request matcher in Spring Security config.
Fixes #17624