Beispiel #1
0
 public function initNavAcl(MvcEvent $e)
 {
     $acl = new \Zend\Permissions\Acl\Acl();
     $roles = (include __DIR__ . '\\config\\module.acl.roles.php');
     $allResources = array();
     foreach ($roles as $role => $resources) {
         $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
         $acl->addRole($role);
         $allResources = array_merge($resources, $allResources);
         //adding resources
         foreach ($resources as $resource) {
             // Edit 4
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
         }
         //adding restrictions
         foreach ($resources as $resource) {
             $acl->allow($role, $resource);
         }
     }
     //testing
     //echo var_dump($acl->isAllowed('ADMIN','logout'));
     // echo var_dump($acl->isAllowed('guest','logout'));
     //setting to view
     $e->getViewModel()->acl = $acl;
 }
Beispiel #2
0
 public function initAcl(MvcEvent $e)
 {
     $acl = new \Zend\Permissions\Acl\Acl();
     $acls = (include __DIR__ . '/../../config/autoload/acl.php');
     $allResources = array();
     $allRoles = array();
     foreach ($acls as $resource => $actions) {
         foreach ($actions as $action => $roles) {
             $resourceString = $resource . '/' . $action;
             if (!$acl->hasResource($resourceString)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resourceString));
             }
             foreach ($roles as $role) {
                 if (!in_array($role, $allRoles)) {
                     $allRoles[] = $role;
                     $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
                     $acl->addRole($role);
                 }
                 $acl->allow($role, $resourceString);
             }
         }
     }
     //setting to view
     $e->getViewModel()->acl = $acl;
 }
Beispiel #3
0
 public function initAcl(MvcEvent $e)
 {
     $acl = new \Zend\Permissions\Acl\Acl();
     $roles = (include __DIR__ . '/config/module.acl.roles.php');
     $allResources = array();
     foreach ($roles as $role => $resources) {
         $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
         $acl->addRole($role);
         //adding resources
         foreach ($resources as $resource) {
             // Edit 4
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
             $acl->allow($role, $resource);
         }
     }
     //setting to view
     $e->getViewModel()->acl = $acl;
 }
Beispiel #4
0
 public function testDefaultZendAclCaching()
 {
     /* @var $cache \Zend\Cache\Storage\StorageInterface */
     $cache = $this->aclService->getCacheStorage();
     $this->assertInstanceOf('\\Zend\\Cache\\Storage\\StorageInterface', $cache);
     /* @var $acl \Zend\Permissions\Acl\Acl */
     $acl = new \Zend\Permissions\Acl\Acl();
     $acl->addResource('resource01');
     $this->assertTrue($acl->hasResource('resource01'), 'ACL object should contain resource01 before caching');
     if ($cache->hasItem('acl_cached')) {
         $cache->removeItem('acl_cached');
     }
     // Test if the ACL gets cached properly.
     $cache->addItem('acl_cached', $acl);
     $this->assertTrue($cache->hasItem('acl_cached'), 'Cache should contain Acl object');
     /* @var $aclCached \Zend\Permissions\Acl\Acl */
     $aclCached = $cache->getItem('acl_cached');
     // Test if the ACL is in working order.
     $this->assertInstanceOf('\\Zend\\Permissions\\Acl\\Acl', $aclCached);
     $this->assertTrue($aclCached->hasResource('resource01'), 'ACL object should contain resource01 after caching');
     $cache->removeItem('acl_cached');
 }
Beispiel #5
0
 public function initAcl(MvcEvent $e)
 {
     $acl = new \Zend\Permissions\Acl\Acl();
     $roles = (include __DIR__ . '/config/module.acl.roles.php');
     $allResources = array();
     foreach ($roles as $role => $values) {
         $resources = $values['resources'];
         $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
         $acl->addRole($role, $values['inherits']);
         $allResources = array_merge($resources, $allResources);
         //Resources
         foreach ($resources as $resource) {
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
         }
         //Restrictions
         foreach ($resources as $resource) {
             $acl->allow($role, $resource);
         }
     }
     //setting to view
     $e->getViewModel()->acl = $acl;
 }
Beispiel #6
0
 /**
  * Initiate ACLs
  */
 public function initAcl(MvcEvent $e)
 {
     $acl = new \Zend\Permissions\Acl\Acl();
     $roles = (include dirname(dirname(__DIR__)) . '/config/acl.config.php');
     $allResources = array();
     foreach ($roles as $role => $resources) {
         $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
         $acl->addRole($role);
         $allResources = array_merge($resources, $allResources);
         //adding resources
         foreach ($resources as $resource) {
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
         }
         //adding restrictions
         foreach ($resources as $resource) {
             $acl->allow($role, $resource);
         }
     }
     //setting to view
     $e->getViewModel()->acl = $acl;
 }