Skip to content

Commit b1b0fd7

Browse files
[Security] Keep roles when serializing tokens
1 parent e9eb3e7 commit b1b0fd7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ abstract class AbstractToken implements TokenInterface, \Serializable
3232
*/
3333
public function __construct(array $roles = [])
3434
{
35-
$this->roleNames = [];
36-
37-
foreach ($roles as $role) {
38-
$this->roleNames[] = (string) $role;
39-
}
35+
$this->roleNames = $roles;
4036
}
4137

4238
public function getRoleNames(): array
4339
{
44-
return $this->roleNames ??= self::__construct($this->user->getRoles()) ?? $this->roleNames;
40+
return $this->roleNames ??= $this->user?->getRoles() ?? [];
4541
}
4642

4743
public function getUserIdentifier(): string
@@ -92,7 +88,7 @@ public function __serialize(): array
9288
{
9389
$data = [$this->user, true, null, $this->attributes];
9490

95-
if (!$this->user instanceof EquatableInterface) {
91+
if (($this->user?->getRoles() ?? []) !== $this->getRoleNames()) {
9692
$data[] = $this->roleNames;
9793
}
9894

@@ -161,7 +157,7 @@ public function __toString(): string
161157
$class = substr($class, strrpos($class, '\\') + 1);
162158

163159
$roles = [];
164-
foreach ($this->roleNames as $role) {
160+
foreach ($this->getRoleNames() as $role) {
165161
$roles[] = $role;
166162
}
167163

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy