-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[Security] Use the is_granted
expression to keep consistency with php example above
#4282
Conversation
…above As `has_role` only check for roles without calling the voter, it does not do the same job that `$this->get('security.context')->isGranted('ROLE_ADMIN')` So it is quiete confusing.
Nope, it does not a a simple in_array check. It still supports the role hierarchy. So the vote for roles is still the same. However, it is true that |
I guess you're right. I read the code on branch 2.5: I just see on master, it looks to be changed. Indeed my point was about the custom voters not called. |
I'm 👍 thanks @tyx ! |
If we are going to use So:
Thanks! |
Given that this place is documenting the FrameworkExtraBundle annotation, it is fine
This is wrong. |
@stof Ah, thanks for those details! Could we make |
@weaverryan no we cannot. A voter cannot have access to the full authentication system. It is a circular dependency. |
So what about the changes @weaverryan asked ? Should I only add mention about |
Yes, I think we should, and I think we should use it where we can. I don't understand yet why it can't also be made to work under access_control, but I admit I'm totally ignorant to the implementation :). I have homework to look into that further. @tyx if I'm being unclear or if you have any questions, let me know! |
@weaverryan this is because the access_control uses the security system. Expression used there at evaluated by a voter, which then cannot have access to the full AuthorizationManager given that it would create a circular dependency. |
I updated the PR with Let me know if there is another modification needed. |
@@ -1786,6 +1786,8 @@ Additionally, you have access to a number of functions inside the expression: | |||
see below; | |||
* ``has_role``: Checks to see if the user has the given role - equivalent | |||
to an expression like ``'ROLE_ADMIN' in roles``. | |||
* ``is_granted``: Similar to the php code like `$securityContext->isGranted('ROLE_USER')`. | |||
Unlike `has_role` expression, `is_granted` will call your custom voters if defined. |
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.
You'll have to indent this line by two spaces to make it part of the list item.
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.
done !
81d44ca
to
f96aca8
Compare
@@ -1786,6 +1786,8 @@ Additionally, you have access to a number of functions inside the expression: | |||
see below; | |||
* ``has_role``: Checks to see if the user has the given role - equivalent | |||
to an expression like ``'ROLE_ADMIN' in roles``. | |||
* ``is_granted``: Similar to the php code like `$securityContext->isGranted('ROLE_USER')`. | |||
Unlike `has_role` expression, `is_granted` will call your custom voters if defined. |
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.
I would add something like "(this can ony be used in the @Security
annotation)" at the end of this item, to warn users and avoid confusion.
As
has_role
expression only check for roles (simplein_array
) without calling theAccessDecisionManager
, it does not do the same job that$this->get('security.context')->isGranted('ROLE_ADMIN')
used in the php example just above.It is quiete confusing.