From bd26a7946191f9964f741f83eb1be91fb473e001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 4 Feb 2021 22:30:00 +0100 Subject: [PATCH] [Worflow] Fixed GuardListener when using the new Security system --- .../Workflow/EventListener/GuardListener.php | 22 +++++++++++-------- .../InvalidTokenConfigurationException.php | 21 ------------------ 2 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 9329d40436..8b63f9380b 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -17,7 +17,6 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Workflow\Event\GuardEvent; -use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException; use Symfony\Component\Workflow\TransitionBlocker; /** @@ -76,15 +75,8 @@ class GuardListener { $token = $this->tokenStorage->getToken(); - if (null === $token) { - throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow "%s".', $event->getWorkflowName())); - } - $variables = [ - 'token' => $token, - 'user' => $token->getUser(), 'subject' => $event->getSubject(), - 'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()), // needed for the is_granted expression function 'auth_checker' => $this->authorizationChecker, // needed for the is_* expression function @@ -93,6 +85,18 @@ class GuardListener 'validator' => $this->validator, ]; - return $variables; + if (null === $token) { + return $variables + [ + 'token' => null, + 'user' => null, + 'role_names' => [], + ]; + } + + return $variables + [ + 'token' => $token, + 'user' => $token->getUser(), + 'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()), + ]; } } diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php deleted file mode 100644 index a70fd4c98d..0000000000 --- a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Workflow\Exception; - -/** - * Thrown by GuardListener when there is no token set, but guards are placed on a transition. - * - * @author Matt Johnson - */ -class InvalidTokenConfigurationException extends LogicException -{ -}