From 20697942981ec4206b6ab4fe887c79add11208b6 Mon Sep 17 00:00:00 2001 From: "lukasz.barulski" Date: Tue, 29 Apr 2014 16:35:35 +0200 Subject: [PATCH] voter fixes --- DependencyInjection/Compiler/GateKeeperCompilerPass.php | 3 +++ DependencyInjection/Configuration.php | 3 +++ DependencyInjection/GateKeeperExtension.php | 1 + Resources/config/services.yml | 2 +- Voter/GateKeeper.php | 9 ++------- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/Compiler/GateKeeperCompilerPass.php b/DependencyInjection/Compiler/GateKeeperCompilerPass.php index c641fde..70b566f 100644 --- a/DependencyInjection/Compiler/GateKeeperCompilerPass.php +++ b/DependencyInjection/Compiler/GateKeeperCompilerPass.php @@ -27,6 +27,9 @@ public function process(ContainerBuilder $container) return; } + $definition = $container->getDefinition('gatekeeper.voter'); + $definition->addArgument(new Reference($container->getParameter('gatekeeper.provider.service'))); + $definition = $container->getDefinition('gatekeeper'); $definition->addArgument(new Reference($container->getParameter('gatekeeper.repository.service'))); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3dd1c4a..877bb16 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -24,6 +24,9 @@ public function getConfigTreeBuilder() ->scalarNode('repository_service') ->defaultValue('gatekeeper.repository.dummy') ->end() + ->scalarNode('provider_service') + ->defaultValue('gatekeeper.gates_provider.dummy') + ->end() ->end(); return $treeBuilder; diff --git a/DependencyInjection/GateKeeperExtension.php b/DependencyInjection/GateKeeperExtension.php index 89826cd..39125cc 100644 --- a/DependencyInjection/GateKeeperExtension.php +++ b/DependencyInjection/GateKeeperExtension.php @@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration($configuration, $configs); $container->setParameter('gatekeeper.repository.service', $config['repository_service']); + $container->setParameter('gatekeeper.provider.service', $config['provider_service']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 04d0f97..97c20f4 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -15,7 +15,7 @@ services: gatekeeper.voter: class: GateKeeperBundle\Voter\GateKeeper - arguments: [@gatekeeper, @gatekeeper.gates_provider.dummy] + arguments: [@gatekeeper] tags: - { name: security.voter } diff --git a/Voter/GateKeeper.php b/Voter/GateKeeper.php index c758545..3303f74 100644 --- a/Voter/GateKeeper.php +++ b/Voter/GateKeeper.php @@ -48,12 +48,7 @@ public function __construct(Keeper $gateKeeper, GatesProviderInterface $gatesPro */ public function supportsAttribute($attribute) { - if (null === $this->gates) - { - $this->gates = $this->gatesProvider->getGates(); - } - - return in_array($attribute, $this->gates); + return strpos($attribute, 'GATE_') === 0; } /** @@ -92,7 +87,7 @@ public function vote(TokenInterface $token, $object, array $attributes) } $user = $token->getUser() instanceof ObjectInterface ? $token->getUser() : null; - $attributes = is_array($object) ? $object : []; + $object = is_array($object) ? $object : []; if ($this->gateKeeper->hasAccess($attributes[0], $user, $object)) {