Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AccessDecisionManager can not be injected into Voter anymore #18554

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

Closed
gharlan opened this issue Apr 15, 2016 · 12 comments
Closed

AccessDecisionManager can not be injected into Voter anymore #18554

gharlan opened this issue Apr 15, 2016 · 12 comments

Comments

@gharlan
Copy link
Contributor

gharlan commented Apr 15, 2016

http://symfony.com/doc/master/cookbook/security/voters.html#checking-for-roles-inside-a-voter

This works with current release (3.0.4), but not with current master.
I get this error:

[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]

Circular reference detected for service "debug.security.access.decision_manager", path: "debug.security.access.decision_manager".

Reproducible by this branch of symfony-standard:
https://github.com/gharlan/symfony-standard/tree/voter-with-decision-manager

You can see the error in composer install (ScriptHandler::clearCache).

@linaori
Copy link
Contributor

linaori commented Apr 15, 2016

@gharlan can you verify if it does work without dev? I think the issue could be related to a service only loaded in dev. Possibly introduced in #17887, can you verify this?

/cc @javiereguiluz

@gharlan
Copy link
Contributor Author

gharlan commented Apr 15, 2016

can you verify if it does work without dev?

I can confirm this.

bin/console cache:clear --env=dev -> error
bin/console cache:clear --env=prod -> no error

@javiereguiluz
Copy link
Member

@iltar do you have any clue about how to fix this? Thanks!

@linaori
Copy link
Contributor

linaori commented Apr 15, 2016

@javiereguiluz I can't seem to find a fix for this just yet. I've encountered this issue myself for a completely other case (if I inject the ADM in my voter):

Circular reference detected for service "debug.security.access.decision_manager", path: "
   cache_warmer 
-> hostnet_webpack.bridge.cache_warmer 
-> hostnet_webpack.bridge.asset_compiler 
-> hostnet_webpack.bridge.asset_twig_parser 
-> twig 
-> security.authorization_checker 
-> debug.security.access.decision_manager 
-> app.security.voter.contract".

This one is created because of the SecurityExtension in the TwigBridge. If I lazy load the service by injecting the container here, it works fine and I get the above error.

I'm not entirely sure why that error is present, but this is in fact a circular reference. When creating the voter, it needs to inject the access decision manager and this one needs the voters. I'm curious how this can work in the first place.

Imo the access decision manager should not be directly accessible in another voter and the container should be injected instead. One option you could do is to wrap the container in an implementation using the designated ADM interface.

@HeahDude
Copy link
Contributor

See #18566, tested with the fork.

@ghost
Copy link

ghost commented Apr 20, 2016

Same issue here, hopefully to get a fast fix for this. I really like to use Symfony 3.1.* :)

@javiereguiluz
Copy link
Member

@JHGitty could you please test the fix proposed by @HeahDude in #18566? Thanks!

@ghost
Copy link

ghost commented Apr 20, 2016

@javiereguiluz The fix in #18566 works fine here. Please merge it! 👍

@hhamon
Copy link
Contributor

hhamon commented Apr 22, 2016

Is there any valid reason to have access to the ADM inside a voter? It does sound weird to me!

@javiereguiluz
Copy link
Member

@hhamon
Copy link
Contributor

hhamon commented Apr 22, 2016

For this use case I just inject the security.role_hierarchy service to get all reachable roles and iterate over it. No need for the whole ADM into the voter.

@javiereguiluz
Copy link
Member

@hhamon I still think that checking for votes is not done well in Symfony. I proposed some changes in #14048.

@fabpot fabpot closed this as completed Apr 28, 2016
fabpot added a commit that referenced this issue Apr 28, 2016
…HeahDude)

This PR was squashed before being merged into the 3.1-dev branch (closes #18566).

Discussion
----------

[SecurityBundle] fixed DebugAccessDecisionManager config

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18554
| License       | MIT
| Doc PR        | ~

Commits
-------

53c78fe [SecurityBundle] fixed DebugAccessDecisionManager config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants