-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security][SecurityBundle] Implement ADM strategies as dedicated classes #42177
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
26b22a5
to
abe1c15
Compare
1524d5b
to
069864f
Compare
Hey! I think @aschempp has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php
Show resolved
Hide resolved
I wonder if you could simply reuse the |
Yeah, I thought about that too. But that'll give you very cryptic error messages if want to select one of the core strategies and make a typo.
I wouldn't do that. As long as you don't want to specify your own custom strategy, the DX is better with the old set of options. |
069864f
to
1e8af86
Compare
I just looked into the issue with a custom access decision manager. As far as I see, using a custom access decision strategy seems like an edge case only relevant in an app context, would you agree to that? If you simply replace the |
@aschempp Yes, you can basically hack this with a small compiler pass. This PR creates an official extension point for strategies and provides you with tools to test them. |
1e8af86
to
5733fa5
Compare
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.
Nice! Some comments, cosmetic only
src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php
Show resolved
Hide resolved
f70b38a
to
d2b8351
Compare
Signed-off-by: Alexander M. Turek <me@derrabus.de>
d2b8351
to
d25956a
Compare
Thank you @derrabus. |
…rabus) This PR was merged into the 5.4 branch. Discussion ---------- [Security] Document custom access decision managers Fixes #16032 Documents symfony/symfony#42177 Commits ------- 04ce795 Document custom access decision managers
Resolves deprecations added in symfony 5.4 (symfony/symfony#42177)
We currently allow to replace the access decision manager with a fully custom implementation. However, if the app makes use of that feature just because it needs a custom decision strategy, it also has to take care of wiring the voters into the custom implementation. This is a bit cumbersome.
This PR introduces a new interface
AccessDecisionStrategyInterface
that allows the app to implement a custom strategy that can be plugged into the default access decision manager. All built-in strategies have been migrated to that new interface.Furthermore, a new option is added to SecurityBundle to leverage this feature:
The "old" way of configuring the strategy will continue to work:
In that case, SecurityBundle will wire the new strategy classes for us, so we don't have to change anything in our app when upgrading to Symfony 5.4.
Additionally, I decided to finalize
AccessDecisionManager
because once the strategies are pluggable, there shouldn't be a use-case left for extending the class that could not be covered with a decorator.Implementing a custom strategy is straightforward. Your class implenting
AccessDecisionStrategyInterface
will receive a generator of voter results and is expected to return its decision as a boolean. This way, the interaction with the individual voters is abstracted away from the strategy and the strategy can stop the voter iteration whenever the decision is final.