[Worflow] Fixed GuardListener when using the new Security system

This commit is contained in:
Grégoire Pineau 2021-02-04 22:30:00 +01:00
parent b128423b64
commit bd26a79461
2 changed files with 13 additions and 30 deletions

View File

@ -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()),
];
}
}

View File

@ -1,21 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <matj1985@gmail.com>
*/
class InvalidTokenConfigurationException extends LogicException
{
}