From 5ea0f0edfab77cbf2935f770db266197d05c9699 Mon Sep 17 00:00:00 2001 From: "Israel J. Carberry" Date: Wed, 27 Oct 2021 20:08:03 -0500 Subject: [PATCH] Remove redundant token storage action --- .../Security/Factory/OAuthFactory.php | 5 ++--- Resources/config/security.xml | 1 - .../Authenticator/OAuthAuthenticator.php | 10 ---------- .../Security/Factory/OAuthFactoryTest.php | 9 ++------- .../Authenticator/OAuthAuthenticatorTest.php | 14 -------------- 5 files changed, 4 insertions(+), 35 deletions(-) diff --git a/DependencyInjection/Security/Factory/OAuthFactory.php b/DependencyInjection/Security/Factory/OAuthFactory.php index 90ed48de..e97ac786 100644 --- a/DependencyInjection/Security/Factory/OAuthFactory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -36,9 +36,8 @@ public function createAuthenticator(ContainerBuilder $container, string $id, arr $container ->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.authenticator')) ->replaceArgument(0, new Reference('fos_oauth_server.server')) - ->replaceArgument(1, new Reference('security.token_storage')) - ->replaceArgument(2, new Reference('security.user_checker.'.$id)) - ->replaceArgument(3, new Reference($userProviderId)) + ->replaceArgument(1, new Reference('security.user_checker.'.$id)) + ->replaceArgument(2, new Reference($userProviderId)) ; return $providerId; diff --git a/Resources/config/security.xml b/Resources/config/security.xml index a6b355e7..d2961b6d 100644 --- a/Resources/config/security.xml +++ b/Resources/config/security.xml @@ -14,7 +14,6 @@ - diff --git a/Security/Authentication/Authenticator/OAuthAuthenticator.php b/Security/Authentication/Authenticator/OAuthAuthenticator.php index 1ea627db..795f003e 100644 --- a/Security/Authentication/Authenticator/OAuthAuthenticator.php +++ b/Security/Authentication/Authenticator/OAuthAuthenticator.php @@ -20,7 +20,6 @@ use OAuth2\OAuth2ServerException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AccountStatusException; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -45,11 +44,6 @@ class OAuthAuthenticator implements AuthenticatorInterface */ protected $serverService; - /** - * @var TokenStorageInterface - */ - private $tokenStorage; - /** * @var UserCheckerInterface */ @@ -62,12 +56,10 @@ class OAuthAuthenticator implements AuthenticatorInterface public function __construct( OAuth2 $serverService, - TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker, UserProviderInterface $userProvider ) { $this->serverService = $serverService; - $this->tokenStorage = $tokenStorage; $this->userChecker = $userChecker; $this->userProvider = $userProvider; } @@ -161,8 +153,6 @@ public function createAuthenticatedToken(PassportInterface $passport, string $fi $token->setToken($credentials->getTokenString()); $token->setUser($user); - $this->tokenStorage->setToken($token); - return $token; } diff --git a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php index 3965693f..22daf5a8 100644 --- a/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php +++ b/Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php @@ -142,7 +142,7 @@ public function testCreateAuthenticator(): void ; $definition - ->expects($this->exactly(4)) + ->expects($this->exactly(3)) ->method('replaceArgument') ->withConsecutive( [ @@ -151,19 +151,14 @@ public function testCreateAuthenticator(): void ], [ 1, - new Reference('security.token_storage'), - ], - [ - 2, new Reference('security.user_checker.'.$id), ], [ - 3, + 2, new Reference($userProviderId), ] ) ->willReturnOnConsecutiveCalls( - $definition, $definition, $definition, $definition diff --git a/Tests/Security/Authentication/Authenticator/OAuthAuthenticatorTest.php b/Tests/Security/Authentication/Authenticator/OAuthAuthenticatorTest.php index ae83ba69..b8d66d66 100644 --- a/Tests/Security/Authentication/Authenticator/OAuthAuthenticatorTest.php +++ b/Tests/Security/Authentication/Authenticator/OAuthAuthenticatorTest.php @@ -21,7 +21,6 @@ use OAuth2\OAuth2AuthenticateException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\CredentialsExpiredException; use Symfony\Component\Security\Core\Exception\DisabledException; @@ -44,11 +43,6 @@ class OAuthAuthenticatorTest extends \PHPUnit\Framework\TestCase */ protected $serverService; - /** - * @var \PHPUnit\Framework\MockObject\MockObject|TokenStorageInterface - */ - protected $tokenStorage; - /** * @var \PHPUnit\Framework\MockObject\MockObject|User */ @@ -75,7 +69,6 @@ public function setUp(): void ]) ->getMock() ; - $this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->disableOriginalConstructor()->getMock(); $this->userChecker = $this->getMockBuilder(UserCheckerInterface::class)->disableOriginalConstructor()->getMock(); $this->userProvider = $this->getMockBuilder(UserProviderInterface::class)->disableOriginalConstructor()->getMock(); @@ -85,7 +78,6 @@ public function setUp(): void $this->authenticator = new OAuthAuthenticator( $this->serverService, - $this->tokenStorage, $this->userChecker, $this->userProvider ); @@ -263,12 +255,6 @@ public function testCreateAuthenticatedTokenWithValidPassport(): void ->will($this->returnValue(['ROLE_USER'])) ; - // expect a new authenticated token to be stored - $this->tokenStorage->expects($this->once()) - ->method('setToken') - ->with($this->isInstanceOf(OAuthToken::class)) - ; - // configure the passport $passport = new Passport( new UserBadge('test_user'),