Skip to content

Commit da1417b

Browse files
[Security] Deprecate PersistentToken::getClass() and RememberMeDetails::getUserFqcn() in order to remove the user FQCN from the remember-me cookie in 8.0
1 parent ab924e5 commit da1417b

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

Authentication/RememberMe/InMemoryTokenProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function updateToken(string $series, #[\SensitiveParameter] string $token
3838
}
3939

4040
$token = new PersistentToken(
41-
$this->tokens[$series]->getClass(),
41+
$this->tokens[$series]->getClass(false),
4242
$this->tokens[$series]->getUserIdentifier(),
4343
$series,
4444
$tokenValue,

Authentication/RememberMe/PersistentToken.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ public function __construct(
4343
$this->lastUsed = \DateTimeImmutable::createFromInterface($lastUsed);
4444
}
4545

46-
public function getClass(): string
46+
/**
47+
* @deprecated since Symfony 7.4
48+
*/
49+
public function getClass(bool $triggerDeprecation = true): string
4750
{
51+
if ($triggerDeprecation) {
52+
trigger_deprecation('symfony/security-core', '7.4', 'The "%s()" method is deprecated: the user class will be removed from the remember-me cookie in 8.0.', __METHOD__);
53+
}
54+
4855
return $this->class;
4956
}
5057

Authentication/RememberMe/PersistentTokenInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface PersistentTokenInterface
2121
{
2222
/**
2323
* Returns the class of the user.
24+
*
25+
* @deprecated since Symfony 7.4, the user class will be removed from the remember-me cookie in 8.0
2426
*/
2527
public function getClass(): string;
2628

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CHANGELOG
44
7.4
55
---
66

7-
* Add `MermaidDumper` to dump Role Hierarchy graphs in the Mermaid.js flowchart format
7+
* Add `MermaidDumper` to dump Role Hierarchy graphs in the Mermaid.js flowchart format
8+
* Deprecate `PersistentTokenInterface::getClass()`, the user class will be removed from the remember-me cookie in 8.0
89

910
7.3
1011
---

Tests/Authentication/RememberMe/PersistentTokenTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Security\Core\Tests\Authentication\RememberMe;
1313

14+
use PHPUnit\Framework\Attributes\Group;
15+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1416
use PHPUnit\Framework\TestCase;
1517
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
1618

@@ -21,7 +23,6 @@ public function testConstructor()
2123
$lastUsed = new \DateTimeImmutable();
2224
$token = new PersistentToken('fooclass', 'fooname', 'fooseries', 'footokenvalue', $lastUsed);
2325

24-
$this->assertEquals('fooclass', $token->getClass());
2526
$this->assertEquals('fooname', $token->getUserIdentifier());
2627
$this->assertEquals('fooseries', $token->getSeries());
2728
$this->assertEquals('footokenvalue', $token->getTokenValue());
@@ -35,4 +36,12 @@ public function testDateTime()
3536

3637
$this->assertEquals($lastUsed, $token->getLastUsed());
3738
}
39+
40+
#[IgnoreDeprecations]
41+
#[Group('legacy')]
42+
public function testClassDeprecation()
43+
{
44+
$token = new PersistentToken('fooclass', 'fooname', 'fooseries', 'footokenvalue', new \DateTimeImmutable());
45+
$this->assertSame('fooclass', $token->getClass());
46+
}
3847
}

0 commit comments

Comments
 (0)