8000 [Security] Rename PersistentTokenInterface::getUsername() to getUserI… · symfony/symfony@cc659eb · GitHub
[go: up one dir, main page]

Skip to content

Commit cc659eb

Browse files
committed
[Security] Rename PersistentTokenInterface::getUsername() to getUserIdentifier()
1 parent d132e69 commit cc659eb

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

UPGRADE-5.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Security
171171
* Deprecate `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
172172
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
173173
* Deprecate `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
174+
* Deprecate `PersistentTokenInterface::getUsername()` in favor of `PersistentTokenInterface::getUserIdentifier()`
174175
* Deprecate calling `PasswordUpgraderInterface::upgradePassword()` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface`
175176
* Deprecate calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface`
176177
* Deprecate all classes in the `Core\Encoder\` sub-namespace, use the `PasswordHasher` component instead

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Security
263263
* Remove `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
264264
* Remove `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
265265
* Remove `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
266+
* Remove `PersistentTokenInterface::getUsername()` in favor of `PersistentTokenInterface::getUserIdentifier()`
266267
* Calling `PasswordUpgraderInterface::upgradePassword()` with a `UserInterface` instance that
267268
does not implement `PasswordAuthenticatedUserInterface` now throws a `\TypeError`.
268269
* Calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface`

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.3
55
---
66

7+
* Deprecate `PersistentTokenInterface::getUsername()` in favor of `PersistentTokenInterface::getUserIdentifier()`
78
* Deprecate `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
89
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
910
* Deprecate `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`

src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
final class PersistentToken implements PersistentTokenInterface
2020
{
2121
private $class;
22-
private $username;
22+
private $userIdentifier;
2323
private $series;
2424
private $tokenValue;
2525
private $lastUsed;
2626

27-
public function __construct(string $class, string $username, string $series, string $tokenValue, \DateTime $lastUsed)
27+
public function __construct(string $class, string $userIdentifier, string $series, string $tokenValue, \DateTime $lastUsed)
2828
{
2929
if (empty($class)) {
3030
throw new \InvalidArgumentException('$class must not be empty.');
3131
}
32-
if ('' === $username) {
33-
throw new \InvalidArgumentException('$username must not be empty.');
32+
if ('' === $userIdentifier) {
33+
throw new \InvalidArgumentException('$userIdentifier must not be empty.');
3434
}
3535
if (empty($series)) {
3636
throw new \InvalidArgumentException('$series must not be empty.');
@@ -40,7 +40,7 @@ public function __construct(string $class, string $username, string $series, str
4040
}
4141

4242
$this->class = $class;
43-
$this->username = $username;
43+
$this->userIdentifier = $userIdentifier;
4444
$this->series = $series;
4545
$this->tokenValue = $tokenValue;
4646
$this->lastUsed = $lastUsed;
@@ -59,7 +59,14 @@ public function getClass(): string
5959
*/
6060
public function getUsername(): string
6161
{
62-
return $this->username;
62+
trigger_deprecation('symfony/security-core', '5.3', 'Method "%s()" is deprecated and will be removed in 6.0, use getUserIdentifier() instead.', __METHOD__);
63+
64+
return $this->userIdentifier;
65+
}
66+
67+
public function getUserIdentifier(): string
68+
{
69+
return $this->userIdentifier;
6370
}
6471

6572
/**

src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentTokenInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Interface to be implemented by persistent token classes (such as
1616
* Doctrine entities representing a remember-me token).
1717
*
18+
* @method string getUserIdentifier()
19+
*
1820
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
1921
*/
2022
interface PersistentTokenInterface
@@ -30,6 +32,8 @@ public function getClass();
3032
* Returns the username.
3133
*
3234
* @return string
35+
*
36+
* @deprecated since version 5.3, use/implement getUserIdentifier() instead.
3337
*/
3438
public function getUsername();
3539

src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
9494
);
9595

9696
$userProvider = $this->getUserProvider($persistentToken->getClass());
97-
$userIdentifier = $persistentToken->getUsername();
97+
if (method_exists($persistentToken, 'getUserIdentifier')) {
98+
$userIdentifier = $persistentToken->getUserIdentifier();
99+
} else {
100+
trigger_deprecation('symfony/security-core', '5.3', 'Not implementing method "getUserIdentifier()" in persistent token "%s" is deprecated. This method will replace "loadUserByUsername()" in Symfony 6.0.', \get_class($persistentToken));
101+
102+
$userIdentifier = $persistentToken->getUsername();
103+
}
104+
98105
if (method_exists($userProvider, 'loadUserByIdentifier')) {
99106
return $userProvider->loadUserByIdentifier($userIdentifier);
100107
} else {

0 commit comments

Comments
 (0)
0