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] Add ability for voters to explain their vote#59771
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
d664683
tofcc69a6
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.
Just a thought at first read:Vote
andAccessDecision
really look like value objects.
Should we make:
AccessDecision::isGranted
readonly and set with a constructor? The decision may not change when the object is created, and if so, a new instance may be created instead because that's another decision actually ;- The same thing for
Vote::$result
andVote::$voter
? Here again, if one of these property has to change after instantiation, then it may be more correct to create a new instance because this is not the "same" vote anymore.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.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.
@alexandre-daubois making the properties readonly would break the FC layer: setting the results multiple times is how an updated implementation can still give proper feedback when given a non-updated one (voters/access decision managers/strategies.) |
src/Symfony/Component/Security/Core/Authorization/Voter/Voter.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.
fae982d
to20e7b35
Comparetry { | ||
return $this->userSecurityChecker->isGrantedForUser($user, $attribute, $subject, $accessDecision); | ||
} catch (AuthenticationCredentialsNotFoundException) { | ||
return 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.
added for parity with isGranted() above
69264d6
to2f4b88e
CompareThis PR should be ready for review. Status: needs review |
src/Symfony/Component/Security/Core/Authorization/AccessDecision.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
public function __construct( | ||
private TokenStorageInterface $tokenStorage, | ||
private AccessDecisionManagerInterface $accessDecisionManager, | ||
) { | ||
} | ||
final public function isGranted(mixed $attribute, mixed $subject = null): bool | ||
final public function isGranted(mixed $attribute, mixed $subject = null, ?AccessDecision $accessDecision = null): bool |
nicolas-grekasFeb 14, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Note that wecould decide to not expose AccessDecision objects when using (User)AuthorizationCheckerInterface.
Any opinions on this?
Having the AccessDecision available toisGranted[ForUser]()
methods would allow userland to get the audit log more easily. It's also used right now inAbstractController::denyUnlessGranted()
, to compute a better error message. Using the AccessDecisionManager instead of the (User)AuthorizationChecker would be the alternative.
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.
Having it in(User)AuthorizationCheckerInterface
looks useful enough
2f4b88e
tobe530b6
Comparesrc/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
be530b6
to532bc37
Compare532bc37
toc6eb9ae
CompareWhat a ride for those PRs :) |
Thank you@nicolas-grekas. |
2962567
intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
kevinpapst commentedMay 12, 2025
The method |
We'd need benchmarks to consider any perf/mem issue here. To me, this should be negligible. |
j-schumann commentedMay 12, 2025
This is our primary/only reason why we wanted this feature. |
Uh oh!
There was an error while loading.Please reload this page.
This PR takes over#58107, which itself took over from#46493, etc.
It takes the only approach I could think of that would preserve BC.
The visible tip of what this achieves is:
Internally, this provides a new access audit log infrastructure that relies on new
AccessDecision
andVote
objects.Note that I didn't add (nor fix) tests for now. I'll borrow (and credit) from#58107 /#46493 as much as possible.