From 1b6c8610278af036c0d627803e1e137453d9c8fa Mon Sep 17 00:00:00 2001 From: "Israel J. Carberry" Date: Tue, 26 Oct 2021 07:51:03 -0500 Subject: [PATCH] Support authentication manager --- .../Security/Factory/OAuthFactory.php | 19 +++++- .../Security/Factory/OAuthFactoryTest.php | 58 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Security/Factory/OAuthFactory.php b/DependencyInjection/Security/Factory/OAuthFactory.php index c638bcc3..3a54521a 100644 --- a/DependencyInjection/Security/Factory/OAuthFactory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -13,6 +13,7 @@ namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory; +use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -24,8 +25,24 @@ * * @author Arnaud Le Blanc */ -class OAuthFactory implements SecurityFactoryInterface +class OAuthFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface { + /** + * {@inheritdoc} + */ + public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId) + { + $providerId = 'fos_oauth_server.security.authentication.provider.'.$id; + $container + ->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.provider')) + ->replaceArgument(0, new Reference($userProviderId)) + ->replaceArgument(1, new Reference('security.user_checker.'.$id)) + ->replaceArgument(2, $id) + ; + + return $providerId; + } + /** * {@inheritdoc} */ diff --git a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php index 301e1712..feb81fc0 100644 --- a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php +++ b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php @@ -113,6 +113,64 @@ public function testCreate(): void ], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint)); } + public function testCreateAuthenticator(): void + { + $container = $this->getMockBuilder(ContainerBuilder::class) + ->disableOriginalConstructor() + ->setMethods([ + 'setDefinition', + ]) + ->getMock() + ; + $id = '12'; + $config = []; + $userProvider = 'mock.user.provider.service'; + + $definition = $this->getMockBuilder(Definition::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $container + ->expects($this->once()) + ->method('setDefinition') + ->with( + 'fos_oauth_server.security.authentication.provider.'.$id, + new ChildDefinition('fos_oauth_server.security.authentication.provider') + ) + ->will($this->returnValue($definition)) + ; + + $definition + ->expects($this->exactly(3)) + ->method('replaceArgument') + ->withConsecutive( + [ + 0, + new Reference($userProvider), + ], + [ + 1, + new Reference('security.user_checker.'.$id), + ], + [ + 2, + $id, + ] + ) + ->willReturnOnConsecutiveCalls( + $definition, + $definition, + $definition + ) + ; + + $this->assertSame( + 'fos_oauth_server.security.authentication.provider.'.$id, + $this->instance->createAuthenticator($container, $id, $config, $userProvider) + ); + } + public function testAddConfigurationDoesNothing(): void { $nodeDefinition = $this->getMockBuilder(NodeDefinition::class)