diff --git a/src/Symfony/Bundle/SecurityBundle/CHANGELOG.md b/src/Symfony/Bundle/SecurityBundle/CHANGELOG.md index 89b5130493c22..8c54471d1e19f 100644 --- a/src/Symfony/Bundle/SecurityBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/SecurityBundle/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Deprecate `Security::ACCESS_DENIED_ERROR`, `AUTHENTICATION_ERROR` and `LAST_USERNAME` constants, use the ones on `SecurityRequestAttributes` instead + * Allow an array of `pattern` in firewall configuration 6.3 --- diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index e982fc1871940..992a3b5bb6649 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -191,7 +191,12 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto ; $firewallNodeBuilder - ->scalarNode('pattern')->end() + ->scalarNode('pattern') + ->beforeNormalization() + ->ifArray() + ->then(fn ($v) => sprintf('(?:%s)', implode('|', $v))) + ->end() + ->end() ->scalarNode('host')->end() ->arrayNode('methods') ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php index 44193e4ec0a58..ea01daa96bf73 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php @@ -716,6 +716,15 @@ public function testFirewallLogoutClearSiteData() $this->assertSame(['cookies', 'executionContexts'], $ClearSiteDataConfig); } + public function testFirewallPatterns() + { + $container = $this->getContainer('firewall_patterns'); + $chainRequestMatcherId = (string) $container->getDefinition('security.firewall.map')->getArgument(1)->getValues()['security.firewall.map.context.no_security']; + $requestMatcherId = (string) $container->getDefinition($chainRequestMatcherId)->getArgument(0)[0]; + + $this->assertSame('(?:^/register$|^/documentation$)', $container->getDefinition($requestMatcherId)->getArgument(0)); + } + protected function getContainer($file) { $file .= '.'.$this->getFileExtension(); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/firewall_patterns.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/firewall_patterns.php new file mode 100644 index 0000000000000..1b1acdd448b55 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/firewall_patterns.php @@ -0,0 +1,12 @@ +loadFromExtension('security', [ + 'firewalls' => [ + 'no_security' => [ + 'pattern' => [ + '^/register$', + '^/documentation$', + ], + ], + ], +]); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/firewall_patterns.yml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/firewall_patterns.yml new file mode 100644 index 0000000000000..f57fe7131c43f --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/firewall_patterns.yml @@ -0,0 +1,6 @@ +security: + firewalls: + no_security: + pattern: + - "^/register$" + - "^/documentation$" diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php index eccfabef77950..2624adc9bebcd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php @@ -17,6 +17,11 @@ class XmlCompleteConfigurationTest extends CompleteConfigurationTestCase { + public function testFirewallPatterns() + { + $this->markTestSkipped('This features is not supported in XML.'); + } + protected function getLoader(ContainerBuilder $container) { return new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: