diff --git a/DependencyInjection/Security/Factory/JWTFactory.php b/DependencyInjection/Security/Factory/JWTFactory.php index cfd35113..12a70e29 100644 --- a/DependencyInjection/Security/Factory/JWTFactory.php +++ b/DependencyInjection/Security/Factory/JWTFactory.php @@ -4,6 +4,7 @@ use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Component\Config\Definition\Builder\NodeDefinition; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; @@ -22,12 +23,12 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider, { $providerId = 'security.authentication.provider.jwt.' . $id; $container - ->setDefinition($providerId, new DefinitionDecorator($config['authentication_provider'])) + ->setDefinition($providerId, $this->createChildDefinition($config['authentication_provider'])) ->replaceArgument(0, new Reference($userProvider)); $listenerId = 'security.authentication.listener.jwt.' . $id; $container - ->setDefinition($listenerId, new DefinitionDecorator($config['authentication_listener'])) + ->setDefinition($listenerId, $this->createChildDefinition($config['authentication_listener'])) ->replaceArgument(2, $config); $entryPointId = $defaultEntryPoint; @@ -40,7 +41,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider, $authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor.' . $id; $container - ->setDefinition($authorizationHeaderExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.authorization_header_extractor')) + ->setDefinition($authorizationHeaderExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.authorization_header_extractor')) ->replaceArgument(0, $config['authorization_header']['prefix']) ->replaceArgument(1, $config['authorization_header']['name']); @@ -54,7 +55,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider, $queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor.' . $id; $container - ->setDefinition($queryParameterExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.query_parameter_extractor')) + ->setDefinition($queryParameterExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.query_parameter_extractor')) ->replaceArgument(0, $config['query_parameter']['name']); $container @@ -67,7 +68,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider, $cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor.' . $id; $container - ->setDefinition($cookieExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.cookie_extractor')) + ->setDefinition($cookieExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.cookie_extractor')) ->replaceArgument(0, $config['cookie']['name']); $container @@ -165,8 +166,17 @@ public function addConfiguration(NodeDefinition $node) protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint) { $entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.'.$id; - $container->setDefinition($entryPointId, new DefinitionDecorator('lexik_jwt_authentication.security.authentication.entry_point')); + $container->setDefinition($entryPointId, $this->createChildDefinition('lexik_jwt_authentication.security.authentication.entry_point')); return $entryPointId; } + + private function createChildDefinition($parent) + { + if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { + return new ChildDefinition($parent); + } + + return new DefinitionDecorator($parent); + } }