File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
src/Symfony/Component/Workflow Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1212namespace Symfony \Component \Workflow \EventListener ;
1313
1414use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
15+ use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
1516use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
1617use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
1718use Symfony \Component \Security \Core \Role \RoleHierarchyInterface ;
@@ -55,6 +56,11 @@ private function getVariables(GuardEvent $event)
5556 {
5657 $ token = $ this ->tokenStorage ->getToken ();
5758
59+ if ($ token == null ) {
60+ $ token = new AnonymousToken ('secret ' ,'anon ' ,[]);
61+ $ this ->tokenStorage ->setToken ($ token );
62+ }
63+
5864 if (null !== $ this ->roleHierarchy ) {
5965 $ roles = $ this ->roleHierarchy ->getReachableRoles ($ token ->getRoles ());
6066 } else {
Original file line number Diff line number Diff line change @@ -69,6 +69,20 @@ public function testWithSupportedEventAndAccept()
6969 $ this ->assertTrue ($ event ->isBlocked ());
7070 }
7171
72+ public function testWithNoTokenStorage ()
73+ {
74+ $ event = $ this ->createEvent ();
75+ $ this ->tokenStorage = null ;
76+
77+ $ this ->listener ->onTransition ($ event , 'event_name_a ' );
78+
79+ $ this ->assertFalse ($ event ->isBlocked ());
80+
81+ $ this ->listener ->onTransition ($ event , 'event_name_b ' );
82+
83+ $ this ->assertTrue ($ event ->isBlocked ());
84+ }
85+
7286 private function createEvent ()
7387 {
7488 $ subject = new \stdClass ();
You can’t perform that action at this time.
0 commit comments