Skip to content

Commit 77490c6

Browse files
committed
feature #58007 [Security] Deprecate empty user identifier (ajgarlag)
This PR was merged into the 7.2 branch. Discussion ---------- [Security] Deprecate empty user identifier | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | yes | Issues | Fix #57982 | License | MIT Commits ------- 63690ec02e Deprecate empty user identifier
2 parents 5dafbdd + cf7f816 commit 77490c6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Authenticator/Passport/Badge/UserBadge.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ 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 throw an exception in Symfony 8.0.');
57+
// throw new BadCredentialsException('Empty user identifier.');
58+
}
59+
5560
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
5661
throw new BadCredentialsException('Username too long.');
5762
}

CHANGELOG.md

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

77
* Pass the current token to the `checkPostAuth()` method of user checkers
88
* Deprecate argument `$secret` of `RememberMeAuthenticator`
9+
* Deprecate passing an empty string as `$userIdentifier` argument to `UserBadge` constructor
910

1011
7.1
1112
---

Tests/Authenticator/Passport/Badge/UserBadgeTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
16+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1517
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1618
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1719

1820
class UserBadgeTest extends TestCase
1921
{
22+
use ExpectUserDeprecationMessageTrait;
23+
2024
public function testUserNotFound()
2125
{
2226
$badge = new UserBadge('dummy', fn () => null);
2327
$this->expectException(UserNotFoundException::class);
2428
$badge->getUser();
2529
}
30+
31+
/**
32+
* @group legacy
33+
*/
34+
public function testEmptyUserIdentifier()
35+
{
36+
$this->expectUserDeprecationMessage('Since symfony/security-http 7.2: Using an empty string as user identifier is deprecated and will throw an exception in Symfony 8.0.');
37+
// $this->expectException(BadCredentialsException::class)
38+
new UserBadge('', fn () => null);
39+
}
2640
}

0 commit comments

Comments
 (0)