Skip to content

Commit 0b3b0d5

Browse files
committed
bug #18934 Fixed some issues of the AccessDecisionManager profiler (javiereguiluz)
This PR was squashed before being merged into the 3.1 branch (closes #18934). Discussion ---------- Fixed some issues of the AccessDecisionManager profiler | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19022 https://github.com/symfony/symfony-standard/issues/968 schmittjoh/JMSSecurityExtraBundle#207 | License | MIT | Doc PR | - Commits ------- 082f1b5 Fixed some issues of the AccessDecisionManager profiler
2 parents fe6841c + 082f1b5 commit 0b3b0d5

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<argument type="service" id="security.token_storage" on-invalid="ignore" />
1111
<argument type="service" id="security.role_hierarchy" />
1212
<argument type="service" id="security.logout_url_generator" />
13-
<argument type="service" id="debug.security.access.decision_manager" />
13+
<argument type="service" id="security.access.decision_manager" />
1414
</service>
1515
</services>
1616
</container>

src/Symfony/Bundle/SecurityBundle/Resources/config/security_debug.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" ?>
22

33
<container xmlns="http://symfony.com/schema/dic/services"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
88
<service id="debug.security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager" decorates="security.access.decision_manager" public="false">

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.5.9",
20-
"symfony/security": "~3.1",
20+
"symfony/security": "~3.1,>=3.1.2",
2121
"symfony/http-kernel": "~2.8|~3.0",
2222
"symfony/polyfill-php70": "~1.0"
2323
},

src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ class DebugAccessDecisionManager implements AccessDecisionManagerInterface
2626
{
2727
private $manager;
2828
private $strategy;
29-
private $voters;
29+
private $voters = array();
3030
private $decisionLog = array();
3131

32-
public function __construct(AccessDecisionManager $manager)
32+
public function __construct(AccessDecisionManagerInterface $manager)
3333
{
3434
$this->manager = $manager;
3535

36-
// The strategy is stored in a private property of the decorated service
37-
$reflection = new \ReflectionProperty($manager, 'strategy');
38-
$reflection->setAccessible(true);
39-
$this->strategy = $reflection->getValue($manager);
36+
if ($this->manager instanceof AccessDecisionManager) {
37+
// The strategy is stored in a private property of the decorated service
38+
$reflection = new \ReflectionProperty(AccessDecisionManager::class, 'strategy');
39+
$reflection->setAccessible(true);
40+
$this->strategy = $reflection->getValue($manager);
41+
}
4042
}
4143

4244
/**
@@ -60,6 +62,10 @@ public function decide(TokenInterface $token, array $attributes, $object = null)
6062
*/
6163
public function setVoters(array $voters)
6264
{
65+
if (!$this->manager instanceof AccessDecisionManager) {
66+
return;
67+
}
68+
6369
$this->voters = $voters;
6470
$this->manager->setVoters($voters);
6571
}
@@ -72,7 +78,7 @@ public function getStrategy()
7278
// The $strategy property is misleading because it stores the name of its
7379
// method (e.g. 'decideAffirmative') instead of the original strategy name
7480
// (e.g. 'affirmative')
75-
return strtolower(substr($this->strategy, 6));
81+
return null === $this->strategy ? '-' : strtolower(substr($this->strategy, 6));
7682
}
7783

7884
/**

0 commit comments

Comments
 (0)