-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adding a new interface that give voters access to AccessDecisionManager #14550
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
…ement to be able to ask other voters
I just don't like doing any work in the __construct
There is a drawback with this implementation: any such voter creates a circular object graph, which hurts garbage collection. |
👍 |
Does it make sense to add a DI tag instead of this configuration-through-implements? |
@nicolas-grekas Do you mean give your voters an extra tag, and then a compiler pass will modify those service Definitions to have a |
That's true. An other idea trying to remove the circular dep: what about always injecting the AccessDecisionManager in a voting attribute? That would allow removing the new interface, and rely on the existing |
@nicolas-grekas That's really clever :). And actually, I think we can make it work technically. But, the "attributes" are what the user passes to I see a few options: a) Be ok with the circular reference. Afterall, you're opting into it Would any of these 3 options be acceptable? |
I see two valid options:
Since these are all services, my preference goes for 1. |
See #14733 |
@nicolas-grekas Fast and great reply. I'm closing this - your approach is superior and simpler. Thanks! |
…icolas-grekas) This PR was merged into the 2.8 branch. Discussion ---------- [Security] Add setVoters() on AccessDecisionManager | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | partially #12360 | License | MIT | Doc PR | - Alternative for #14550 Commits ------- 3fd7cea [Security] Add setVoters() on AccessDecisionManager
Hi guys!
Problem: From inside a voter, if you want to check an attribute from another voter, you can't do that easily. You need the
security.access.decision_manager
service, but injecting it (orsecurity.authorization_checker
) causes a circular reference exception. So, you need to inject the entire container.Solution: With this, if your voter implements the new
AccessDecisionManagerAwareInterface
, thensetAccessDecisionManager
is called on it beforevote()
.This allows code like:
Thanks!