Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like to add that it's safe to assume that $attribute and $object passed the supports method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpdoc fixes should actually be done in 2.8, not here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Koc can you submit a PR for the phpdoc change on 2.8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* It is safe to assume that $attribute and $object's class pass supports method call.
*
* @param string $attribute
* @param object $object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@

class RoleVoterTest extends \PHPUnit_Framework_TestCase
{
public function testSupportsClass()
{
$voter = new RoleVoter();

$this->assertTrue($voter->supportsClass('Foo'));
}

/**
* @dataProvider getVoteTests
*/
Expand Down