Skip to content

Commit

Permalink
Added 'host' option to firewall configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pkruithof committed Sep 1, 2013
1 parent cade045 commit 94d648b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.4.0
-----

* Added 'host' option to firewall configuration

2.3.0
-----

Expand Down
Expand Up @@ -199,6 +199,7 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto

$firewallNodeBuilder
->scalarNode('pattern')->end()
->scalarNode('host')->end()
->booleanNode('security')->defaultTrue()->end()
->scalarNode('request_matcher')->end()
->scalarNode('access_denied_url')->end()
Expand Down
Expand Up @@ -244,8 +244,10 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
$matcher = null;
if (isset($firewall['request_matcher'])) {
$matcher = new Reference($firewall['request_matcher']);
} elseif (isset($firewall['pattern'])) {
$matcher = $this->createRequestMatcher($container, $firewall['pattern']);
} elseif (isset($firewall['pattern']) || isset($firewall['host'])) {
$pattern = isset($firewall['pattern']) ? $firewall['pattern'] : null;
$host = isset($firewall['host']) ? $firewall['host'] : null;
$matcher = $this->createRequestMatcher($container, $pattern, $host);
}

// Security disabled?
Expand Down
Expand Up @@ -85,9 +85,41 @@ public function testFirewalls()
'security.access_listener',
'security.authentication.switchuser_listener.secure',
),
array(
'security.channel_listener',
'security.context_listener.0',
'security.authentication.listener.basic.host',
'security.authentication.listener.anonymous.host',
'security.access_listener',
),
), $listeners);
}

public function testFirewallRequestMatchers()
{
$container = $this->getContainer('container1');

$arguments = $container->getDefinition('security.firewall.map')->getArguments();
$matchers = array();

foreach ($arguments[1] as $reference) {
if ($reference instanceof Reference) {
$definition = $container->getDefinition((string) $reference);
$matchers[] = $definition->getArguments();
}
}

$this->assertEquals(array(
array(
'/login',
),
array(
'/test',
'foo\\.example\\.org',
),
), $matchers);
}

public function testAccess()
{
$container = $this->getContainer('container1');
Expand Down
Expand Up @@ -71,6 +71,12 @@
'x509' => true,
'logout' => true,
),
'host' => array(
'pattern' => '/test',
'host' => 'foo\\.example\\.org',
'anonymous' => true,
'http_basic' => true,
),
),

'access_control' => array(
Expand Down
Expand Up @@ -57,6 +57,11 @@
<logout />
</firewall>

<firewall name="host" pattern="/test" host="foo\.example\.org">
<anonymous />
<http-basic />
</firewall>

<role id="ROLE_ADMIN">ROLE_USER</role>
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
Expand Down
Expand Up @@ -53,6 +53,11 @@ security:
switch_user: true
x509: true
logout: true
host:
pattern: /test
host: foo\.example\.org
anonymous: true
http_basic: true

role_hierarchy:
ROLE_ADMIN: ROLE_USER
Expand Down

0 comments on commit 94d648b

Please sign in to comment.