Skip to content

Commit e83df40

Browse files
committed
[SecurityBundle] Allow an array of pattern in firewall configuration
1 parent 86c41bb commit e83df40

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 1 deletion
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+
->ifTrue(fn ($v) => is_array($v))
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

Lines changed: 9 additions & 0 deletions
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();
Lines changed: 12 additions & 0 deletions
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+
]);
Lines changed: 6 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy