public function isValid() { $account = $this->authenticationService->getAccountEntity(); if (!$account) { return false; } $permission = $this->resource . '.' . $this->permission; return $this->authorizationService->isGranted('account-' . $account->getId()->toString(), $permission); }
public function __invoke($permission, $assert = null, AccountInterface $account = null) { if ($account === null) { $account = $this->authenticationService->getAccountEntity(); } //$groups = $account->getGroups(); //var_dump($groups->count()); //exit; return $this->authorizationService->isGranted('account-' . $account->getId()->toString(), $permission, $assert); }
/** * * @param mixed $permission * @return boolean */ public function isGranted($permission) { if (!$this->identityRoles) { return false; } $isGranted = false; foreach ($this->identityRoles as $role) { if ($this->rbac->isGranted($role, $permission)) { $isGranted = true; break; } } return $isGranted; }
/** * @tesdox Test adding custom child roles works */ public function testAddCustomChildRole() { $role = $this->getMockForAbstractClass('Zend\\Permissions\\Rbac\\RoleInterface'); $this->rbac->setCreateMissingRoles(true)->addRole($role, array('parent')); $role->expects($this->any())->method('getName')->will($this->returnValue('customchild')); $role->expects($this->once())->method('hasPermission')->with('test')->will($this->returnValue(true)); $this->assertTrue($this->rbac->isGranted('parent', 'test')); }
public function testIsGrantedChildRoles() { $foo = new Rbac\Role('foo'); $bar = new Rbac\Role('bar'); $foo->addPermission('can.foo'); $bar->addPermission('can.bar'); $this->rbac->addRole($foo); $this->rbac->addRole($bar, $foo); $this->assertEquals(true, $this->rbac->isGranted('foo', 'can.bar')); $this->assertEquals(true, $this->rbac->isGranted('foo', 'can.foo')); $this->assertEquals(true, $this->rbac->isGranted('bar', 'can.bar')); $this->assertEquals(false, $this->rbac->isGranted('foo', 'can.baz')); $this->assertEquals(false, $this->rbac->isGranted('bar', 'can.baz')); }