Skip to content

Commit 38e3e37

Browse files
committed
Deprecate empty user identifier
1 parent a8098b2 commit 38e3e37

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

UPGRADE-7.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Security
3939

4040
* Add `$token` argument to `UserCheckerInterface::checkPostAuth()`
4141
* Deprecate argument `$secret` of `RememberMeToken` and `RememberMeAuthenticator`
42+
* Deprecate passing an empty string as `$userIdentifier` argument to `UserBadge` constructor
4243

4344
String
4445
------

src/Symfony/Component/Security/Core/User/UserInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function eraseCredentials(): void;
5656

5757
/**
5858
* Returns the identifier for this user (e.g. username or email address).
59+
*
60+
* @return non-empty-string
5961
*/
6062
public function getUserIdentifier(): string;
6163
}

src/Symfony/Component/Security/Http/Authenticator/Passport/Badge/UserBadge.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function __construct(
5252
?callable $userLoader = null,
5353
private ?array $attributes = null,
5454
) {
55+
if ('' === $userIdentifier) {
56+
trigger_deprecation('symfony/security-http', '7.2', 'Using an empty string as user identifier is deprecated and will not be allowed in 8.0.');
57+
}
58+
5559
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
5660
throw new BadCredentialsException('Username too long.');
5761
}

src/Symfony/Component/Security/Http/Tests/Authenticator/Passport/Badge/UserBadgeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@
1212
namespace Symfony\Component\Security\Http\Tests\Authenticator\Passport\Badge;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1516
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1617
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1718

1819
class UserBadgeTest extends TestCase
1920
{
21+
use ExpectUserDeprecationMessageTrait;
22+
2023
public function testUserNotFound()
2124
{
2225
$badge = new UserBadge('dummy', fn () => null);
2326
$this->expectException(UserNotFoundException::class);
2427
$badge->getUser();
2528
}
29+
30+
/**
31+
* @group legacy
32+
*/
33+
public function testDeprecatedEmptyUserIdentifier()
34+
{
35+
$this->expectUserDeprecationMessage('Since symfony/security-http 7.2: Using an empty string as the user indentifier is deprecated and will not be allowed in 8.0.');
36+
new UserBadge('', fn () => null);
37+
}
2638
}

0 commit comments

Comments
 (0)