From b044ffb4a23d109d62724e7c62855f4d03d72a32 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Wed, 16 Aug 2017 23:21:24 +0000 Subject: [PATCH 01/12] Added support for guards when advancing workflow from a command --- .../Workflow/EventListener/GuardListener.php | 6 ++++++ .../Tests/EventListener/GuardListenerTest.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 20ba04c007fc..d7d9d2edc43a 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -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 @@ private function getVariables(GuardEvent $event) { $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 { diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index b46ee9092c57..50481654e5b5 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -69,6 +69,20 @@ public function testWithSupportedEventAndAccept() $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(); From 324c208e129c6d5792486df71df09b8f6f4e8d08 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Wed, 16 Aug 2017 23:27:57 +0000 Subject: [PATCH 02/12] Code standards update --- .../Component/Workflow/EventListener/GuardListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index d7d9d2edc43a..d78ae47396cf 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -56,8 +56,8 @@ private function getVariables(GuardEvent $event) { $token = $this->tokenStorage->getToken(); - if($token == null) { - $token = new AnonymousToken('secret','anon',[]); + if ($token == null) { + $token = new AnonymousToken('secret', 'anon', array()); $this->tokenStorage->setToken($token); } From 8ab59cb1c2b579179ef6db318bb2c362b9f613e9 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Thu, 17 Aug 2017 01:27:02 -0700 Subject: [PATCH 03/12] Updated if statement --- src/Symfony/Component/Workflow/EventListener/GuardListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index d78ae47396cf..e0c29876af0b 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -56,7 +56,7 @@ private function getVariables(GuardEvent $event) { $token = $this->tokenStorage->getToken(); - if ($token == null) { + if (null === $token) { $token = new AnonymousToken('secret', 'anon', array()); $this->tokenStorage->setToken($token); } From 22b44e251fdf4c7a41a3ac85f4150addd9e82660 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Thu, 17 Aug 2017 23:37:10 -0700 Subject: [PATCH 04/12] Changed automatic token generation to throw an exception instead --- .../Component/Workflow/EventListener/GuardListener.php | 3 +-- .../Workflow/Tests/EventListener/GuardListenerTest.php | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index e0c29876af0b..798af6ae6165 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -57,8 +57,7 @@ private function getVariables(GuardEvent $event) $token = $this->tokenStorage->getToken(); if (null === $token) { - $token = new AnonymousToken('secret', 'anon', array()); - $this->tokenStorage->setToken($token); + throw new \Exception("No token is set"); } if (null !== $this->roleHierarchy) { diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index 50481654e5b5..d72e31931360 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -74,13 +74,9 @@ public function testWithNoTokenStorage() $event = $this->createEvent(); $this->tokenStorage = null; - $this->listener->onTransition($event, 'event_name_a'); - - $this->assertFalse($event->isBlocked()); + $this->expectException(\Exception::class); - $this->listener->onTransition($event, 'event_name_b'); - - $this->assertTrue($event->isBlocked()); + $this->listener->onTransition($event, 'event_name_a'); } private function createEvent() From 3a8b2eded11932f41d617c285ffeb67e5614ccc9 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Thu, 17 Aug 2017 23:45:14 -0700 Subject: [PATCH 05/12] Code standard fixes --- src/Symfony/Component/Workflow/EventListener/GuardListener.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 798af6ae6165..3e402e9280a9 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -12,7 +12,6 @@ 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; @@ -57,7 +56,7 @@ private function getVariables(GuardEvent $event) $token = $this->tokenStorage->getToken(); if (null === $token) { - throw new \Exception("No token is set"); + throw new \Exception('No token is set'); } if (null !== $this->roleHierarchy) { From 2ebc71a61671d30142b1f67989c9c48dff5bf425 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 18 Aug 2017 08:37:36 -0700 Subject: [PATCH 06/12] Created new Exception to throw and modified tests --- .../Workflow/EventListener/GuardListener.php | 3 ++- .../InvalidTokenConfigurationException.php | 21 +++++++++++++++++++ .../Tests/EventListener/GuardListenerTest.php | 8 ++++--- 3 files changed, 28 insertions(+), 4 deletions(-) create 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 3e402e9280a9..5d10cbcfceee 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -16,6 +16,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Role\RoleHierarchyInterface; use Symfony\Component\Workflow\Event\GuardEvent; +use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException; /** * @author Grégoire Pineau @@ -56,7 +57,7 @@ private function getVariables(GuardEvent $event) $token = $this->tokenStorage->getToken(); if (null === $token) { - throw new \Exception('No token is set'); + throw new InvalidTokenConfigurationException('No token is set'); } if (null !== $this->roleHierarchy) { diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php new file mode 100644 index 000000000000..367d4c6eb637 --- /dev/null +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -0,0 +1,21 @@ + + * + * 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 implements ExceptionInterface +{ +} \ No newline at end of file diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index d72e31931360..c32aec06a45b 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -69,12 +69,14 @@ public function testWithSupportedEventAndAccept() $this->assertTrue($event->isBlocked()); } + /** + * @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException + * @expectedExceptionMessage No token is set + */ public function testWithNoTokenStorage() { $event = $this->createEvent(); - $this->tokenStorage = null; - - $this->expectException(\Exception::class); + $this->tokenStorage->setToken(null); $this->listener->onTransition($event, 'event_name_a'); } From 92308b4815b6ab2ee7eb018d9c284faf428b2131 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 18 Aug 2017 08:40:24 -0700 Subject: [PATCH 07/12] Created new Exception to throw and modified tests. --- .../Workflow/Exception/InvalidTokenConfigurationException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php index 367d4c6eb637..85ada5e78071 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Workflow\Exception; /** - * Thrown by GuardListener when there is no token set, but guards are placed on a transition + * Thrown by GuardListener when there is no token set, but guards are placed on a transition. * * @author Matt Johnson */ From 2c9d1e2d426673fe5d5ea568c1794ee5e4bf364c Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 18 Aug 2017 08:42:05 -0700 Subject: [PATCH 08/12] Removed newline --- .../Component/Workflow/Exception/InvalidDefinitionException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php b/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php index d41170953564..4ba9b183192a 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php @@ -18,4 +18,4 @@ */ class InvalidDefinitionException extends LogicException { -} +} \ No newline at end of file From 49839e3c286d292a7068c9865cd12d884f299b9e Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 18 Aug 2017 08:43:29 -0700 Subject: [PATCH 09/12] Ahh, I see. It actually wants a newline! --- .../Component/Workflow/Exception/InvalidDefinitionException.php | 2 +- .../Workflow/Exception/InvalidTokenConfigurationException.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php b/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php index 4ba9b183192a..d41170953564 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidDefinitionException.php @@ -18,4 +18,4 @@ */ class InvalidDefinitionException extends LogicException { -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php index 85ada5e78071..681d7a8bba52 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -18,4 +18,4 @@ */ class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface { -} \ No newline at end of file +} From 8f2fa6b047243ed6424e805ee767b6c15eca8fc9 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 25 Aug 2017 11:25:19 -0700 Subject: [PATCH 10/12] changed exception message --- src/Symfony/Component/Workflow/EventListener/GuardListener.php | 2 +- .../Workflow/Exception/InvalidTokenConfigurationException.php | 2 +- .../Workflow/Tests/EventListener/GuardListenerTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 5d10cbcfceee..8726e4bddca4 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -57,7 +57,7 @@ private function getVariables(GuardEvent $event) $token = $this->tokenStorage->getToken(); if (null === $token) { - throw new InvalidTokenConfigurationException('No token is set'); + throw new InvalidTokenConfigurationException(sprintf('There are no token available for workflow %s', $event->getWorkflowName())); } if (null !== $this->roleHierarchy) { diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php index 681d7a8bba52..85ada5e78071 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -18,4 +18,4 @@ */ class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface { -} +} \ No newline at end of file diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index c32aec06a45b..0e2dbc13bc53 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -71,7 +71,7 @@ public function testWithSupportedEventAndAccept() /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException - * @expectedExceptionMessage No token is set + * @expectedExceptionMessage There are no token available for workflow unnamed */ public function testWithNoTokenStorage() { From fefc20233b081691b428358d8c05b395ef8cc7af Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 25 Aug 2017 11:26:09 -0700 Subject: [PATCH 11/12] newline at end of file --- .../Workflow/Exception/InvalidTokenConfigurationException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php index 85ada5e78071..681d7a8bba52 100644 --- a/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php +++ b/src/Symfony/Component/Workflow/Exception/InvalidTokenConfigurationException.php @@ -18,4 +18,4 @@ */ class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface { -} \ No newline at end of file +} From 15fd8631128e9d5dfb61c2cbc59e066bb1a98242 Mon Sep 17 00:00:00 2001 From: GDIBass Date: Fri, 15 Sep 2017 09:32:24 -0700 Subject: [PATCH 12/12] Updated Test name and exception name to be more accurate --- .../Component/Workflow/EventListener/GuardListener.php | 2 +- .../Workflow/Tests/EventListener/GuardListenerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 8726e4bddca4..4d1065299de0 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -57,7 +57,7 @@ private function getVariables(GuardEvent $event) $token = $this->tokenStorage->getToken(); if (null === $token) { - throw new InvalidTokenConfigurationException(sprintf('There are no token available for workflow %s', $event->getWorkflowName())); + throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName())); } if (null !== $this->roleHierarchy) { diff --git a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php index 0e2dbc13bc53..741dcf093057 100644 --- a/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php +++ b/src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php @@ -71,9 +71,9 @@ public function testWithSupportedEventAndAccept() /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException - * @expectedExceptionMessage There are no token available for workflow unnamed + * @expectedExceptionMessage There are no tokens available for workflow unnamed. */ - public function testWithNoTokenStorage() + public function testWithNoTokensInTokenStorage() { $event = $this->createEvent(); $this->tokenStorage->setToken(null);