diff options
Diffstat (limited to 'Core')
-rw-r--r-- | Core/Authorization/DebugAccessDecisionManager.php | 88 | ||||
-rw-r--r-- | Core/Authorization/TraceableAccessDecisionManager.php | 100 | ||||
-rw-r--r-- | Core/LICENSE | 2 | ||||
-rw-r--r-- | Core/Tests/Authorization/TraceableAccessDecisionManagerTest.php (renamed from Core/Tests/Authorization/DebugAccessDecisionManagerTest.php) | 14 |
4 files changed, 119 insertions, 85 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/LICENSE b/Core/LICENSE index 12a7453..17d16a1 100644 --- a/Core/LICENSE +++ b/Core/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2016 Fabien Potencier +Copyright (c) 2004-2017 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal 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'); + } + } } |