[Worflow] Fixed GuardListener when using the new Security system
This commit is contained in:
parent
b128423b64
commit
bd26a79461
@ -17,7 +17,6 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
|||||||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\Workflow\Event\GuardEvent;
|
use Symfony\Component\Workflow\Event\GuardEvent;
|
||||||
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
|
|
||||||
use Symfony\Component\Workflow\TransitionBlocker;
|
use Symfony\Component\Workflow\TransitionBlocker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,15 +75,8 @@ class GuardListener
|
|||||||
{
|
{
|
||||||
$token = $this->tokenStorage->getToken();
|
$token = $this->tokenStorage->getToken();
|
||||||
|
|
||||||
if (null === $token) {
|
|
||||||
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow "%s".', $event->getWorkflowName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$variables = [
|
$variables = [
|
||||||
'token' => $token,
|
|
||||||
'user' => $token->getUser(),
|
|
||||||
'subject' => $event->getSubject(),
|
'subject' => $event->getSubject(),
|
||||||
'role_names' => $this->roleHierarchy->getReachableRoleNames($token->getRoleNames()),
|
|
||||||
// needed for the is_granted expression function
|
// needed for the is_granted expression function
|
||||||
'auth_checker' => $this->authorizationChecker,
|
'auth_checker' => $this->authorizationChecker,
|
||||||
// needed for the is_* expression function
|
// needed for the is_* expression function
|
||||||
@ -93,6 +85,18 @@ class GuardListener
|
|||||||
'validator' => $this->validator,
|
'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()),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
{
|
|
||||||
}
|
|
Reference in New Issue
Block a user