27
27
use Symfony \Component \HttpFoundation \Response ;
28
28
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
29
29
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
30
+ use Symfony \Component \Security \Core \User \UserChecker ;
31
+ use Symfony \Component \Security \Core \User \UserCheckerInterface ;
30
32
use Symfony \Component \Security \Core \User \UserInterface ;
31
33
use Symfony \Component \Security \Core \User \UserProviderInterface ;
32
34
use Symfony \Component \Security \Guard \AuthenticatorInterface as GuardAuthenticatorInterface ;
@@ -509,7 +511,7 @@ public function provideEntryPointRequiredData()
509
511
];
510
512
}
511
513
512
- public function testAlwaysAuthenticateBeforeGrantingCannotBeTrueWithAuthenticationManager ()
514
+ public function testAlwaysAuthenticateBeforeGrantingCannotBeTrueWithAuthenticatorManager ()
513
515
{
514
516
$ this ->expectException (InvalidConfigurationException::class);
515
517
$ this ->expectExceptionMessage ('The security option "always_authenticate_before_granting" cannot be used when "enable_authenticator_manager" is set to true. If you rely on this behavior, set it to false. ' );
@@ -559,7 +561,7 @@ public function provideConfigureCustomAuthenticatorData()
559
561
];
560
562
}
561
563
562
- public function testCompilesWithoutSessionListenerWithStatelessFirewallWithAuthenticationManager ()
564
+ public function testCompilesWithoutSessionListenerWithStatelessFirewallWithAuthenticatorManager ()
563
565
{
564
566
$ container = $ this ->getRawContainer ();
565
567
@@ -580,7 +582,7 @@ public function testCompilesWithoutSessionListenerWithStatelessFirewallWithAuthe
580
582
$ this ->assertFalse ($ container ->has ('security.listener.session. ' .$ firewallId ));
581
583
}
582
584
583
- public function testCompilesWithSessionListenerWithStatefulllFirewallWithAuthenticationManager ()
585
+ public function testCompilesWithSessionListenerWithStatefulllFirewallWithAuthenticatorManager ()
584
586
{
585
587
$ container = $ this ->getRawContainer ();
586
588
@@ -601,6 +603,37 @@ public function testCompilesWithSessionListenerWithStatefulllFirewallWithAuthent
601
603
$ this ->assertTrue ($ container ->has ('security.listener.session. ' .$ firewallId ));
602
604
}
603
605
606
+ /**
607
+ * @dataProvider provideUserCheckerConfig
608
+ */
609
+ public function testUserCheckerWithAuthenticatorManager (array $ config , string $ expectedUserCheckerClass )
610
+ {
611
+ $ container = $ this ->getRawContainer ();
612
+ $ container ->register (TestUserChecker::class);
613
+
614
+ $ container ->loadFromExtension ('security ' , [
615
+ 'enable_authenticator_manager ' => true ,
616
+ 'firewalls ' => [
617
+ 'main ' => array_merge ([
618
+ 'pattern ' => '/.* ' ,
619
+ 'http_basic ' => true ,
620
+ ], $ config ),
621
+ ],
622
+ ]);
623
+
624
+ $ container ->compile ();
625
+
626
+ $ userCheckerId = (string ) $ container ->getDefinition ('security.listener.user_checker.main ' )->getArgument (0 );
627
+ $ this ->assertTrue ($ container ->has ($ userCheckerId ));
628
+ $ this ->assertEquals ($ expectedUserCheckerClass , $ container ->findDefinition ($ userCheckerId )->getClass ());
629
+ }
630
+
631
+ public function provideUserCheckerConfig ()
632
+ {
633
+ yield [[], UserChecker::class];
634
+ yield [['user_checker ' => TestUserChecker::class], TestUserChecker::class];
635
+ }
636
+
604
637
protected function getRawContainer ()
605
638
{
606
639
$ container = new ContainerBuilder ();
@@ -689,3 +722,14 @@ public function supportsRememberMe()
689
722
{
690
723
}
691
724
}
725
+
726
+ class TestUserChecker implements UserCheckerInterface
727
+ {
728
+ public function checkPreAuth (UserInterface $ user )
729
+ {
730
+ }
731
+
732
+ public function checkPostAuth (UserInterface $ user )
733
+ {
734
+ }
735
+ }
0 commit comments