Added support for guards when advancing workflow from a command
This commit is contained in:
parent
be7751aba7
commit
b044ffb4a2
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Workflow\EventListener;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
|
||||
@ -55,6 +56,11 @@ class GuardListener
|
||||
{
|
||||
$token = $this->tokenStorage->getToken();
|
||||
|
||||
if($token == null) {
|
||||
$token = new AnonymousToken('secret','anon',[]);
|
||||
$this->tokenStorage->setToken($token);
|
||||
}
|
||||
|
||||
if (null !== $this->roleHierarchy) {
|
||||
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
|
||||
} else {
|
||||
|
@ -69,6 +69,20 @@ class GuardListenerTest extends TestCase
|
||||
$this->assertTrue($event->isBlocked());
|
||||
}
|
||||
|
||||
public function testWithNoTokenStorage()
|
||||
{
|
||||
$event = $this->createEvent();
|
||||
$this->tokenStorage = null;
|
||||
|
||||
$this->listener->onTransition($event, 'event_name_a');
|
||||
|
||||
$this->assertFalse($event->isBlocked());
|
||||
|
||||
$this->listener->onTransition($event, 'event_name_b');
|
||||
|
||||
$this->assertTrue($event->isBlocked());
|
||||
}
|
||||
|
||||
private function createEvent()
|
||||
{
|
||||
$subject = new \stdClass();
|
||||
|
Reference in New Issue
Block a user