Added support for guards when advancing workflow from a command

This commit is contained in:
GDIBass 2017-08-16 23:21:24 +00:00
parent be7751aba7
commit b044ffb4a2
2 changed files with 20 additions and 0 deletions

View File

@ -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 {

View File

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