Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Security] Allow using a callable with#[IsGranted]
#59150
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
#[IsGranted]
#[IsGranted]
b493c5d
tod1cd7c3
Comparesrc/Symfony/Component/Security/Core/Authorization/IsGrantedPayload.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
d1cd7c3
to6eedfaa
CompareThe WIP fix on |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/IsGrantedPayload.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/IsGrantedPayload.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
6eedfaa
toa28dcfd
CompareThank you for your feedbacks. I updated the PR. Also, I'm now using |
a28dcfd
toda421f7
Comparesrc/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Status: Needs Review |
I think the Attribute phpdoc and future docs should mention that only static closures are supported (for now). |
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/CallableVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
@chalasr supporting static closures only is not a limitation of our code. It is a limitation of PHP attributes. If PHP supports more closures (quite unlikely though, as I don't see how they would work), the code in Symfony would not require any change to support them. |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
3c1d6cd
to2dafa16
Compare2dafa16
to6ce5080
Compare6ce5080
to897ac91
CompareThere 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.
Some comments to improve the DX hopefully.
src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/Voter/ClosureVoter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
816c445
tof3cfa81
CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/AuthorizationCheckerInterface.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ClosureVoterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ClosureVoterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
f3cfa81
to30f3f4e
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
...y/Component/Security/Http/Tests/Fixtures/IsGrantedAttributeMethodsWithCallableController.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
54712d5
tod4bad72
CompareThere's one failure to check (at least on the windows build) |
d4bad72
toa53efbf
Comparea53efbf
to9c31038
CompareThank you@alexandre-daubois. |
ab6c611
intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
…kas)This PR was merged into the 7.3 branch.Discussion----------[Security] Improve DX of recent additions| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | not really| Deprecations? | no| Issues | -| License | MITThis is a follow up of#48142 and#59150 which were merged recently into 7.3.Summary of the changes:- `UserAuthorizationChecker`, the implementation of the corresponding interface is merged into the existing `AuthorizationChecker`.- `AuthorizationChecker::isGranted()` is made aware of token changed by its new `isGrantedForUser()` method, so that calls to `is_granted()` nested into `is_granted_for_user()` calls will check the provided user, not the logged in one.- Replace the many arguments passed to `IsGranted`'s closures by 1. a new `IsGrantedContext` and 2. the `$subject`. This makes everything simpler, easier to discover, and more extensible. Thanks to the previous item, IsGrantedContext only needs the auth-checker, not the access-decision-manager anymore. Simpler again.- Fix to the tests, those were broken in both PRs.Commits-------aa38eb8 [Security] Improve DX of recent additions
Uh oh!
There was an error while loading.Please reload this page.
Thanks tothe latest RFC that successfully passed for the next version of PHP, closures are now allowed in attributes. Symfony could leverage this at multiple places, especially where the ExpressionLanguage is currently used. What's nice is that, compared to expressions, closures can benefit from typing, autocomplete, etc. Way better for the DX.
This PR propose to leverage this new feature in
#[IsGranted]
, which would allow to write such code: