/** * @param \Zend\ServiceManager\AbstractPluginManager|ServiceLocatorInterface $serviceLocator * @return RouteGuard */ public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); /* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */ $moduleOptions = $parentLocator->get('ZfcRbac\\Options\\ModuleOptions'); /* @var \ZfcRbac\Service\AuthorizationService $authorizationService */ $authorizationService = $parentLocator->get('ZfcRbac\\Service\\AuthorizationService'); $guard = new ControllerPermissionsGuard($authorizationService, $this->options); $guard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); return $guard; }
/** * @dataProvider controllerDataProvider */ public function testControllerGranted(array $rules, $controller, $action, $identityPermissions, $isGranted, $protectionPolicy) { $routeMatch = $this->createRouteMatch(['controller' => $controller, 'action' => $action]); $authorizationService = $this->getMockAuthorizationService(); $authorizationService->expects($this->any())->method('isGranted')->will($this->returnValueMap($identityPermissions)); $controllerGuard = new ControllerPermissionsGuard($authorizationService, $rules); $controllerGuard->setProtectionPolicy($protectionPolicy); $event = new MvcEvent(); $event->setRouteMatch($routeMatch); $this->assertEquals($isGranted, $controllerGuard->isGranted($event)); }
/** * @param ContainerInterface $container * @param string $resolvedName * @param array|null $options * @return ControllerPermissionsGuard */ public function __invoke(ContainerInterface $container, $resolvedName, array $options = null) { if (null === $options) { $options = []; } /* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */ $moduleOptions = $container->get('ZfcRbac\\Options\\ModuleOptions'); /* @var \ZfcRbac\Service\AuthorizationService $authorizationService */ $authorizationService = $container->get('ZfcRbac\\Service\\AuthorizationService'); $guard = new ControllerPermissionsGuard($authorizationService, $options); $guard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); return $guard; }