Skip to content

Commit 6ae61f6

Browse files
committed
minor #16460 [SecurityBundle] Fix disabling of RoleHierarchyVoter when passing empty hierarchy (WouterJ)
This PR was submitted for the 2.3 branch but it was merged into the 2.8 branch instead (closes #16460). Discussion ---------- [SecurityBundle] Fix disabling of RoleHierarchyVoter when passing empty hierarchy | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16358 | License | MIT | Doc PR | - * When passing `role_hierarchy: ~` in the config, the role hierarchy voter was still enabled. I've now changed this so that an empty hierarchy also results in disabling this voter. With an empty hierarchy, the voter behaves exactly the same as the RoleVoter, so no BC break is introduced here. * Added some tests for the RoleHierarchyVoter when passing an empty hierarchy. As it then behaves exactly like RoleVoter, the question is whether we shouldn't just always return ACCESS_ABSTAIN when the hierarchy is empty Commits ------- 96afff6 [SecurityBundle] Fix disabling of RoleHierarchyVoter when passing empty hierarchy
2 parents 5486c68 + 96afff6 commit 6ae61f6

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