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 12
12
namespace Symfony \Component \Workflow \EventListener ;
13
13
14
14
use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
15
+ use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
15
16
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
16
17
use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
17
18
use Symfony \Component \Security \Core \Role \RoleHierarchyInterface ;
@@ -55,6 +56,11 @@ private function getVariables(GuardEvent $event)
55
56
{
56
57
$ token = $ this ->tokenStorage ->getToken ();
57
58
59
+ if ($ token == null ) {
60
+ $ token = new AnonymousToken ('secret ' ,'anon ' ,[]);
61
+ $ this ->tokenStorage ->setToken ($ token );
62
+ }
63
+
58
64
if (null !== $ this ->roleHierarchy ) {
59
65
$ roles = $ this ->roleHierarchy ->getReachableRoles ($ token ->getRoles ());
60
66
} else {
Original file line number Diff line number Diff line change @@ -69,6 +69,20 @@ public function testWithSupportedEventAndAccept()
69
69
$ this ->assertTrue ($ event ->isBlocked ());
70
70
}
71
71
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
+
72
86
private function createEvent ()
73
87
{
74
88
$ subject = new \stdClass ();
You can’t perform that action at this time.
0 commit comments