/**
  * @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');
     $routeGuard = new RoutePermissionsGuard($authorizationService, $this->options);
     $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy());
     return $routeGuard;
 }
예제 #2
0
 /**
  * @dataProvider routeDataProvider
  */
 public function testRoutePermissionGranted(array $rules, $matchedRouteName, array $identityPermissions, $isGranted, $protectionPolicy)
 {
     $routeMatch = new RouteMatch([]);
     $routeMatch->setMatchedRouteName($matchedRouteName);
     $event = new MvcEvent();
     $event->setRouteMatch($routeMatch);
     $authorizationService = $this->getMock('ZfcRbac\\Service\\AuthorizationServiceInterface', [], [], '', false);
     $authorizationService->expects($this->any())->method('isGranted')->will($this->returnValueMap($identityPermissions));
     $routeGuard = new RoutePermissionsGuard($authorizationService, $rules);
     $routeGuard->setProtectionPolicy($protectionPolicy);
     $this->assertEquals($isGranted, $routeGuard->isGranted($event));
 }
 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array|null $options
  * @return RoutePermissionsGuard
  */
 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\AuthorizationService $authorizationService */
     $authorizationService = $container->get('ZfcRbac\\Service\\AuthorizationService');
     $routeGuard = new RoutePermissionsGuard($authorizationService, $options);
     $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy());
     return $routeGuard;
 }