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

Skip to content

Commit 5a5b2bd

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

File tree

9 files changed

+46
-96
lines changed

9 files changed

+46
-96
lines changed

UPGRADE-3.0.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,36 @@ 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+
728758
### Translator
729759

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

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

Lines changed: 1 addition & 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,7 @@ 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.
9792
*
9893
* @param string $attribute
9994
* @param object $object

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ 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
*/
@@ -91,4 +75,9 @@ public function vote(TokenInterface $token, $object, array $attributes)
9175

9276
return $result;
9377
}
78+
79+
private function supportsAttribute($attribute)
80+
{
81+
return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute);
82+
}
9483
}

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

Lines changed: 5 additions & 16 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
*/
@@ -115,4 +99,9 @@ private function getVariables(TokenInterface $token, $object)
11599

116100
return $variables;
117101
}
102+
103+
private function supportsAttribute($attribute)
104+
{
105+
return $attribute instanceof Expression;
106+
}
118107
}

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

Lines changed: 5 additions & 16 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
*/
@@ -76,4 +60,9 @@ protected function extractRoles(TokenInterface $token)
7660
{
7761
return $token->getRoles();
7862
}
63+
64+
private function supportsAttribute($attribute)
65+
{
66+
return 0 === strpos($attribute, $this->prefix);
67+
}
7968
}

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