8000 [3.0][Security] Remove deprecated features (follow up of #15899) · symfony/symfony@e2d859c · GitHub
[go: up one dir, main page]

Skip to content

Commit e2d859c

Browse files
committed
[3.0][Security] Remove deprecated features (follow up of #15899)
1 parent aa2e7e4 commit e2d859c

File tree

9 files changed

+40
-99
lines changed

9 files changed

+40
-99
lines changed

UPGRADE-3.0.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,39 @@ UPGRADE FROM 2.x to 3.0
725725
}
726726
```
727727

728+
* The `AbstractVoter::isGranted()` method have been replaced by `AbstractVoter::voteOnAttribute()`.
729+
730+
Before:
731+
732+
```php
733+
class MyVoter extends AbstractVoter
734+
{
735+
protected function isGranted($attribute, $object, $user = null)
736+
{
737+
return 'EDIT' === $attribute && $user === $object->getAuthor();
738+
}
739+
740+
// ...
741+
}
742+
```
743+
744+
After:
745+
746+
```php
747+
class MyVoter extends AbstractVoter
748+
{
749+
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
750+
{
751+
return 'EDIT' === $attribute && $token->getUser() === $object->getAuthor();
752+
}
753+
754+
// ...
755+
}
756+
```
757+
758+
* The `supportsAttribute()` and `supportsClass()` methods of classes `AuthenticatedVoter`, `ExpressionVoter`
759+
and `RoleVoter` have been removed.
760+
728761
### Translator
729762

730763
* The `Translator::setFallbackLocale()` method has been removed in favor of

src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Core\Authorization\Voter;
1313

14-
use Symfony\Component\Security\Core\User\UserInterface;
1514
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1615

1716
/**
@@ -89,11 +88,8 @@ protected function isClassInstanceOf($actualClass, $expectedClass)
8988
}
9089

9190
/**
92-
* Perform a single access check operation on a given attribute, object and (optionally) user
93-
* It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
94-
* $user can be one of the following:
95-
* a UserInterface object (fully authenticated user)
96-
* a string (anonymously authenticated user).
91+
* Perform a single access check operation on a given attribute, object and token.
92+
* It is safe to assume that $attribute and $object's class pass supports method call.
9793
*
9894
* @param string $attribute
9995
* @param object $object

src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,16 @@ public function __construct(AuthenticationTrustResolverInterface $authentication
4141
$this->authenticationTrustResolver = $authenticationTrustResolver;
4242
}
4343

44-
/**
45-
* {@inheritdoc}
46-
*/
47-
public function supportsAttribute($attribute)
48-
{
49-
return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute);
50-
}
51-
52-
/**
53-
* {@inheritdoc}
54-
*/
55-
public function supportsClass($class)
56-
{
57-
return true;
58-
}
59-
6044
/**
6145
* {@inheritdoc}
6246
*/
6347
public function vote(TokenInterface $token, $object, array $attributes)
6448
{
6549
$result = VoterInterface::ACCESS_ABSTAIN;
6650
foreach ($attributes as $attribute) {
67-
if (!$this->supportsAttribute($attribute)) {
51+
if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute
52+
|| self::IS_AUTHENTICATED_REMEMBERED !== $attribute
53+
|| self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute)) {
6854
continue;
6955
}
7056

src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,6 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
4949
$this->expressionLanguage->registerProvider($provider);
5050
}
5151

52-
/**
53-
* {@inheritdoc}
54-
*/
55-
public function supportsAttribute($attribute)
56-
{
57-
return $attribute instanceof Expression;
58-
}
59-
60-
/**
61-
* {@inheritdoc}
62-
*/
63-
public function supportsClass($class)
64-
{
65-
return true;
66-
}
67-
6852
/**
6953
* {@inheritdoc}
7054
*/
@@ -73,7 +57,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
7357
$result = VoterInterface::ACCESS_ABSTAIN;
7458
$variables = null;
7559
foreach ($attributes as $attribute) {
76-
if (!$this->supportsAttribute($attribute)) {
60+
if (!$attribute instanceof Expression) {
7761
continue;
7862
}
7963

src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ public function __construct($prefix = 'ROLE_')
3232
$this->prefix = $prefix;
3333
}
3434

35-
/**
36-
* {@inheritdoc}
37-
*/
38-
public function supportsAttribute($attribute)
39-
{
40-
return 0 === strpos($attribute, $this->prefix);
41-
}
42-
43-
/**
44-
* {@inheritdoc}
45-
*/
46-
public function supportsClass($class)
47-
{
48-
return true;
49-
}
50-
5135
/**
5236
* {@inheritdoc}
5337
*/
@@ -57,7 +41,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
5741
$roles = $this->extractRoles($token);
5842

5943
foreach ($attributes as $attribute) {
60-
if (!$this->supportsAttribute($attribute)) {
44+
if (0 !== strpos($attribute, $this->prefix)) {
6145
continue;
6246
}
6347

src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,4 @@ protected function getVoter($vote)
137137

138138
return $voter;
139139
}
140-
141-
protected function getVoterSupportsClass($ret)
142-
{
143-
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
144-
$voter->expects($this->any())
145-
->method('supportsClass')
146-
->will($this->returnValue($ret));
147-
148-
return $voter;
149-
}
150-
151-
protected function getVoterSupportsAttribute($ret)
152-
{
153-
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
154-
$voter->expects($this->any())
155-
->method('supportsAttribute')
156-
->will($this->returnValue($ret));
157-
158-
return $voter;
159-
}
160140
}

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717

1818
class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase
1919
{
20-
public function testSupportsClass()
21-
{
22-
$voter = new AuthenticatedVoter($this->getResolver());
23-
$this->assertTrue($voter->supportsClass('stdClass'));
24-
}
25-
2620
/**
2721
* @dataProvider getVoteTests
2822
*/

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ExpressionVoterTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717

1818
class ExpressionVoterTest extends \PHPUnit_Framework_TestCase
1919
{
20-
public function testSupportsAttribute()
21-
{
22-
$expression = $this->createExpression();
23-
$expressionLanguage = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage');
24-
$voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy());
25-
26-
$this->assertTrue($voter->supportsAttribute($expression));
27-
}
28-
2920
/**
3021
* @dataProvider getVoteTests
3122
*/

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717

1818
class RoleVoterTest extends \PHPUnit_Framework_TestCase
1919
{
20-
public function testSupportsClass()
21-
{
22-
$voter = new RoleVoter();
23-
24-
$this->assertTrue($voter->supportsClass('Foo'));
25-
}
26-
2720
/**
2821
* @dataProvider getVoteTests
2922
*/

0 commit comments

Comments
 (0)
0