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

Rbac does not support Zend Navigation helper #199

Closed pimjansen closed 10 years ago

pimjansen commented 10 years ago

I added the ZfcRbac into my application and the guard is blocking my page correctly.

'zfc_rbac'                   => array(
    'guards'         => array(
        'ZfcRbac\Guard\RouteGuard' => array(
            'relation*' => array('relation'),
        ),
    ),
    'role_provider'  => array(
        'ZfcRbac\Role\InMemoryRoleProvider' => array(
            'relation' => array(
                'permissions' => array('view', 'edit', 'delete'),
            ),
        ),
    ),
),

The problem is that the ZF2 Navigation helper does not see the permissions on the page which means it will still show the page. This even though the guard is blocking it.

The ->getPermission() on the page returns null.

danizord commented 10 years ago

$page->getPermission() will return null unless you set the value. Not a zfc-rbac issue.

pimjansen commented 10 years ago

Can you tell me how to set it on the page itself? Its not really clear in the docs if you ask me? Isnt it a bit weird that the guard is blocking it even though the page itself does not know it?

danizord commented 10 years ago

IIRC, simply add a permission key to your page config.

pimjansen commented 10 years ago

Like in the Rbac settings above or in the router definitions?

'router'                     => array(
    'routes' => array(
        'relation'       => array(
            'type'       => 'Segment',
            'priority'   => 2000,
            'permission' => 'relation',
            'options'    => array(
                'route'      => '/relation[/:action][/:id][/:search]',
                'defaults'   => array(
                    'controller' => 'SenetRelation\Controller\RelationController',
                    'action'     => 'index',
                    'id'         => null,
                    'search'     => '',
                ),
            ),
        ),
    )
)
danizord commented 10 years ago

In navigation config.

bakura10 commented 10 years ago

I'm closing this. Zend\Navigation is a bit broken and ZfcRbac integration is not easy.

webdevilopers commented 10 years ago

What kind of integration do you recommend then if I would like to use Zend\Navigation with ZfcRbac - a listener like in the following example? http://stackoverflow.com/a/18942160/1937050

webdevilopers commented 10 years ago

I tried the example I posted above but the solution no longer seems to work @bakura10 @danizord : https://github.com/ZF-Commons/zfc-rbac/issues/237