Skip to content

Commit 2878757

Browse files
author
Daniel Tschinder
committed
Make it possible to match the request based on HTTP methods in the firewall configuration
1 parent 535d6c8 commit 2878757

File tree

6 files changed

+10
-2
lines changed

6 files changed

+10
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
201201
$firewallNodeBuilder
202202
->scalarNode('pattern')->end()
203203
->scalarNode('host')->end()
204+
->arrayNode('methods')
205+
->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
206+
->prototype('scalar')->end()
207+
->end()
204208
->booleanNode('security')->defaultTrue()->end()
205209
->scalarNode('request_matcher')->end()
206210
->scalarNode('access_denied_url')->end()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
254254
} elseif (isset($firewall['pattern']) || isset($firewall['host'])) {
255255
$pattern = isset($firewall['pattern']) ? $firewall['pattern'] : null;
256256
$host = isset($firewall['host']) ? $firewall['host'] : null;
257-
$matcher = $this->createRequestMatcher($container, $pattern, $host);
257+
$methods = isset($firewall['methods']) ? $firewall['methods'] : array();
258+
$matcher = $this->createRequestMatcher($container, $pattern, $host, $methods);
258259
}
259260

260261
// Security disabled?

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function testFirewallRequestMatchers()
117117
array(
118118
'/test',
119119
'foo\\.example\\.org',
120+
array('GET', 'POST'),
120121
),
121122
), $matchers);
122123
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
'host' => array(
7575
'pattern' => '/test',
7676
'host' => 'foo\\.example\\.org',
77+
'methods' => array('GET', 'POST'),
7778
'anonymous' => true,
7879
'http_basic' => true,
7980
),

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<logout />
5858
</firewall>
5959

60-
<firewall name="host" pattern="/test" host="foo\.example\.org">
60+
<firewall name="host" pattern="/test" host="foo\.example\.org" methods="GET,POST">
6161
<anonymous />
6262
<http-basic />
6363
</firewall>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ security:
5656
host:
5757
pattern: /test
5858
host: foo\.example\.org
59+
methods: [GET,POST]
5960
anonymous: true
6061
http_basic: true
6162

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