B
B
bahek24627742014-10-28 00:40:57
Zend Framework
bahek2462774, 2014-10-28 00:40:57

Resources from DB - BjyAuthorize - Zend Framework 2?

I have a table of objects
object (id, name)
There is a controller with actions index, add, delete, edit
For ACL I use the BjyAuthorize module.
How can I make it so that all my objects (from the object table) are like "resources". those. for example groups: administrators and managers - I can give access to the first and second objects
1 | FirstObject
2 | SecondObject
and for example, editors and guests - to set access only to the 3rd and fourth objects?
3 | ThirdObject
4 | FourthObject

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shirshov Alexander, 2014-10-28
@bahek2462774

you can redefine the factory, in it you can take resources from anywhere.
and if books have already gone, then directly about access: ftp://help-master.net/temp/zend/ZF2Guard.pdf

N
Narek, 2014-11-06
@webtop

Here is my solution:

...
'resource_providers' => array(
            'AopAdmin\Provider\Resource\ObjectRepositoryProvider' => array(
                'resource_entity_class' => 'AopAdmin\Entity\AccessObject',
                'object_manager' => 'doctrine.entity_manager.orm_default',
            ),
        ),
...

<?php
namespace AopAdmin\Provider\Resource;

use BjyAuthorize\Provider\Resource\ProviderInterface;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;
use AopAdmin\Repository\AccessObjectRepository;

class ObjectRepositoryProvider implements ProviderInterface {
    /**
     * var AccessObjectRepository
     */
    protected $resourceRepository;

    /**
     * @param AccessObjectRepository $resourceRepository
     */
    public function __construct(AccessObjectRepository $resourceRepository){
        $this->resourceRepository = $resourceRepository;
    }

    /**
     * {@inheritDoc}
     */
    public function getResources(){
        $all = $this->resourceRepository->getAllWithModules();
        $resources = array();
        if (!empty($all)) {
            /* var $resource \AopAdmin\Entity\AccessObject */
            foreach($all as $resource){
                $resourcePermissions = $resource->getPermissions();
                if (empty($resourcePermissions)) {
                    continue;
                }
                /* var $permission \AopAdmin\Entity\Permission */
                foreach($resourcePermissions as $permission){
                    $resources[] = new Resource("controller/".$resource->getResourceName().":".$permission->getName());
                }
            }
        }
        return $resources;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question