This PR was merged into the 3.0-dev branch.
Discussion
----------
[3.0][Security] Remove deprecated features (follow up of #15899)
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #15899
| License | MIT
| Doc PR | -
- updated UPGRADE-3.0.md
- removed unused `supportsClass` methods
- changed visibility of `supportsAttribute` methods from public to private, removed `inheritdoc` annotation from them because there is no definition for this methods in parent interface
- removed tests for `supportsClass` and `supportsAttribute` method
- removed unused mock creation
Commits
-------
437398d
[3.0][Security] Remove deprecated features (follow up of #15899)
This commit is contained in:
commit
7e3c4a6afd
@ -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 @@ abstract class AbstractVoter implements VoterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,22 +41,6 @@ class AuthenticatedVoter implements VoterInterface
|
||||
$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}
|
||||
*/
|
||||
@ -64,7 +48,9 @@ class AuthenticatedVoter implements VoterInterface
|
||||
{
|
||||
$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 @@ class ExpressionVoter implements VoterInterface
|
||||
$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 @@ class ExpressionVoter implements VoterInterface
|
||||
$result = VoterInterface::ACCESS_ABSTAIN;
|
||||
$variables = null;
|
||||
foreach ($attributes as $attribute) {
|
||||
if (!$this->supportsAttribute($attribute)) {
|
||||
if (!$attribute instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -32,22 +32,6 @@ class RoleVoter implements VoterInterface
|
||||
$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 @@ class RoleVoter implements VoterInterface
|
||||
$roles = $this->extractRoles($token);
|
||||
|
||||
foreach ($attributes as $attribute) {
|
||||
if (!$this->supportsAttribute($attribute)) {
|
||||
if (0 !== strpos($attribute, $this->prefix)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -137,24 +137,4 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
||||
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 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
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 @@ use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
class RoleVoterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupportsClass()
|
||||
{
|
||||
$voter = new RoleVoter();
|
||||
|
||||
$this->assertTrue($voter->supportsClass('Foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getVoteTests
|
||||
*/
|
||||
|
Reference in New Issue
Block a user