|
24 | 24 | use Symfony\Component\DependencyInjection\Reference;
|
25 | 25 | use Symfony\Component\ExpressionLanguage\Expression;
|
26 | 26 | use Symfony\Component\HttpFoundation\Request;
|
| 27 | +use Symfony\Component\HttpFoundation\Response; |
27 | 28 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
28 | 29 | use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
29 | 30 | use Symfony\Component\Security\Core\User\UserInterface;
|
30 | 31 | use Symfony\Component\Security\Core\User\UserProviderInterface;
|
31 |
| -use Symfony\Component\Security\Guard\AuthenticatorInterface; |
| 32 | +use Symfony\Component\Security\Guard\AuthenticatorInterface as GuardAuthenticatorInterface; |
| 33 | +use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; |
| 34 | +use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator; |
| 35 | +use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; |
32 | 36 |
|
33 | 37 | class SecurityExtensionTest extends TestCase
|
34 | 38 | {
|
@@ -520,6 +524,41 @@ public function testAlwaysAuthenticateBeforeGrantingCannotBeTrueWithAuthenticati
|
520 | 524 | $container->compile();
|
521 | 525 | }
|
522 | 526 |
|
| 527 | + /** |
| 528 | + * @dataProvider provideConfigureCustomAuthenticatorData |
| 529 | + */ |
| 530 | + public function testConfigureCustomAuthenticator(array $firewall, array $expectedAuthenticators) |
| 531 | + { |
| 532 | + $container = $this->getRawContainer(); |
| 533 | + $container->loadFromExtension('security', [ |
| 534 | + 'enable_authenticator_manager' => true, |
| 535 | + 'providers' => [ |
| 536 | + 'first' => ['id' => 'users'], |
| 537 | + ], |
| 538 | + |
| 539 | + 'firewalls' => [ |
| 540 | + 'main' => $firewall, |
| 541 | + ], |
| 542 | + ]); |
| 543 | + |
| 544 | + $container->compile(); |
| 545 | + |
| 546 | + $this->assertEquals($expectedAuthenticators, array_map('strval', $container->getDefinition('security.authenticator.manager.main')->getArgument(0))); |
| 547 | + } |
| 548 | + |
| 549 | + public function provideConfigureCustomAuthenticatorData() |
| 550 | + { |
| 551 | + yield [ |
| 552 | + ['custom_authenticator' => TestAuthenticator::class], |
| 553 | + [TestAuthenticator::class], |
| 554 | + ]; |
| 555 | + |
| 556 | + yield [ |
| 557 | + ['custom_authenticators' => [TestAuthenticator::class, HttpBasicAuthenticator::class]], |
| 558 | + [TestAuthenticator::class, HttpBasicAuthenticator::class], |
| 559 | + ]; |
| 560 | + } |
| 561 | + |
523 | 562 | protected function getRawContainer()
|
524 | 563 | {
|
525 | 564 | $container = new ContainerBuilder();
|
@@ -547,7 +586,30 @@ protected function getContainer()
|
547 | 586 | }
|
548 | 587 | }
|
549 | 588 |
|
550 |
| -class NullAuthenticator implements AuthenticatorInterface |
| 589 | +class TestAuthenticator implements AuthenticatorInterface |
| 590 | +{ |
| 591 | + public function supports(Request $request): ?bool |
| 592 | + { |
| 593 | + } |
| 594 | + |
| 595 | + public function authenticate(Request $request): PassportInterface |
| 596 | + { |
| 597 | + } |
| 598 | + |
| 599 | + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface |
| 600 | + { |
| 601 | + } |
| 602 | + |
| 603 | + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response |
| 604 | + { |
| 605 | + } |
| 606 | + |
| 607 | + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response |
| 608 | + { |
| 609 | + } |
| 610 | +} |
| 611 | + |
| 612 | +class NullAuthenticator implements GuardAuthenticatorInterface |
551 | 613 | {
|
552 | 614 | public function start(Request $request, AuthenticationException $authException = null)
|
553 | 615 | {
|
|
0 commit comments