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 https://github.com/schmittjoh/JMSSecurityExtraBundle/issues/207
| License       | MIT
| Doc PR        | -

Commits
-------

082f1b5 Fixed some issues of the AccessDecisionManager profiler
This commit is contained in:
Fabien Potencier 2016-06-29 17:24:22 +02:00
commit 0b3b0d5268
4 changed files with 17 additions and 11 deletions

View File

@ -10,7 +10,7 @@
<argument type="service" id="security.token_storage" on-invalid="ignore" />
<argument type="service" id="security.role_hierarchy" />
<argument type="service" id="security.logout_url_generator" />
<argument type="service" id="debug.security.access.decision_manager" />
<argument type="service" id="security.access.decision_manager" />
</service>
</services>
</container>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="debug.security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager" decorates="security.access.decision_manager" public="false">

View File

@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.5.9",
"symfony/security": "~3.1",
"symfony/security": "~3.1,>=3.1.2",
"symfony/http-kernel": "~2.8|~3.0",
"symfony/polyfill-php70": "~1.0"
},

View File

@ -26,17 +26,19 @@ class DebugAccessDecisionManager implements AccessDecisionManagerInterface
{
private $manager;
private $strategy;
private $voters;
private $voters = array();
private $decisionLog = array();
public function __construct(AccessDecisionManager $manager)
public function __construct(AccessDecisionManagerInterface $manager)
{
$this->manager = $manager;
// The strategy is stored in a private property of the decorated service
$reflection = new \ReflectionProperty($manager, 'strategy');
$reflection->setAccessible(true);
$this->strategy = $reflection->getValue($manager);
if ($this->manager instanceof AccessDecisionManager) {
// The strategy is stored in a private property of the decorated service
$reflection = new \ReflectionProperty(AccessDecisionManager::class, 'strategy');
$reflection->setAccessible(true);
$this->strategy = $reflection->getValue($manager);
}
}
/**
@ -60,6 +62,10 @@ class DebugAccessDecisionManager implements AccessDecisionManagerInterface
*/
public function setVoters(array $voters)
{
if (!$this->manager instanceof AccessDecisionManager) {
return;
}
$this->voters = $voters;
$this->manager->setVoters($voters);
}
@ -72,7 +78,7 @@ class DebugAccessDecisionManager implements AccessDecisionManagerInterface
// The $strategy property is misleading because it stores the name of its
// method (e.g. 'decideAffirmative') instead of the original strategy name
// (e.g. 'affirmative')
return strtolower(substr($this->strategy, 6));
return null === $this->strategy ? '-' : strtolower(substr($this->strategy, 6));
}
/**