/**
  * {@inheritDoc}
  *
  * @return AssertionManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $assertionManagerConfig = [];
     if (isset($config['cmspermissions']['acl']['assertion_manager'])) {
         $assertionManagerConfig = $config['cmspermissions']['acl']['assertion_manager'];
     }
     $pluginManager = new AssertionManager(new Config($assertionManagerConfig));
     $pluginManager->setServiceLocator($serviceLocator);
     return $pluginManager;
 }
Example #2
0
 /**
  * @param string|array|AssertionInterface $assertion
  * @return null|AssertionInterface
  */
 protected function normalizeAssertion($assertion)
 {
     if (!$assertion) {
         return;
     }
     if ($assertion instanceof AssertionInterface) {
         return $assertion;
     }
     $assertion = (array) $assertion;
     if (count($assertion) > 1) {
         $assertionAggregate = new AssertionAggregate();
         foreach ($ruleData['assertion'] as $plugin) {
             if (is_string($plugin) && $this->assertionPluginManager->has($plugin)) {
                 $plugin = $this->assertionPluginManager->get($plugin);
             }
             if ($plugin instanceof AssertionInterface) {
                 $assertionAggregate->addAssertion($plugin);
             }
         }
         return $assertionAggregate;
     }
     $assertion = reset($assertion);
     if (!$assertion instanceof AssertionInterface) {
         if (is_string($assertion) && $this->assertionPluginManager->has($assertion)) {
             $assertion = $this->assertionPluginManager->get($assertion);
         } else {
             $assertion = null;
         }
     }
     return $assertion;
 }
Example #3
0
 /**
  * @param array $rule
  * @throws InvalidRuleException
  * @return Rule
  */
 protected function loadRule(array $rule)
 {
     switch (count($rule)) {
         case 4:
             list($roles, $resources, $privileges, $assertion) = $rule;
             if (is_string($assertion)) {
                 $assertion = $this->assertionPluginManager->get($assertion);
             }
             return new Rule($roles, $resources, $privileges, $assertion);
         case 3:
             list($roles, $resources, $privileges) = $rule;
             return new Rule($roles, $resources, $privileges);
         case 2:
             list($roles, $resources) = $rule;
             return new Rule($roles, $resources);
         default:
             throw new InvalidRuleException('Invalid rule definition: ' . print_r($rule, true));
     }
 }
Example #4
0
 /**
  * @depends testAddRole
  */
 public function testLoadResourceAssert()
 {
     $this->service->addRole('role1');
     $pluginManager = new AssertionManager();
     $pluginManager->setService('testAssert', new MockAssertion1());
     $mockStorage = $this->getMockBuilder('AclMan\\Storage\\Adapter\\ArrayAdapter\\ArrayAdapter')->disableOriginalConstructor()->setMethods(['hasResource', 'getPermissions', 'hasRole', 'getParentRoles'])->getMock();
     $mockStorage->expects($this->any())->method('hasResource')->will($this->returnValue(true));
     $permission = $this->getMockBuilder('AclMan\\Permission\\GenericPermission')->disableOriginalConstructor()->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId'])->getMock();
     $permission->expects($this->any())->method('getRoleId')->will($this->returnValue('role1'));
     $permission->expects($this->any())->method('getResourceId')->will($this->returnValue('resource1'));
     $permission->expects($this->any())->method('getPrivilege')->will($this->returnValue('view'));
     $permission->expects($this->any())->method('getAssertion')->will($this->returnValue('testAssert'));
     $permission->expects($this->any())->method('isAllow')->will($this->returnValue(false));
     $mockStorage->expects($this->any())->method('getPermissions')->will($this->returnValue([$permission]));
     $this->service->setStorage($mockStorage);
     $this->service->setPluginManager($pluginManager);
     $this->assertTrue($this->service->loadResource('role1', 'resource1'));
 }