20
20
use Symfony \Component \EventDispatcher \EventDispatcher ;
21
21
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
22
22
use Symfony \Component \Security \Core \AuthenticationEvents ;
23
+ use Symfony \Component \Security \Core \Event \AuthenticationSuccessEvent ;
23
24
use Symfony \Component \Security \Http \Event \CheckPassportEvent ;
25
+ use Symfony \Component \Security \Http \Event \InteractiveLoginEvent ;
26
+ use Symfony \Component \Security \Http \Event \LoginFailureEvent ;
24
27
use Symfony \Component \Security \Http \Event \LoginSuccessEvent ;
25
28
use Symfony \Component \Security \Http \Event \LogoutEvent ;
29
+ use Symfony \Component \Security \Http \SecurityEvents ;
26
30
27
31
class RegisterGlobalSecurityEventListenersPassTest extends TestCase
28
32
{
@@ -45,6 +49,42 @@ protected function setUp(): void
45
49
$ securityBundle ->build ($ this ->container );
46
50
}
47
51
52
+ /**
53
+ * @dataProvider providePropagatedEvents
54
+ */
55
+ public function testEventIsPropagated (string $ configuredEvent , string $ registeredEvent )
56
+ {
57
+ $ this ->container ->loadFromExtension ('security ' , [
58
+ 'enable_authenticator_manager ' => true ,
59
+ 'firewalls ' => ['main ' => ['pattern ' => '/ ' , 'http_basic ' => true ]],
60
+ ]);
61
+
62
+ $ this ->container ->register ('app.security_listener ' , \stdClass::class)
63
+ ->addTag ('kernel.event_listener ' , ['method ' => 'onEvent ' , 'event ' => $ configuredEvent ]);
64
+
65
+ $ this ->container ->compile ();
66
+
67
+ $ this ->assertListeners ([
68
+ [$ registeredEvent , ['app.security_listener ' , 'onEvent ' ], 0 ],
69
+ ]);
70
+ }
71
+
72
+ public function providePropagatedEvents (): array
73
+ {
74
+ return [
75
+ [CheckPassportEvent::class, CheckPassportEvent::class],
76
+ [LoginFailureEvent::class, LoginFailureEvent::class],
77
+ [LoginSuccessEvent::class, LoginSuccessEvent::class],
78
+ [LogoutEvent::class, LogoutEvent::class],
79
+ [AuthenticationEvents::AUTHENTICATION_SUCCESS , AuthenticationEvents::AUTHENTICATION_SUCCESS ],
80
+ [SecurityEvents::INTERACTIVE_LOGIN , SecurityEvents::INTERACTIVE_LOGIN ],
81
+
82
+ // These events are ultimately registered by their event name instead of the FQN
83
+ [AuthenticationSuccessEvent::class, AuthenticationEvents::AUTHENTICATION_SUCCESS ],
84
+ [InteractiveLoginEvent::class, SecurityEvents::INTERACTIVE_LOGIN ],
85
+ ];
86
+ }
87
+
48
88
public function testRegisterCustomListener ()
49
89
{
50
90
$ this ->container ->loadFromExtension ('security ' , [
0 commit comments