8000 [SecurityBundle] Allow an array of `pattern` in firewall configuration · symfony/symfony@46344de · GitHub
[go: up one dir, main page]

Skip to content

Commit 46344de

Browse files
lyrixxchalasr
authored andcommitted
[SecurityBundle] Allow an array of pattern in firewall configuration
1 parent 510e51f commit 46344de

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Deprecate `Security::ACCESS_DENIED_ERROR`, `AUTHENTICATION_ERROR` and `LAST_USERNAME` constants, use the ones on `SecurityRequestAttributes` instead
8+
* Allow an array of `pattern` in firewall configuration
89

910
6.3
1011
---

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
191191
;
192192

193193
$firewallNodeBuilder
194-
->scalarNode('pattern')->end()
194+
->scalarNode('pattern')
195+
->beforeNormalization()
196+
->ifArray()
197+
->then(fn ($v) => sprintf('(?:%s)', implode('|', $v)))
198+
->end()
199+
->end()
195200
->scalarNode('host')->end()
196201
->arrayNode('methods')
197202
->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php

+9
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,15 @@ public function testFirewallLogoutClearSiteData()
716716
$this->assertSame(['cookies', 'executionContexts'], $ClearSiteDataConfig);
717717
}
718718

719+
public function testFirewallPatterns()
720+
{
721+
$container = $this->getContainer('firewall_patterns');
722+
$chainRequestMatcherId = (string) $container->getDefinition('security.firewall.map')->getArgument(1)->getValues()['security.firewall.map.context.no_security'];
723+
$requestMatcherId = (string) $container->getDefinition($chainRequestMatcherId)->getArgument(0)[0];
724+
725+
$this->assertSame('(?:^/register$|^/documentation$)', $container->getDefinition($requestMatcherId)->getArgument(0));
726+
}
727+
719728
protected function getContainer($file)
720729
{
721730
$file .= '.'.$this->getFileExtension();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', [
4+
'firewalls' => [
5+
'no_security' => [
6+
'pattern' => [
7+
'^/register$',
8+
'^/documentation$',
9+
],
10+
],
11+
],
12+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
security:
2+
firewalls:
3+
no_security:
4+
pattern:
5+
- "^/register$"
6+
- "^/documentation$"

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
class XmlCompleteConfigurationTest extends CompleteConfigurationTestCase
1919
{
20+
public function testFirewallPatterns()
21+
{
22+
$this->markTestSkipped('This features is not supported in XML.');
23+
}
24+
2025
protected function getLoader(ContainerBuilder $container)
2126
{
2227
return new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));

0 commit comments

Comments
 (0)
0