|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
| 16 | +use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface; |
| 17 | +use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; |
16 | 18 | use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
|
17 | 19 | use Symfony\Bundle\SecurityBundle\SecurityBundle;
|
18 | 20 | use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
|
19 | 21 | use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\Security\EntryPointStub;
|
20 | 22 | use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\GuardedBundle\AppCustomAuthenticator;
|
| 23 | +use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
21 | 24 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
22 | 25 | use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
23 | 26 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
@@ -601,6 +604,29 @@ public function testCompilesWithSessionListenerWithStatefulllFirewallWithAuthent
|
601 | 604 | $this->assertTrue($container->has('security.listener.session.'.$firewallId));
|
602 | 605 | }
|
603 | 606 |
|
| 607 | + public function testConfigureCustomFirewallListener(): void |
| 608 | + { |
| 609 | + $container = $this->getRawContainer(); |
| 610 | + /** @var SecurityExtension $extension */ |
| 611 | + $extension = $container->getExtension('security'); |
| 612 | + $extension->addSecurityListenerFactory(new TestFirewallListenerFactory()); |
| 613 | + |
| 614 | + $container->loadFromExtension('security', [ |
| 615 | + 'firewalls' => [ |
| 616 | + 'main' => [ |
| 617 | + 'custom_listener' => true, |
| 618 | + ], |
| 619 | + ], |
| 620 | + ]); |
| 621 | + |
| 622 | + $container->compile(); |
| 623 | + |
| 624 | + /** @var IteratorArgument $listenersIteratorArgument */ |
| 625 | + $listenersIteratorArgument = $container->getDefinition('security.firewall.map.context.main')->getArgument(0); |
| 626 | + $firewallListeners = array_map('strval', $listenersIteratorArgument->getValues()); |
| 627 | + $this->assertContains('custom_firewall_listener_id', $firewallListeners); |
| 628 | + } |
| 629 | + |
604 | 630 | protected function getRawContainer()
|
605 | 631 | {
|
606 | 632 | $container = new ContainerBuilder();
|
@@ -689,3 +715,30 @@ public function supportsRememberMe()
|
689 | 715 | {
|
690 | 716 | }
|
691 | 717 | }
|
| 718 | + |
| 719 | +class TestFirewallListenerFactory implements SecurityFactoryInterface, FirewallListenerFactoryInterface |
| 720 | +{ |
| 721 | + public function createListeners(ContainerBuilder $container, string $firewallName, array $config): array |
| 722 | + { |
| 723 | + return ['custom_firewall_listener_id']; |
| 724 | + } |
| 725 | + |
| 726 | + public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint) |
| 727 | + { |
| 728 | + return ['provider_id', 'listener_id', $defaultEntryPoint]; |
| 729 | + } |
| 730 | + |
| 731 | + public function getPosition() |
| 732 | + { |
| 733 | + return 'form'; |
| 734 | + } |
| 735 | + |
| 736 | + public function getKey() |
| 737 | + { |
| 738 | + return 'custom_listener'; |
| 739 | + } |
| 740 | + |
| 741 | + public function addConfiguration(NodeDefinition $builder) |
| 742 | + { |
| 743 | + } |
| 744 | +} |
0 commit comments