Skip to content

Commit 2dfbd23

Browse files
Merge branch '4.4' into 5.0
* 4.4: (25 commits) [DoctrineBridge] Use new Types::* constants and support new json type [Debug][ErrorHandler] improved deprecation notices for methods new args and return type [BrowserKit] Nested file array prevents uploading file [ExpressionLanguage] Fixed collisions of character operators with object properties [Validator] Remove specific check for Valid targets [PhpUnitBridge] Use trait instead of extending deprecated class Fix versioned namespace clears fix remember me Use strict assertion in asset tests [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types Do not rely on the current locale when dumping a Graphviz object fix typo [Ldap] force default network timeout [Config] don't throw on missing excluded paths Docs: Typo, grammar [Validator] Add the missing translations for the Polish ("pl") locale [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662 [Routing] Add locale requirement for localized routes [Console] Inline exact-match handling with 4.4 Set previous exception when rethrown from controller resolver ...
2 parents c68520f + 6251c8e commit 2dfbd23

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Authentication/Provider/RememberMeAuthenticationProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1616
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1717
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
18+
use Symfony\Component\Security\Core\Exception\LogicException;
1819
use Symfony\Component\Security\Core\User\UserCheckerInterface;
20+
use Symfony\Component\Security\Core\User\UserInterface;
1921

2022
class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
2123
{
@@ -48,6 +50,11 @@ public function authenticate(TokenInterface $token)
4850
}
4951

5052
$user = $token->getUser();
53+
54+
if (!$token->getUser() instanceof UserInterface) {
55+
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)));
56+
}
57+
5158
$this->userChecker->checkPreAuth($user);
5259
$this->userChecker->checkPostAuth($user);
5360

Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
16+
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
1617
use Symfony\Component\Security\Core\Exception\DisabledException;
18+
use Symfony\Component\Security\Core\User\User;
1719

1820
class RememberMeAuthenticationProviderTest extends TestCase
1921
{
@@ -23,6 +25,7 @@ public function testSupports()
2325

2426
$this->assertTrue($provider->supports($this->getSupportedToken()));
2527
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
28+
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->disableOriginalConstructor()->getMock()));
2629
}
2730

2831
public function testAuthenticateWhenTokenIsNotSupported()
@@ -44,6 +47,17 @@ public function testAuthenticateWhenSecretsDoNotMatch()
4447
$provider->authenticate($token);
4548
}
4649

50+
public function testAuthenticateThrowsOnNonUserInterfaceInstance()
51+
{
52+
$this->expectException('Symfony\Component\Security\Core\Exception\LogicException');
53+
$this->expectExceptionMessage('Method "Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::getUser()" must return a "Symfony\Component\Security\Core\User\UserInterface" instance, "string" returned.');
54+
55+
$provider = $this->getProvider();
56+
$token = new RememberMeToken(new User('dummyuser', null), 'foo', 'test');
57+
$token->setUser('stringish-user');
58+
$provider->authenticate($token);
59+
}
60+
4761
public function testAuthenticateWhenPreChecksFails()
4862
{
4963
$this->expectException('Symfony\Component\Security\Core\Exception\DisabledException');

User/UserInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
* password (for checking against a submitted password), assigning roles
2020
* and so on.
2121
*
22-
* Regardless of how your user are loaded or where they come from (a database,
23-
* configuration, web service, etc), you will have a class that implements
24-
* this interface. Objects that implement this interface are created and
25-
* loaded by different objects that implement UserProviderInterface
22+
* Regardless of how your users are loaded or where they come from (a database,
23+
* configuration, web service, etc.), you will have a class that implements
24+
* this interface. Objects that implement this interface are created and
25+
* loaded by different objects that implement UserProviderInterface.
2626
*
2727
* @see UserProviderInterface
2828
*

0 commit comments

Comments
 (0)