|
14 | 14 | use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; |
15 | 15 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
16 | 16 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
| 17 | +use Symfony\Component\Security\Core\Role\Role; |
| 18 | +use Symfony\Component\Security\Core\Role\RoleHierarchy; |
17 | 19 | use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; |
18 | 20 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
19 | 21 | use Symfony\Component\Workflow\Event\GuardEvent; |
@@ -80,19 +82,23 @@ private function getVariables(GuardEvent $event): array |
80 | 82 | throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName())); |
81 | 83 | } |
82 | 84 |
|
83 | | - if (null !== $this->roleHierarchy) { |
84 | | - $roles = $this->roleHierarchy->getReachableRoles($token->getRoles()); |
| 85 | + if (method_exists($token, 'getRoleNames')) { |
| 86 | + $roles = $token->getRoleNames(); |
85 | 87 | } else { |
86 | | - $roles = $token->getRoles(); |
| 88 | + $roles = array_map(function (Role $role) { return $role->getRole(); }, $token->getRoles(false)); |
| 89 | + } |
| 90 | + |
| 91 | + if ($this->roleHierarchy instanceof RoleHierarchy) { |
| 92 | + $roles = $this->roleHierarchy->getReachableRoleNames($roles); |
| 93 | + } elseif (null !== $this->roleHierarchy) { |
| 94 | + $roles = $this->roleHierarchy->getReachableRoles($token->getRoles(false)); |
87 | 95 | } |
88 | 96 |
|
89 | 97 | $variables = [ |
90 | 98 | 'token' => $token, |
91 | 99 | 'user' => $token->getUser(), |
92 | 100 | 'subject' => $event->getSubject(), |
93 | | - 'roles' => array_map(function ($role) { |
94 | | - return $role->getRole(); |
95 | | - }, $roles), |
| 101 | + 'roles' => $roles, |
96 | 102 | // needed for the is_granted expression function |
97 | 103 | 'auth_checker' => $this->authorizationChecker, |
98 | 104 | // needed for the is_* expression function |
|
0 commit comments