Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78cf382

Browse filesBrowse files
committed
feature #14733 [Security] Add setVoters() on AccessDecisionManager (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [Security] Add setVoters() on AccessDecisionManager | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | partially #12360 | License | MIT | Doc PR | - Alternative for #14550 Commits ------- 3fd7cea [Security] Add setVoters() on AccessDecisionManager
2 parents 2983ecb + 3fd7cea commit 78cf382
Copy full SHA for 78cf382

File tree

Expand file treeCollapse file tree

4 files changed

+18
-15
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+18
-15
lines changed

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Reference;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Exception\LogicException;
1718

1819
/**
1920
* Adds all configured security voters to the access decision manager.
@@ -40,6 +41,10 @@ public function process(ContainerBuilder $container)
4041
$voters = iterator_to_array($voters);
4142
ksort($voters);
4243

43-
$container->getDefinition('security.access.decision_manager')->replaceArgument(0, array_values($voters));
44+
if (!$voters) {
45+
throw new LogicException('No security voters found. You need to tag at least one with "security.voter"');
46+
}
47+
48+
$container->getDefinition('security.access.decision_manager')->addMethodCall('setVoters', array(array_values($voters)));
4449
}
4550
}

‎src/Symfony/Bundle/SecurityBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"symfony/security": "~2.7|~3.0.0",
20+
"symfony/security": "~2.8|~3.0.0",
2121
"symfony/http-kernel": "~2.2|~3.0.0"
2222
},
2323
"require-dev": {

‎src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
4141
*
4242
* @throws \InvalidArgumentException
4343
*/
44-
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
44+
public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
4545
{
46-
if (!$voters) {
47-
throw new \InvalidArgumentException('You must at least add one voter.');
48-
}
49-
5046
$strategyMethod = 'decide'.ucfirst($strategy);
5147
if (!is_callable(array($this, $strategyMethod))) {
5248
throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy));
@@ -58,6 +54,16 @@ public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIV
5854
$this->allowIfEqualGrantedDeniedDecisions = (bool) $allowIfEqualGrantedDeniedDecisions;
5955
}
6056

57+
/**
58+
* Configures the voters.
59+
*
60+
* @param VoterInterface[] $voters An array of VoterInterface instances
61+
*/
62+
public function setVoters(array $voters)
63+
{
64+
$this->voters = $voters;
65+
}
66+
6167
/**
6268
* {@inheritdoc}
6369
*/

‎src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public function testSupportsAttribute()
4646
$this->assertFalse($manager->supportsAttribute('foo'));
4747
}
4848

49-
/**
50-
* @expectedException \InvalidArgumentException
51-
*/
52-
public function testSetVotersEmpty()
53-
{
54-
$manager = new AccessDecisionManager(array());
55-
}
56-
5749
/**
5850
* @expectedException \InvalidArgumentException
5951
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.