Loading config/module.config.php +63 −45 Original line number Diff line number Diff line <?php /** * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize) * * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( 'bjyauthorize' => array( use Interop\Container\ContainerInterface; return [ 'bjyauthorize' => [ // default role for unauthenticated users 'default_role' => 'guest', Loading @@ -20,18 +16,18 @@ return array( // Role providers to be used to load all available roles into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'role_providers' => array(), 'role_providers' => [], // Resource providers to be used to load all available resources into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'resource_providers' => array(), 'resource_providers' => [], // Rule providers to be used to load all available rules into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'rule_providers' => array(), 'rule_providers' => [], // Guard listeners to be attached to the application event manager 'guards' => array(), 'guards' => [], // strategy service name for the strategy listener to be used when permission-related errors are detected 'unauthorized_strategy' => 'BjyAuthorize\View\UnauthorizedStrategy', Loading @@ -40,21 +36,21 @@ return array( 'template' => 'error/403', // cache options have to be compatible with Zend\Cache\StorageFactory::factory 'cache_options' => array( 'adapter' => array( 'cache_options' => [ 'adapter' => [ 'name' => 'memory', ), 'plugins' => array( ], 'plugins' => [ 'serializer', ) ), ] ], // Key used by the cache for caching the acl 'cache_key' => 'bjyauthorize_acl' ), ], 'service_manager' => array( 'factories' => array( 'service_manager' => [ 'factories' => [ 'BjyAuthorize\Cache' => 'BjyAuthorize\Service\CacheFactory', 'BjyAuthorize\CacheKeyGenerator' => 'BjyAuthorize\Service\CacheKeyGeneratorFactory', 'BjyAuthorize\Config' => 'BjyAuthorize\Service\ConfigServiceFactory', Loading @@ -81,37 +77,59 @@ return array( 'BjyAuthorize\View\UnauthorizedStrategy' => 'BjyAuthorize\Service\UnauthorizedStrategyServiceFactory', 'BjyAuthorize\Service\RoleDbTableGateway' => 'BjyAuthorize\Service\UserRoleServiceFactory', ), 'invokables' => array( ], 'invokables' => [ 'BjyAuthorize\View\RedirectionStrategy' => 'BjyAuthorize\View\RedirectionStrategy', ), 'aliases' => array( ], 'aliases' => [ 'bjyauthorize_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', ), 'initializers' => array( ], 'initializers' => [ 'BjyAuthorize\Service\AuthorizeAwareServiceInitializer' => 'BjyAuthorize\Service\AuthorizeAwareServiceInitializer' ), ), ], ], 'controller_plugins' => [ 'factories' => [ 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); 'view_manager' => array( 'template_map' => array( return new BjyAuthorize\Controller\Plugin\IsAllowed($authorize); } ], ], 'view_manager' => [ 'template_map' => [ 'error/403' => __DIR__ . '/../view/error/403.phtml', 'zend-developer-tools/toolbar/bjy-authorize-role' => __DIR__ . '/../view/zend-developer-tools/toolbar/bjy-authorize-role.phtml', ), ), ], ], 'view_helpers' => [ 'factories' => [ 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new \BjyAuthorize\View\Helper\IsAllowed($authorize); } ], ], 'zenddevelopertools' => array( 'profiler' => array( 'collectors' => array( 'zenddevelopertools' => [ 'profiler' => [ 'collectors' => [ 'bjy_authorize_role_collector' => 'BjyAuthorize\\Collector\\RoleCollector', ), ), 'toolbar' => array( 'entries' => array( ], ], 'toolbar' => [ 'entries' => [ 'bjy_authorize_role_collector' => 'zend-developer-tools/toolbar/bjy-authorize-role', ), ), ), ); ], ], ], ]; src/BjyAuthorize/Guard/AbstractGuard.php +12 −10 Original line number Diff line number Diff line Loading @@ -24,14 +24,14 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements /** * * @param array $rules * @param array $config * @param ServiceLocatorInterface $serviceLocator */ public function __construct(array $rules, ServiceLocatorInterface $serviceLocator) public function __construct(array $config, ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; $this->setConfig($rules); $this->setConfig($config); } /** Loading @@ -52,28 +52,30 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements */ public function processConfig() { $this->makeRules(); $this->rules = $this->makeRules(); } /** * * @return array */ protected function makeRules() { $rules = $this->config; $rules = []; foreach ($rules as $rule) { $rule['roles'] = (array) ($rule['roles'] ?? null); foreach ($this->config as $rule) { $rule['roles'] = (array) $rule['roles']; $rule['action'] = isset($rule['action']) ? (array) $rule['action'] : array(null); foreach ($this->extractResourcesFromRule($rule) as $resource) { $this->rules[$resource] = array('roles' => (array) $rule['roles']); $rules[$resource] = array('roles' => (array) $rule['roles']); if (isset($rule['assertion'])) { $this->rules[$resource]['assertion'] = $rule['assertion']; $rules[$resource]['assertion'] = $rule['assertion']; } } } return $rules; } abstract protected function extractResourcesFromRule(array $rule); Loading src/BjyAuthorize/Guard/Controller.php +0 −1 Original line number Diff line number Diff line Loading @@ -103,7 +103,6 @@ class Controller extends AbstractGuard /* @var $app \Zend\Mvc\ApplicationInterface */ $app = $event->getTarget(); // $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event); $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $app->getEventManager()->triggerEvent($event); } Loading src/BjyAuthorize/Guard/Route.php +0 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ class Route extends AbstractGuard /* @var $app \Zend\Mvc\Application */ $app = $event->getTarget(); // $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event); $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $app->getEventManager()->triggerEvent($event); } Loading src/BjyAuthorize/Module.php +1 −40 Original line number Diff line number Diff line Loading @@ -2,14 +2,11 @@ namespace BjyAuthorize; use Interop\Container\ContainerInterface; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventInterface; use Zend\ModuleManager\Feature\AutoloaderProviderInterface; use Zend\ModuleManager\Feature\BootstrapListenerInterface; use Zend\ModuleManager\Feature\ConfigProviderInterface; use Zend\ModuleManager\Feature\ControllerPluginProviderInterface; use Zend\ModuleManager\Feature\ViewHelperProviderInterface; /** * BjyAuthorize Module Loading @@ -19,9 +16,7 @@ use Zend\ModuleManager\Feature\ViewHelperProviderInterface; class Module implements AutoloaderProviderInterface, BootstrapListenerInterface, ConfigProviderInterface, ControllerPluginProviderInterface, ViewHelperProviderInterface ConfigProviderInterface { /** * {@inheritDoc} Loading @@ -45,40 +40,6 @@ class Module implements $strategy->attach($app->getEventManager()); } /** * {@inheritDoc} */ public function getViewHelperConfig() { return array( 'factories' => array( 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new View\Helper\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ public function getControllerPluginConfig() { return array( 'factories' => array( 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new Controller\Plugin\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ Loading Loading
config/module.config.php +63 −45 Original line number Diff line number Diff line <?php /** * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize) * * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( 'bjyauthorize' => array( use Interop\Container\ContainerInterface; return [ 'bjyauthorize' => [ // default role for unauthenticated users 'default_role' => 'guest', Loading @@ -20,18 +16,18 @@ return array( // Role providers to be used to load all available roles into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'role_providers' => array(), 'role_providers' => [], // Resource providers to be used to load all available resources into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'resource_providers' => array(), 'resource_providers' => [], // Rule providers to be used to load all available rules into Zend\Permissions\Acl\Acl // Keys are the provider service names, values are the options to be passed to the provider 'rule_providers' => array(), 'rule_providers' => [], // Guard listeners to be attached to the application event manager 'guards' => array(), 'guards' => [], // strategy service name for the strategy listener to be used when permission-related errors are detected 'unauthorized_strategy' => 'BjyAuthorize\View\UnauthorizedStrategy', Loading @@ -40,21 +36,21 @@ return array( 'template' => 'error/403', // cache options have to be compatible with Zend\Cache\StorageFactory::factory 'cache_options' => array( 'adapter' => array( 'cache_options' => [ 'adapter' => [ 'name' => 'memory', ), 'plugins' => array( ], 'plugins' => [ 'serializer', ) ), ] ], // Key used by the cache for caching the acl 'cache_key' => 'bjyauthorize_acl' ), ], 'service_manager' => array( 'factories' => array( 'service_manager' => [ 'factories' => [ 'BjyAuthorize\Cache' => 'BjyAuthorize\Service\CacheFactory', 'BjyAuthorize\CacheKeyGenerator' => 'BjyAuthorize\Service\CacheKeyGeneratorFactory', 'BjyAuthorize\Config' => 'BjyAuthorize\Service\ConfigServiceFactory', Loading @@ -81,37 +77,59 @@ return array( 'BjyAuthorize\View\UnauthorizedStrategy' => 'BjyAuthorize\Service\UnauthorizedStrategyServiceFactory', 'BjyAuthorize\Service\RoleDbTableGateway' => 'BjyAuthorize\Service\UserRoleServiceFactory', ), 'invokables' => array( ], 'invokables' => [ 'BjyAuthorize\View\RedirectionStrategy' => 'BjyAuthorize\View\RedirectionStrategy', ), 'aliases' => array( ], 'aliases' => [ 'bjyauthorize_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', ), 'initializers' => array( ], 'initializers' => [ 'BjyAuthorize\Service\AuthorizeAwareServiceInitializer' => 'BjyAuthorize\Service\AuthorizeAwareServiceInitializer' ), ), ], ], 'controller_plugins' => [ 'factories' => [ 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); 'view_manager' => array( 'template_map' => array( return new BjyAuthorize\Controller\Plugin\IsAllowed($authorize); } ], ], 'view_manager' => [ 'template_map' => [ 'error/403' => __DIR__ . '/../view/error/403.phtml', 'zend-developer-tools/toolbar/bjy-authorize-role' => __DIR__ . '/../view/zend-developer-tools/toolbar/bjy-authorize-role.phtml', ), ), ], ], 'view_helpers' => [ 'factories' => [ 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new \BjyAuthorize\View\Helper\IsAllowed($authorize); } ], ], 'zenddevelopertools' => array( 'profiler' => array( 'collectors' => array( 'zenddevelopertools' => [ 'profiler' => [ 'collectors' => [ 'bjy_authorize_role_collector' => 'BjyAuthorize\\Collector\\RoleCollector', ), ), 'toolbar' => array( 'entries' => array( ], ], 'toolbar' => [ 'entries' => [ 'bjy_authorize_role_collector' => 'zend-developer-tools/toolbar/bjy-authorize-role', ), ), ), ); ], ], ], ];
src/BjyAuthorize/Guard/AbstractGuard.php +12 −10 Original line number Diff line number Diff line Loading @@ -24,14 +24,14 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements /** * * @param array $rules * @param array $config * @param ServiceLocatorInterface $serviceLocator */ public function __construct(array $rules, ServiceLocatorInterface $serviceLocator) public function __construct(array $config, ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; $this->setConfig($rules); $this->setConfig($config); } /** Loading @@ -52,28 +52,30 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements */ public function processConfig() { $this->makeRules(); $this->rules = $this->makeRules(); } /** * * @return array */ protected function makeRules() { $rules = $this->config; $rules = []; foreach ($rules as $rule) { $rule['roles'] = (array) ($rule['roles'] ?? null); foreach ($this->config as $rule) { $rule['roles'] = (array) $rule['roles']; $rule['action'] = isset($rule['action']) ? (array) $rule['action'] : array(null); foreach ($this->extractResourcesFromRule($rule) as $resource) { $this->rules[$resource] = array('roles' => (array) $rule['roles']); $rules[$resource] = array('roles' => (array) $rule['roles']); if (isset($rule['assertion'])) { $this->rules[$resource]['assertion'] = $rule['assertion']; $rules[$resource]['assertion'] = $rule['assertion']; } } } return $rules; } abstract protected function extractResourcesFromRule(array $rule); Loading
src/BjyAuthorize/Guard/Controller.php +0 −1 Original line number Diff line number Diff line Loading @@ -103,7 +103,6 @@ class Controller extends AbstractGuard /* @var $app \Zend\Mvc\ApplicationInterface */ $app = $event->getTarget(); // $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event); $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $app->getEventManager()->triggerEvent($event); } Loading
src/BjyAuthorize/Guard/Route.php +0 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ class Route extends AbstractGuard /* @var $app \Zend\Mvc\Application */ $app = $event->getTarget(); // $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event); $event->setName(MvcEvent::EVENT_DISPATCH_ERROR); $app->getEventManager()->triggerEvent($event); } Loading
src/BjyAuthorize/Module.php +1 −40 Original line number Diff line number Diff line Loading @@ -2,14 +2,11 @@ namespace BjyAuthorize; use Interop\Container\ContainerInterface; use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventInterface; use Zend\ModuleManager\Feature\AutoloaderProviderInterface; use Zend\ModuleManager\Feature\BootstrapListenerInterface; use Zend\ModuleManager\Feature\ConfigProviderInterface; use Zend\ModuleManager\Feature\ControllerPluginProviderInterface; use Zend\ModuleManager\Feature\ViewHelperProviderInterface; /** * BjyAuthorize Module Loading @@ -19,9 +16,7 @@ use Zend\ModuleManager\Feature\ViewHelperProviderInterface; class Module implements AutoloaderProviderInterface, BootstrapListenerInterface, ConfigProviderInterface, ControllerPluginProviderInterface, ViewHelperProviderInterface ConfigProviderInterface { /** * {@inheritDoc} Loading @@ -45,40 +40,6 @@ class Module implements $strategy->attach($app->getEventManager()); } /** * {@inheritDoc} */ public function getViewHelperConfig() { return array( 'factories' => array( 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new View\Helper\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ public function getControllerPluginConfig() { return array( 'factories' => array( 'isAllowed' => function (ContainerInterface $container) { /* @var $authorize \BjyAuthorize\Service\Authorize */ $authorize = $container->get('BjyAuthorize\Service\Authorize'); return new Controller\Plugin\IsAllowed($authorize); } ), ); } /** * {@inheritDoc} */ Loading