ZF-Commons / zfc-rbac

Role-based access control module to provide additional features on top of Zend\Permissions\Rbac
BSD 3-Clause "New" or "Revised" License
181 stars 111 forks source link

Protection Policy at Guard Level #263

Open davidwindell opened 10 years ago

davidwindell commented 10 years ago

I have two route guards - role and permission based.

I already have the role guards setup with a default DENY policy, but with two guards it doesn't make sense to have them both denying, I would like the be able to make permissions ALLOW by default.

davidwindell commented 10 years ago

@bakura10 I was able to achieve this with the below (not a real life example), but it's a bit hacky. Essentially my permission route guard has a wildcard which affects any routes not mentioned above this. That way, the role guard operates in DENY mode, whereas the permission guard operates in a pseudo ALLOW mode

'zfc_rbac' => [
    'protection_policy' => GuardInterface::POLICY_DENY,
    'guards' => [
        'ZfcRbac\Guard\RouteGuard' => [
            'app/calendar' => Role::EVENT_MANAGER,
        ],
        'ZfcRbac\Guard\RoutePermissionsGuard' => [
            'app/something*' => Permission::ALLOW_THIS,
            '*' => '*',
        ]
    ]
]

EDIT This only works when the order is correct, so merging multiple configs leaves the wildcard rule above others which breaks the hack.

davidwindell commented 10 years ago

I'm not sure how this would look in practice...perhaps the below as an option? Retaining the old method as a default for BC and ease of config?

'zfc_rbac' => [
    'protection_policy' => GuardInterface::POLICY_DENY,
    'guards' => [
        'ZfcRbac\Guard\RouteGuard' => [
            'app/calendar' => Role::EVENT_MANAGER,
        ],
        'ZfcRbac\Guard\RoutePermissionsGuard' => [
            'protection_policy' => GuardInterface::POLICY_ALLOW,
            'rules' => [
                'app/something*' => Permission::ALLOW_THIS,
                '*' => '*',
            ]
        ]
    ]
]

What do you think?

jmleroux commented 10 years ago

Could be interesting. ping @bakura10