Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge branch '2.8'
Browse files Browse the repository at this point in the history
* 2.8: (23 commits)
  [Validator] added BIC (SWIFT-BIC) validation constraint
  [TwigBridge] Foundation form layout integration
  [Security] Deprecated supportsAttribute and supportsClass methods
  bumped Symfony version to 2.7.6
  updated VERSION for 2.7.5
  updated CHANGELOG for 2.7.5
  bumped Symfony version to 2.3.34
  updated VERSION for 2.3.33
  update CONTRIBUTORS for 2.3.33
  updated CHANGELOG for 2.3.33
  [Console] Fix transient HHVM test
  [OptionsResolver] Fix catched exception along the dependency tree mistakenly detects cyclic dependencies
  fixed tests
  [DI] Support deprecated definitions in decorators
  [DI] Allow to change the deprecation message in Definition
  [DI] Trigger a deprecated error on the container builder
  [DI] Dump the deprecated status
  [DI] Supports the deprecated tag in loaders
  [DI] Add a deprecated status to definitions
  Fixing test locations
  ...
  • Loading branch information
fabpot committed Sep 26, 2015
2 parents a54d984 + d250979 commit 18a3795
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,11 @@ CHANGELOG
`Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface` instead
* deprecated `Symfony\Component\Security\Core\Util\ClassUtils`, use
`Symfony\Component\Security\Acl\Util\ClassUtils` instead
* deprecated `supportsAttribute()` and `supportsClass()` methods of
`Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface` and
`Symfony\Component\Security\Core\Authorization\Voter\VoterInterface`.
* deprecated `getSupportedAttributes()` and `getSupportedClasses()` methods of
`Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter`, use `supports()` instead.

2.7.0
-----
Expand Down
4 changes: 4 additions & 0 deletions Core/Authorization/AccessDecisionManager.php
Expand Up @@ -77,6 +77,8 @@ public function decide(TokenInterface $token, array $attributes, $object = null)
*/
public function supportsAttribute($attribute)
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');

foreach ($this->voters as $voter) {
if ($voter->supportsAttribute($attribute)) {
return true;
Expand All @@ -91,6 +93,8 @@ public function supportsAttribute($attribute)
*/
public function supportsClass($class)
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');

foreach ($this->voters as $voter) {
if ($voter->supportsClass($class)) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions Core/Authorization/AccessDecisionManagerInterface.php
Expand Up @@ -37,6 +37,8 @@ public function decide(TokenInterface $token, array $attributes, $object = null)
* @param string $attribute An attribute
*
* @return bool true if this decision manager supports the attribute, false otherwise
*
* @deprecated since version 2.8, to be removed in 3.0.
*/
public function supportsAttribute($attribute);

Expand All @@ -46,6 +48,8 @@ public function supportsAttribute($attribute);
* @param string $class A class name
*
* @return true if this decision manager can process the class
*
* @deprecated since version 2.8, to be removed in 3.0.
*/
public function supportsClass($class);
}
73 changes: 69 additions & 4 deletions Core/Authorization/Voter/AbstractVoter.php
Expand Up @@ -26,6 +26,8 @@ abstract class AbstractVoter implements VoterInterface
*/
public function supportsAttribute($attribute)
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');

return in_array($attribute, $this->getSupportedAttributes());
}

Expand All @@ -34,6 +36,8 @@ public function supportsAttribute($attribute)
*/
public function supportsClass($class)
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');

foreach ($this->getSupportedClasses() as $supportedClass) {
if ($supportedClass === $class || is_subclass_of($class, $supportedClass)) {
return true;
Expand All @@ -58,12 +62,13 @@ public function supportsClass($class)
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
if (!$object || !$this->supportsClass(get_class($object))) {
if (!$object) {
return self::ACCESS_ABSTAIN;
}

// abstain vote by default in case none of the attributes are supported
$vote = self::ACCESS_ABSTAIN;
$class = get_class($object);

$reflector = new \ReflectionMethod($this, 'voteOnAttribute');
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter';
Expand All @@ -72,7 +77,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
}

foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
if (!$this->supports($attribute, $class)) {
continue;
}

Expand All @@ -95,19 +100,79 @@ public function vote(TokenInterface $token, $object, array $attributes)
return $vote;
}

/**
* Determines if the attribute and class are supported by this voter.
*
* To determine if the passed class is instance of the supported class, the
* isClassInstanceOf() method can be used.
*
* This method will become abstract in 3.0.
*
* @param string $attribute An attribute
* @param string $class The fully qualified class name of the passed object
*
* @return bool True if the attribute and class is supported, false otherwise
*/
protected function supports($attribute, $class)
{
@trigger_error('The getSupportedClasses and getSupportedAttributes methods are deprecated since version 2.8 and will be removed in version 3.0. Overwrite supports instead.');

$classIsSupported = false;
foreach ($this->getSupportedClasses() as $supportedClass) {
if ($this->isClassInstanceOf($class, $supportedClass)) {
$classIsSupported = true;
break;
}
}

if (!$classIsSupported) {
return false;
}

if (!in_array($attribute, $this->getSupportedAttributes())) {
return false;
}

return true;
}

/**
* A helper method to test if the actual class is instanceof or equal
* to the expected class.
*
* @param string $actualClass The actual class name
* @param string $expectedClass The expected class name
*
* @return bool
*/
protected function isClassInstanceOf($actualClass, $expectedClass)
{
return $expectedClass === $actualClass || is_subclass_of($actualClass, $expectedClass);
}

/**
* Return an array of supported classes. This will be called by supportsClass.
*
* @return array an array of supported classes, i.e. array('Acme\DemoBundle\Model\Product')
*
* @deprecated since version 2.8, to be removed in 3.0. Use supports() instead.
*/
abstract protected function getSupportedClasses();
protected function getSupportedClasses()
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');
}

/**
* Return an array of supported attributes. This will be called by supportsAttribute.
*
* @return array an array of supported attributes, i.e. array('CREATE', 'READ')
*
* @deprecated since version 2.8, to be removed in 3.0. Use supports() instead.
*/
abstract protected function getSupportedAttributes();
protected function getSupportedAttributes()
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.');
}

/**
* Perform a single access check operation on a given attribute, object and (optionally) user
Expand Down
4 changes: 4 additions & 0 deletions Core/Authorization/Voter/VoterInterface.php
Expand Up @@ -30,6 +30,8 @@ interface VoterInterface
* @param string $attribute An attribute
*
* @return bool true if this Voter supports the attribute, false otherwise
*
* @deprecated since version 2.8, to be removed in 3.0.
*/
public function supportsAttribute($attribute);

Expand All @@ -39,6 +41,8 @@ public function supportsAttribute($attribute);
* @param string $class A class name
*
* @return bool true if this Voter can process the class
*
* @deprecated since version 2.8, to be removed in 3.0.
*/
public function supportsClass($class);

Expand Down
6 changes: 6 additions & 0 deletions Core/Tests/Authorization/AccessDecisionManagerTest.php
Expand Up @@ -16,6 +16,9 @@

class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @group legacy
*/
public function testSupportsClass()
{
$manager = new AccessDecisionManager(array(
Expand All @@ -31,6 +34,9 @@ public function testSupportsClass()
$this->assertFalse($manager->supportsClass('FooClass'));
}

/**
* @group legacy
*/
public function testSupportsAttribute()
{
$manager = new AccessDecisionManager(array(
Expand Down
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Tests\Core\Authentication\Voter;
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
Expand Down Expand Up @@ -78,7 +78,7 @@ class VoterFixture extends AbstractVoter
protected function getSupportedClasses()
{
return array(
'Symfony\Component\Security\Tests\Core\Authentication\Voter\ObjectFixture',
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
);
}

Expand All @@ -98,7 +98,7 @@ class DeprecatedVoterFixture extends AbstractVoter
protected function getSupportedClasses()
{
return array(
'Symfony\Component\Security\Tests\Core\Authentication\Voter\ObjectFixture',
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
);
}

Expand Down
33 changes: 33 additions & 0 deletions Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php
@@ -0,0 +1,33 @@
<?php

namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;

use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;

class LegacyAbstractVoterTest_Voter extends AbstractVoter
{
protected function getSupportedClasses()
{
return array('AbstractVoterTest_Object');
}

protected function getSupportedAttributes()
{
return array('EDIT', 'CREATE');
}

protected function isGranted($attribute, $object, $user = null)
{
return 'EDIT' === $attribute;
}
}

class LegacyAbstractVoterTest extends AbstractVoterTest
{
protected function setUp()
{
parent::setUp();

$this->voter = new LegacyAbstractVoterTest_Voter();
}
}

0 comments on commit 18a3795

Please sign in to comment.