8000 Revert #31177, fixing roles equality check in AbstractToken · wouterj/symfony@e27e80f · GitHub
[go: up one dir, main page]

Skip to content

Commit e27e80f

Browse files
committed
Revert symfony#31177, fixing roles equality check in AbstractToken
1 parent 96d2d19 commit e27e80f

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,6 @@ private function hasUserChanged(UserInterface $user): bool
317317
return true;
318318
}
319319

320-
$currentUserRoles = array_map('strval', (array) $this->user->getRoles());
321-
$userRoles = array_map('strval', (array) $user->getRoles());
322-
323-
if (\count($userRoles) !== \count($currentUserRoles) || \count($userRoles) !== \count(array_intersect($userRoles, $currentUserRoles))) {
324-
return true;
325-
}
326-
327320
if ($this->user->getUsername() !== $user->getUsername()) {
328321
return true;
329322
}

src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ public function testSetUserDoesNotSetAuthenticatedToFalseWhenUserDoesNotChange($
248248
$token->setUser($user);
249249
$this->assertTrue($token->isAuthenticated());
250250
}
251+
252+
public function testIsUserChangedWhenSerializing()
253+
{
254+
$token = new ConcreteToken(['ROLE_ADMIN']);
255+
$token->setAuthenticated(true);
256+
$this->assertTrue($token->isAuthenticated());
257+
258+
$user = new SerializableUser('wouter', ['ROLE_ADMIN']);
259+
$token->setUser($user);
260+
$this->assertTrue($token->isAuthenticated());
261+
262+
$token = unserialize(serialize($token));
263+
$token->setUser($user);
264+
$this->assertTrue($token->isAuthenticated());
265+
}
251266
}
252267

253268
class TestUser
@@ -265,6 +280,55 @@ public function __toString(): string
265280
}
266281
}
267282

283+
class SerializableUser implements UserInterface, \Serializable
284+
{
285+
private $roles;
286+
private $name;
287+
288+
public function __construct($name, array $roles = [])
289+
{
290+
$this->name = $name;
291+
$this->roles = $roles;
292+
}
293+
294+
public function getUsername()
295+
{
296+
return $this->name;
297+
}
298+
299+
public function getPassword()
300+
{
301+
return '***';
302+
}
303+
304+
public function getRoles()
305+
{
306+
if (empty($this->roles)) {
307+
return ['ROLE_USER'];
308+
}
309+
310+
return $this->roles;
311+
}
312+
313+
public function eraseCredentials()
314+
{}
315+
316+
public function getSalt()
317+
{
318+
return null;
319+
}
320+
321+
public function serialize()
322+
{
323+
return serialize($this->name);
324+
}
325+
326+
public function unserialize($serialized)
327+
{
328+
$this->name = unserialize($serialized);
329+
}
330+
}
331+
268332
class ConcreteToken extends AbstractToken
269333
{
270334
private $credentials = 'credentials_value';

0 commit comments

Comments
 (0)
0