Skip to content

Commit d1ef0f3

Browse files
committed
merged branch pkruithof/firewall-host-option (PR #8905)
This PR was merged into the master branch. Discussion ---------- Added 'host' option to firewall configuration | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7103 | License | MIT | Doc PR | This is a follow-up of #8880. Commits ------- 94d648b Added 'host' option to firewall configuration
2 parents 6f59f07 + 94d648b commit d1ef0f3

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.4.0
5+
-----
6+
7+
* Added 'host' option to firewall configuration
8+
49
2.3.0
510
-----
611

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
199199

200200
$firewallNodeBuilder
201201
->scalarNode('pattern')->end()
202+
->scalarNode('host')->end()
202203
->booleanNode('security')->defaultTrue()->end()
203204
->scalarNode('request_matcher')->end()
204205
->scalarNode('access_denied_url')->end()

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
244244
$matcher = null;
245245
if (isset($firewall['request_matcher'])) {
246246
$matcher = new Reference($firewall['request_matcher']);
247-
} elseif (isset($firewall['pattern'])) {
248-
$matcher = $this->createRequestMatcher($container, $firewall['pattern']);
247+
} elseif (isset($firewall['pattern']) || isset($firewall['host'])) {
248+
$pattern = isset($firewall['pattern']) ? $firewall['pattern'] : null;
249+
$host = isset($firewall['host']) ? $firewall['host'] : null;
250+
$matcher = $this->createRequestMatcher($container, $pattern, $host);
249251
}
250252

251253
// Security disabled?

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,41 @@ public function testFirewalls()
8585
'security.access_listener',
8686
'security.authentication.switchuser_listener.secure',
8787
),
88+
array(
89+
'security.channel_listener',
90+
'security.context_listener.0',
91+
'security.authentication.listener.basic.host',
92+
'security.authentication.listener.anonymous.host',
93+
'security.access_listener',
94+
),
8895
), $listeners);
8996
}
9097

98+
public function testFirewallRequestMatchers()
99+
{
100+
$container = $this->getContainer('container1');
101+
102+
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
103+
$matchers = array();
104+
105+
foreach ($arguments[1] as $reference) {
106+
if ($reference instanceof Reference) {
107+
$definition = $container->getDefinition((string) $reference);
108+
$matchers[] = $definition->getArguments();
109+
}
110+
}
111+
112+
$this->assertEquals(array(
113+
array(
114+
'/login',
115+
),
116+
array(
117+
'/test',
118+
'foo\\.example\\.org',
119+
),
120+
), $matchers);
121+
}
122+
91123
public function testAccess()
92124
{
93125
$container = $this->getContainer('container1');

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
'x509' => true,
7272
'logout' => true,
7373
),
74+
'host' => array(
75+
'pattern' => '/test',
76+
'host' => 'foo\\.example\\.org',
77+
'anonymous' => true,
78+
'http_basic' => true,
79+
),
7480
),
7581

7682
'access_control' => array(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
<logout />
5858
</firewall>
5959

60+
<firewall name="host" pattern="/test" host="foo\.example\.org">
61+
<anonymous />
62+
<http-basic />
63+
</firewall>
64+
6065
<role id="ROLE_ADMIN">ROLE_USER</role>
6166
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
6267
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ security:
5353
switch_user: true
5454
x509: true
5555
logout: true
56+
host:
57+
pattern: /test
58+
host: foo\.example\.org
59+
anonymous: true
60+
http_basic: true
5661

5762
role_hierarchy:
5863
ROLE_ADMIN: ROLE_USER

0 commit comments

Comments
 (0)