Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #17887 Show more information in the security profiler (javier…
…eguiluz) This PR was squashed before being merged into the 3.1-dev branch (closes #17887). Discussion ---------- Show more information in the security profiler | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17856 | License | MIT | Doc PR | - This is an early prototype to explore the feature of displaying more information in the security panel. Example: ![profiler_security](https://cloud.githubusercontent.com/assets/73419/13221929/0235fc46-d97e-11e5-981a-249b7148f3a6.png) Commits ------- b12152d Show more information in the security profiler
- Loading branch information
Showing
8 changed files
with
266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Symfony/Bundle/SecurityBundle/Resources/config/security_debug.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?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"> | ||
|
||
<services> | ||
<service id="debug.security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager" decorates="security.access.decision_manager" public="false"> | ||
<argument type="service" id="debug.security.access.decision_manager.inner" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/Symfony/Component/Security/Core/Authorization/DebugAccessDecisionManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Authorization; | ||
|
||
use Doctrine\Common\Util\ClassUtils; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
|
||
/** | ||
* Decorates the original AccessDecisionManager class to log information | ||
* about the security voters and the decisions made by them. | ||
* | ||
* @author Javier Eguiluz <javier.eguiluz@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
class DebugAccessDecisionManager implements AccessDecisionManagerInterface | ||
{ | ||
private $manager; | ||
private $strategy; | ||
private $voters; | ||
private $decisionLog = array(); | ||
|
||
public function __construct(AccessDecisionManager $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); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function decide(TokenInterface $token, array $attributes, $object = null) | ||
{ | ||
$result = $this->manager->decide($token, $attributes, $object); | ||
|
||
$this->decisionLog[] = array( | ||
'attributes' => $attributes, | ||
'object' => $this->getStringRepresentation($object), | ||
'result' => $result, | ||
); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setVoters(array $voters) | ||
{ | ||
$this->voters = $voters; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getStrategy() | ||
{ | ||
// 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 array | ||
*/ | ||
public function getVoters() | ||
{ | ||
return $this->voters; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getDecisionLog() | ||
{ | ||
return $this->decisionLog; | ||
} | ||
|
||
/** | ||
* @param mixed $object | ||
* | ||
* @return string | ||
*/ | ||
private function getStringRepresentation($object) | ||
{ | ||
if (null === $object) { | ||
return 'NULL'; | ||
} | ||
|
||
if (!is_object($object)) { | ||
return sprintf('%s (%s)', gettype($object), $object); | ||
} | ||
|
||
$objectClass = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($object) : get_class($object); | ||
|
||
if (method_exists($object, 'getId')) { | ||
$objectAsString = sprintf('ID: %s', $object->getId()); | ||
} elseif (method_exists($object, '__toString')) { | ||
$objectAsString = (string) $object; | ||
} else { | ||
$objectAsString = sprintf('object hash: %s', spl_object_hash($object)); | ||
} | ||
|
||
return sprintf('%s (%s)', $objectClass, $objectAsString); | ||
} | ||
} |