summaryrefslogtreecommitdiffstats
path: root/Core
diff options
context:
space:
mode:
authorNicolas Grekas <nicolas.grekas@gmail.com>2017-01-03 10:52:33 +0100
committerNicolas Grekas <nicolas.grekas@gmail.com>2017-01-03 10:52:33 +0100
commit43d87514e9ef2f05c6b70f5e9fa57af9eb74bc12 (patch)
treed97f5135e5bea364fea008b4ce13b20e5d4f8e23 /Core
parentd8ef1285ab7a57971090fb70449a4098f2cb7ac9 (diff)
parent866bd6fe7d3b62a0d1c671a2b340aee73241a095 (diff)
downloadsymfony-security-43d87514e9ef2f05c6b70f5e9fa57af9eb74bc12.zip
symfony-security-43d87514e9ef2f05c6b70f5e9fa57af9eb74bc12.tar.gz
symfony-security-43d87514e9ef2f05c6b70f5e9fa57af9eb74bc12.tar.bz2
minor #21088 Rename DebugAccessDecisionManager to TraceableAccessDecisionManager (Jean85)
This PR was squashed before being merged into the 3.3-dev branch (closes #21088). Discussion ---------- Rename DebugAccessDecisionManager to TraceableAccessDecisionManager | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21085 | License | MIT [EDIT] No longer WIP, test passing. Also, test added to preserve BC with the SecurityBundle. Commits ------- c5e0e59 Rename DebugAccessDecisionManager to TraceableAccessDecisionManager
Diffstat (limited to 'Core')
-rw-r--r--Core/Authorization/DebugAccessDecisionManager.php88
-rw-r--r--Core/Authorization/TraceableAccessDecisionManager.php100
-rw-r--r--Core/Tests/Authorization/TraceableAccessDecisionManagerTest.php (renamed from Core/Tests/Authorization/DebugAccessDecisionManagerTest.php)14
3 files changed, 118 insertions, 84 deletions
diff --git a/Core/Authorization/DebugAccessDecisionManager.php b/Core/Authorization/DebugAccessDecisionManager.php
index 219ca76..59a4796 100644
--- a/Core/Authorization/DebugAccessDecisionManager.php
+++ b/Core/Authorization/DebugAccessDecisionManager.php
@@ -11,88 +11,12 @@
namespace Symfony\Component\Security\Core\Authorization;
-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.
+/*
+ * @internal
*
- * @author Javier Eguiluz <javier.eguiluz@gmail.com>
+ * @deprecated The DebugAccessDecisionManager class has been renamed and is deprecated since version 3.3 and will be removed in 4.0. Use the TraceableAccessDecisionManager class instead.
*
- * @internal
+ * This is a placeholder for the old class, that got renamed; this is not a BC break since the class is internal, this
+ * placeholder is here just to help backward compatibility with older SecurityBundle versions.
*/
-class DebugAccessDecisionManager implements AccessDecisionManagerInterface
-{
- private $manager;
- private $strategy;
- private $voters = array();
- private $decisionLog = array();
-
- public function __construct(AccessDecisionManagerInterface $manager)
- {
- $this->manager = $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);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function decide(TokenInterface $token, array $attributes, $object = null)
- {
- $result = $this->manager->decide($token, $attributes, $object);
-
- $this->decisionLog[] = array(
- 'attributes' => $attributes,
- 'object' => $object,
- 'result' => $result,
- );
-
- return $result;
- }
-
- /**
- * {@inheritdoc}
- */
- public function setVoters(array $voters)
- {
- if (!method_exists($this->manager, 'setVoters')) {
- return;
- }
-
- $this->voters = $voters;
- $this->manager->setVoters($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 null === $this->strategy ? '-' : strtolower(substr($this->strategy, 6));
- }
-
- /**
- * @return array
- */
- public function getVoters()
- {
- return $this->voters;
- }
-
- /**
- * @return array
- */
- public function getDecisionLog()
- {
- return $this->decisionLog;
- }
-}
+class_exists(TraceableAccessDecisionManager::class);
diff --git a/Core/Authorization/TraceableAccessDecisionManager.php b/Core/Authorization/TraceableAccessDecisionManager.php
new file mode 100644
index 0000000..6ba2cab
--- /dev/null
+++ b/Core/Authorization/TraceableAccessDecisionManager.php
@@ -0,0 +1,100 @@
+<?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 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 TraceableAccessDecisionManager implements AccessDecisionManagerInterface
+{
+ private $manager;
+ private $strategy;
+ private $voters = array();
+ private $decisionLog = array();
+
+ public function __construct(AccessDecisionManagerInterface $manager)
+ {
+ $this->manager = $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);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function decide(TokenInterface $token, array $attributes, $object = null)
+ {
+ $result = $this->manager->decide($token, $attributes, $object);
+
+ $this->decisionLog[] = array(
+ 'attributes' => $attributes,
+ 'object' => $object,
+ 'result' => $result,
+ );
+
+ return $result;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setVoters(array $voters)
+ {
+ if (!method_exists($this->manager, 'setVoters')) {
+ return;
+ }
+
+ $this->voters = $voters;
+ $this->manager->setVoters($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 null === $this->strategy ? '-' : strtolower(substr($this->strategy, 6));
+ }
+
+ /**
+ * @return array
+ */
+ public function getVoters()
+ {
+ return $this->voters;
+ }
+
+ /**
+ * @return array
+ */
+ public function getDecisionLog()
+ {
+ return $this->decisionLog;
+ }
+}
+
+class_alias(TraceableAccessDecisionManager::class, DebugAccessDecisionManager::class);
diff --git a/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php b/Core/Tests/Authorization/TraceableAccessDecisionManagerTest.php
index 14b0685..1c50f58 100644
--- a/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php
+++ b/Core/Tests/Authorization/TraceableAccessDecisionManagerTest.php
@@ -13,16 +13,17 @@ namespace Symfony\Component\Security\Core\Tests\Authorization;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
+use Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
-class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
+class TraceableAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideObjectsAndLogs
*/
public function testDecideLog($expectedLog, $object)
{
- $adm = new DebugAccessDecisionManager(new AccessDecisionManager());
+ $adm = new TraceableAccessDecisionManager(new AccessDecisionManager());
$adm->decide($this->getMockBuilder(TokenInterface::class)->getMock(), array('ATTRIBUTE_1'), $object);
$this->assertSame($expectedLog, $adm->getDecisionLog());
@@ -40,4 +41,13 @@ class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => $x = array(), 'result' => false)), $x);
yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => $object, 'result' => false)), $object);
}
+
+ public function testDebugAccessDecisionManagerAliasExistsForBC()
+ {
+ $adm = new TraceableAccessDecisionManager(new AccessDecisionManager());
+
+ if (!$adm instanceof DebugAccessDecisionManager) {
+ $this->fail('For BC, TraceableAccessDecisionManager must be an instance of DebugAccessDecisionManager');
+ }
+ }
}