-
Notifications
You must be signed in to change notification settings - Fork 111
Guards are not really aware of permissions #182
Comments
Here's my opinion on this one: Guards aware of roles is that does not make any sense to me. 😄
However, I know that the current implementation has some benefits
Finally, I think we can mantain the 2 approaches (role guards and permission guards). |
We should keep the capability to check role (for roles that are read-only, as |
Yeah I'm missing the permission check in guards as well - that makes them actually quite unusable for me. However it should be considered, that assertions won't work with guards and probably will throw an exception, if one checks a permission from a guard without context |
However, it is pretty easy to implement your own guard, that is aware of permissions and add it to the guardpm! |
The fact that a guard could be like "don't let any role that has the permission foo" is not really a problem to me. However I feel it really wrong about what we had before, that both roles AND permissions were evaluated. Maybe we could have a RoutePermissionGuard/ControllerPermissionGuard and RouteRoleGuard/ControllerRoleGuard. Thoughts? |
In fact I don't think so. How will you handle a route where you need the edit permission or admin role ? |
Say we can specify role and/or permission configuration. We should be able to optimize the test against role or permission. |
Okey, so basically, if we have no permissions set in the guards config, it uses the current mechanism, otherwise it do a full call to "isGranted" ? Please make a PR if you feel so. However I will be super strict regarding BC! :) |
almost... Does it work for "edit permission OR admin" ? => i'll have both permission and role in config. |
Mmhh this is pretty complicated if we need to take into account AND, OR... It would complicate quite a bit the guards implementation: 'ZfcRbac\Guard\RouteGuard' => [
'roles' => 'admin',
'permissions' => 'edit',
'expr' => RouteGuard::AND
] Something like that. But I really not sure if I want guards to be so complex. Once again my fear with that is that people will tend to use only guards then :(. |
Just OR : this is the simplest and most frequent. |
So try to do it and let's see the impl :). |
That feels wrong to me. Just assign I'm 👍 to |
Maybe the solution is to add a |
👍 I'm just upgrading from 0.2.3 and can't without this feature. We have a PROJECT_CREATE permission that should also apply to the |
I'm still a bit reluctant to include permissions into the guard logic. iirc someone (@jmleroux) needed to give it a try. |
Here's just a small snippet of our 0.2 setup, how else can we achieve this without permission support (besides a custom guard of course); array('route' => 'app/contact/create', 'permissions' => array(Permission::CONTACT_EDIT)),
array('route' => 'app/contact/*', 'permissions' => array(Permission::CONTACT_VIEW_ALL)),
array('route' => 'app/invoice/create', 'permissions' => array(Permission::INVOICE_EDIT)),
array('route' => 'app/invoice/*', 'permissions' => array(Permission::INVOICE_VIEW_ALL)),
array('route' => 'app/api/contact-note', 'roles' => array(Role::ROLE_USER)), |
Can't you role have the permissions instead ? Anyway... seing the config like this, maybe it makes sense... so if you want to try a PR, go on: ). |
It's probably worth mentioning that users create their own roles in our app with any number of different permissions. |
Closed by #238 |
Permissions are often the cornerstone of the previous authorzation systems i made with ZfcRbac.
At first glance, i thought that Guards "role only aware" would be fine, but finally I have a doubt.
I build an application with a classic Rbac system (even without role hierachy).
The administrators must be able to create roles and set permissions on this roles.
Current ZfcRbac can't handle the new roles out of the box, because roles are hard-coded in Guards configuration.
In old ZfcRbac (<1.0), i could set a route firewall with a permission condition. If a new role is created, it don't breaks the permission system.
With current ZfcRbac, roles AND permissions are doomed to be immutable.
@bakura10 and others, what is your opinion on this ?
The text was updated successfully, but these errors were encountered: