Skip to content

Commit e4ec595

Browse files
committed
deprecate the FQCN properties of PersistentToken and RememberMeDetails
1 parent 2586e9a commit e4ec595

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public function loadTokenBySeries(string $series): PersistentTokenInterface
6363

6464
[$class, $username, $value, $last_used] = $row;
6565

66-
return new PersistentToken($class, $username, $series, $value, new \DateTimeImmutable($last_used));
66+
if (method_exists(PersistentToken::class, 'getClass')) {
67+
return new PersistentToken($class, $username, $series, $value, new \DateTimeImmutable($last_used), false);
68+
}
69+
70+
return new PersistentToken($username, $series, $value, new \DateTimeImmutable($last_used));
6771
}
6872

6973
public function deleteTokenBySeries(string $series): void
@@ -166,7 +170,14 @@ public function updateExistingToken(PersistentTokenInterface $token, #[\Sensitiv
166170
try {
167171
$this->deleteTokenBySeries($tmpSeries);
168172
$lastUsed = \DateTime::createFromInterface($lastUsed);
169-
$this->createNewToken(new PersistentToken(method_exists($token, 'getClass') ? $token->getClass(false) : '', $token->getUserIdentifier(), $tmpSeries, $token->getTokenValue(), $lastUsed));
173+
174+
if (method_exists(PersistentToken::class, 'getClass')) {
175+
$persistentToken = new PersistentToken($token->getClass(false), $token->getUserIdentifier(), $tmpSeries, $token->getTokenValue(), $lastUsed, false);
176+
} else {
177+
$persistentToken = new PersistentToken($token->getUserIdentifier(), $tmpSeries, $token->getTokenValue(), $lastUsed);
178+
}
179+
180+
$this->createNewToken($persistentToken);
170181

171182
$this->conn->commit();
172183
} catch (\Exception $e) {

Tests/Security/RememberMe/DoctrineTokenProviderTest.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public function testCreateNewToken()
2727
{
2828
$provider = $this->bootstrapProvider();
2929

30-
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
30+
if (method_exists(PersistentToken::class, 'getClass')) {
31+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'), false);
32+
} else {
33+
$token = new PersistentToken('someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
34+
}
3135
$provider->createNewToken($token);
3236

3337
$this->assertEquals($provider->loadTokenBySeries('someSeries'), $token);
@@ -45,7 +49,12 @@ public function testUpdateToken()
4549
{
4650
$provider = $this->bootstrapProvider();
4751

48-
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
52+
if (method_exists(PersistentToken::class, 'getClass')) {
53+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'), false);
54+
} else {
55+
$token = new PersistentToken('someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
56+
}
57+
4958
$provider->createNewToken($token);
5059
$provider->updateToken('someSeries', 'newValue', $lastUsed = new \DateTime('2014-06-26T22:03:46'));
5160
$token = $provider->loadTokenBySeries('someSeries');
@@ -57,7 +66,11 @@ public function testUpdateToken()
5766
public function testDeleteToken()
5867
{
5968
$provider = $this->bootstrapProvider();
60-
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
69+
if (method_exists(PersistentToken::class, 'getClass')) {
70+
$token = new PersistentToken('someClass', 'someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'), false);
71+
} else {
72+
$token = new PersistentToken('someUser', 'someSeries', 'tokenValue', new \DateTimeImmutable('2013-01-26T18:23:51'));
73+
}
6174
$provider->createNewToken($token);
6275
$provider->deleteTokenBySeries('someSeries');
6376

@@ -74,7 +87,11 @@ public function testVerifyOutdatedTokenAfterParallelRequest()
7487
$newValue = 'newValue';
7588

7689
// setup existing token
77-
$token = new PersistentToken('someClass', 'someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'));
90+
if (method_exists(PersistentToken::class, 'getClass')) {
91+
$token = new PersistentToken('someClass', 'someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'), false);
92+
} else {
93+
$token = new PersistentToken('someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'));
94+
}
7895
$provider->createNewToken($token);
7996

8097
// new request comes in requiring remember-me auth, which updates the token
@@ -99,7 +116,11 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds()
99116
$newValue = 'newValue';
100117

101118
// setup existing token
102-
$token = new PersistentToken('someClass', 'someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'));
119+
if (method_exists(PersistentToken::class, 'getClass')) {
120+
$token = new PersistentToken('someClass', 'someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'), false);
121+
} else {
122+
$token = new PersistentToken('someUser', $series, $oldValue, new \DateTimeImmutable('2013-01-26T18:23:51'));
123+
}
103124
$provider->createNewToken($token);
104125

105126
// new request comes in requiring remember-me auth, which updates the token

0 commit comments

Comments
 (0)