*
- * @deprecated since Symfony 4.3, to be removed in 5.0.
+ * @method string[] getReachableRoleNames(string[] $roles) The associated roles - not implementing it is deprecated since Symfony 4.3
*/
interface RoleHierarchyInterface
{
- /**
- * Returns an array of all reachable roles by the given ones.
- *
- * Reachable roles are the roles directly assigned but also all roles that
- * are transitively reachable from them in the role hierarchy.
- *
- * @param Role[] $roles An array of directly assigned roles
- *
- * @return Role[] An array of all reachable roles
- */
- public function getReachableRoles(array $roles);
}
diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php
index 60cd00ed2084f..a1795b8f47b02 100644
--- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php
+++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php
@@ -13,9 +13,9 @@
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Role\Role;
-use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
@@ -37,6 +37,10 @@ class GuardListener
public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null)
{
+ if (null !== $roleHierarchy && !method_exists($roleHierarchy, 'getReachableRoleNames')) {
+ @trigger_error(sprintf('Not implementing the getReachableRoleNames() method in %s which implements %s is deprecated since Symfony 4.3.', \get_class($roleHierarchy), RoleHierarchyInterface::class), E_USER_DEPRECATED);
+ }
+
$this->configuration = $configuration;
$this->expressionLanguage = $expressionLanguage;
$this->tokenStorage = $tokenStorage;
@@ -83,15 +87,21 @@ private function getVariables(GuardEvent $event): array
}
if (method_exists($token, 'getRoleNames')) {
- $roles = $token->getRoleNames();
+ $roleNames = $token->getRoleNames();
+ $roles = array_map(function (string $role) { return new Role($role, false); }, $roleNames);
} else {
- $roles = array_map(function (Role $role) { return $role->getRole(); }, $token->getRoles(false));
+ @trigger_error(sprintf('Not implementing the getRoleNames() method in %s which implements %s is deprecated since Symfony 4.3.', \get_class($token), TokenInterface::class), E_USER_DEPRECATED);
+
+ $roles = $token->getRoles(false);
+ $roleNames = array_map(function (Role $role) { return $role->getRole(); }, $roles);
}
- if ($this->roleHierarchy instanceof RoleHierarchy) {
- $roles = $this->roleHierarchy->getReachableRoleNames($roles);
+ if (null !== $this->roleHierarchy && method_exists($this->roleHierarchy, 'getReachableRoleNames')) {
+ $roleNames = $this->roleHierarchy->getReachableRoleNames($roles);
+ $roles = array_map(function (string $role) { return new Role($role, false); }, $roleNames);
} elseif (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles(false));
+ $roleNames = array_map(function (Role $role) { return $role->getRole(); }, $roles);
}
$variables = [
@@ -99,6 +109,7 @@ private function getVariables(GuardEvent $event): array
'user' => $token->getUser(),
'subject' => $event->getSubject(),
'roles' => $roles,
+ 'role_names' => $roleNames,
// needed for the is_granted expression function
'auth_checker' => $this->authorizationChecker,
// needed for the is_* expression function
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