Permalink
Browse files

[3.0][Security] Remove deprecated features (follow up of #15899)

  • Loading branch information...
Koc committed Sep 30, 2015
1 parent aa2e7e4 commit 437398d6d03c86552777fdb8ed97c0f9c6cecbd5
View
@@ -725,6 +725,39 @@ UPGRADE FROM 2.x to 3.0
}
```
* The `AbstractVoter::isGranted()` method have been replaced by `AbstractVoter::voteOnAttribute()`.
Before:
```php
class MyVoter extends AbstractVoter
{
protected function isGranted($attribute, $object, $user = null)
{
return 'EDIT' === $attribute && $user === $object->getAuthor();
}
// ...
}
```
After:
```php
class MyVoter extends AbstractVoter
{
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
return 'EDIT' === $attribute && $token->getUser() === $object->getAuthor();
}
// ...
}
```
* The `supportsAttribute()` and `supportsClass()` methods of classes `AuthenticatedVoter`, `ExpressionVoter`
and `RoleVoter` have been removed.
### Translator
* The `Translator::setFallbackLocale()` method has been removed in favor of
@@ -11,7 +11,6 @@
namespace Symfony\Component\Security\Core\Authorization\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
@@ -89,11 +88,8 @@ protected function isClassInstanceOf($actualClass, $expectedClass)
}
/**
* Perform a single access check operation on a given attribute, object and (optionally) user
* It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
* $user can be one of the following:
* a UserInterface object (fully authenticated user)
* a string (anonymously authenticated user).
* Perform a single access check operation on a given attribute, object and token.
* It is safe to assume that $attribute and $object's class pass supports method call.
*
* @param string $attribute
* @param object $object
@@ -41,30 +41,16 @@ public function __construct(AuthenticationTrustResolverInterface $authentication
$this->authenticationTrustResolver = $authenticationTrustResolver;
}
/**
* {@inheritdoc}
*/
public function supportsAttribute($attribute)
{
return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute);
}
/**
* {@inheritdoc}
*/
public function supportsClass($class)
{
return true;
}
/**
* {@inheritdoc}
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
$result = VoterInterface::ACCESS_ABSTAIN;
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute
&& self::IS_AUTHENTICATED_REMEMBERED !== $attribute
&& self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute)) {
continue;
}
@@ -49,22 +49,6 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
$this->expressionLanguage->registerProvider($provider);
}
/**
* {@inheritdoc}
*/
public function supportsAttribute($attribute)
{
return $attribute instanceof Expression;
}
/**
* {@inheritdoc}
*/
public function supportsClass($class)
{
return true;
}
/**
* {@inheritdoc}
*/
@@ -73,7 +57,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
$result = VoterInterface::ACCESS_ABSTAIN;
$variables = null;
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
if (!$attribute instanceof Expression) {
continue;
}
@@ -32,22 +32,6 @@ public function __construct($prefix = 'ROLE_')
$this->prefix = $prefix;
}
/**
* {@inheritdoc}
*/
public function supportsAttribute($attribute)
{
return 0 === strpos($attribute, $this->prefix);
}
/**
* {@inheritdoc}
*/
public function supportsClass($class)
{
return true;
}
/**
* {@inheritdoc}
*/
@@ -57,7 +41,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
$roles = $this->extractRoles($token);
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
if (0 !== strpos($attribute, $this->prefix)) {
continue;
}
@@ -137,24 +137,4 @@ protected function getVoter($vote)
return $voter;
}
protected function getVoterSupportsClass($ret)
{
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
$voter->expects($this->any())
->method('supportsClass')
->will($this->returnValue($ret));
return $voter;
}
protected function getVoterSupportsAttribute($ret)
{
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
$voter->expects($this->any())
->method('supportsAttribute')
->will($this->returnValue($ret));
return $voter;
}
}
@@ -17,12 +17,6 @@
class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase
{
public function testSupportsClass()
{
$voter = new AuthenticatedVoter($this->getResolver());
$this->assertTrue($voter->supportsClass('stdClass'));
}
/**
* @dataProvider getVoteTests
*/
@@ -17,15 +17,6 @@
class ExpressionVoterTest extends \PHPUnit_Framework_TestCase
{
public function testSupportsAttribute()
{
$expression = $this->createExpression();
$expressionLanguage = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage');
$voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy());
$this->assertTrue($voter->supportsAttribute($expression));
}
/**
* @dataProvider getVoteTests
*/
@@ -17,13 +17,6 @@
class RoleVoterTest extends \PHPUnit_Framework_TestCase
{
public function testSupportsClass()
{
$voter = new RoleVoter();
$this->assertTrue($voter->supportsClass('Foo'));
}
/**
* @dataProvider getVoteTests
*/

0 comments on commit 437398d

Please sign in to comment.