예제 #1
0
 /**
  * {@inheritDoc}
  * @return ControllerGuard
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $parentLocator = $serviceLocator->getServiceLocator();
     /* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
     $moduleOptions = $parentLocator->get('ZfcRbac\\Options\\ModuleOptions');
     /* @var \ZfcRbac\Service\RoleService $roleService */
     $roleService = $parentLocator->get('ZfcRbac\\Service\\RoleService');
     $controllerGuard = new ControllerGuard($roleService, $this->options);
     $controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy());
     return $controllerGuard;
 }
 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array|null $options
  * @return ControllerGuard
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if (null === $options) {
         $options = [];
     }
     /* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
     $moduleOptions = $container->get('ZfcRbac\\Options\\ModuleOptions');
     /* @var \ZfcRbac\Service\RoleService $roleService */
     $roleService = $container->get('ZfcRbac\\Service\\RoleService');
     $controllerGuard = new ControllerGuard($roleService, $options);
     $controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy());
     return $controllerGuard;
 }
예제 #3
0
 /**
  * @dataProvider controllerDataProvider
  */
 public function testControllerGranted(array $rules, $controller, $action, array $rolesConfig, $identityRole, $isGranted, $protectionPolicy)
 {
     $event = new MvcEvent();
     $routeMatch = $this->createRouteMatch(['controller' => $controller, 'action' => $action]);
     $event->setRouteMatch($routeMatch);
     $identity = $this->getMock('ZfcRbac\\Identity\\IdentityInterface');
     $identity->expects($this->any())->method('getRoles')->will($this->returnValue($identityRole));
     $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface');
     $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue($identity));
     $roleProvider = new InMemoryRoleProvider($rolesConfig);
     $roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());
     $controllerGuard = new ControllerGuard($roleService, $rules);
     $controllerGuard->setProtectionPolicy($protectionPolicy);
     $this->assertEquals($isGranted, $controllerGuard->isGranted($event));
 }