Skip to content

Commit 96afff6

Browse files
wouterjfabpot
authored andcommitted
[SecurityBundle] Fix disabling of RoleHierarchyVoter when passing empty hierarchy
1 parent 5486c68 commit 96afff6

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function configureDbalAclProvider(array $config, ContainerBuilder $conta
168168
*/
169169
private function createRoleHierarchy($config, ContainerBuilder $container)
170170
{
171-
if (!isset($config['role_hierarchy'])) {
171+
if (!isset($config['role_hierarchy']) || 0 === count($config['role_hierarchy'])) {
172172
$container->removeDefinition('security.access.role_hierarchy_voter');
173173

174174
return;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,33 @@ public function testFirewallWithInvalidUserProvider()
9494
$container->compile();
9595
}
9696

97+
public function testDisableRoleHierarchyVoter()
98+
{
99+
$container = $this->getRawContainer();
100+
101+
$container->loadFromExtension('security', array(
102+
'providers' => array(
103+
'default' => array('id' => 'foo'),
104+
),
105+
106+
'role_hierarchy' => null,
107+
108+
'firewalls' => array(
109+
'some_firewall' => array(
110+
'pattern' => '/.*',
111+
'http_basic' => null,
112+
),
113+
),
114+
));
115+
116+
$container->compile();
117+
118+
$admDefinition = $container->getDefinition('security.access.decision_manager');
119+
$registeredVoters = array_map('strval', $admDefinition->getArgument(0));
120+
121+
$this->assertNotContains('security.access.role_hierarchy_voter', $registeredVoters);
122+
}
123+
97124
protected function getRawContainer()
98125
{
99126
$container = new ContainerBuilder();

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,19 @@ public function getVoteTests()
3333
array(array('ROLE_FOO'), array('ROLE_FOOBAR'), VoterInterface::ACCESS_GRANTED),
3434
));
3535
}
36+
37+
/**
38+
* @dataProvider getVoteWithEmptyHierarchyTests
39+
*/
40+
public function testVoteWithEmptyHierarchy($roles, $attributes, $expected)
41+
{
42+
$voter = new RoleHierarchyVoter(new RoleHierarchy(array()));
43+
44+
$this->assertSame($expected, $voter->vote($this->getToken($roles), null, $attributes));
45+
}
46+
47+
public function getVoteWithEmptyHierarchyTests()
48+
{
49+
return parent::getVoteTests();
50+
}
3651
}

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