From ea7ad5ac623f412d81526e4edfaa7aa2774a98eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4fer?= Date: Sun, 16 Feb 2020 17:40:22 +0100 Subject: [PATCH 1/2] Docs: Typo, grammar --- User/UserInterface.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/User/UserInterface.php b/User/UserInterface.php index 58f6cfb3..fdad6b05 100644 --- a/User/UserInterface.php +++ b/User/UserInterface.php @@ -21,10 +21,10 @@ * password (for checking against a submitted password), assigning roles * and so on. * - * Regardless of how your user are loaded or where they come from (a database, - * configuration, web service, etc), you will have a class that implements - * this interface. Objects that implement this interface are created and - * loaded by different objects that implement UserProviderInterface + * Regardless of how your users are loaded or where they come from (a database, + * configuration, web service, etc.), you will have a class that implements + * this interface. Objects that implement this interface are created and + * loaded by different objects that implement UserProviderInterface. * * @see UserProviderInterface * @see AdvancedUserInterface From fa043123e7800efa2161d617332fa157f39a3dbd Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 19 Feb 2020 20:56:03 +0100 Subject: [PATCH 2/2] fix remember me --- .../Provider/RememberMeAuthenticationProvider.php | 7 +++++++ .../RememberMeAuthenticationProviderTest.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Authentication/Provider/RememberMeAuthenticationProvider.php b/Authentication/Provider/RememberMeAuthenticationProvider.php index d9a6883c..e1a22b79 100644 --- a/Authentication/Provider/RememberMeAuthenticationProvider.php +++ b/Authentication/Provider/RememberMeAuthenticationProvider.php @@ -15,7 +15,9 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; +use Symfony\Component\Security\Core\Exception\LogicException; use Symfony\Component\Security\Core\User\UserCheckerInterface; +use Symfony\Component\Security\Core\User\UserInterface; class RememberMeAuthenticationProvider implements AuthenticationProviderInterface { @@ -49,6 +51,11 @@ public function authenticate(TokenInterface $token) } $user = $token->getUser(); + + if (!$token->getUser() instanceof UserInterface) { + throw new LogicException(sprintf('Method "%s::getUser()" must return a "%s" instance, "%s" returned.', \get_class($token), UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user))); + } + $this->userChecker->checkPreAuth($user); $this->userChecker->checkPostAuth($user); diff --git a/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php b/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php index 418cd77d..ce050226 100644 --- a/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php +++ b/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php @@ -13,8 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider; +use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken; use Symfony\Component\Security\Core\Exception\DisabledException; use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\User\User; class RememberMeAuthenticationProviderTest extends TestCase { @@ -24,6 +26,7 @@ public function testSupports() $this->assertTrue($provider->supports($this->getSupportedToken())); $this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); + $this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->disableOriginalConstructor()->getMock())); } public function testAuthenticateWhenTokenIsNotSupported() @@ -45,6 +48,17 @@ public function testAuthenticateWhenSecretsDoNotMatch() $provider->authenticate($token); } + public function testAuthenticateThrowsOnNonUserInterfaceInstance() + { + $this->expectException('Symfony\Component\Security\Core\Exception\LogicException'); + $this->expectExceptionMessage('Method "Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::getUser()" must return a "Symfony\Component\Security\Core\User\UserInterface" instance, "string" returned.'); + + $provider = $this->getProvider(); + $token = new RememberMeToken(new User('dummyuser', null), 'foo', 'test'); + $token->setUser('stringish-user'); + $provider->authenticate($token); + } + public function testAuthenticateWhenPreChecksFails() { $this->expectException('Symfony\Component\Security\Core\Exception\DisabledException');