-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Deprecate "AbstractVoter" in favor of "Voter" #16601
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Authorization\Voter; | ||
|
||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
|
||
/** | ||
* Voter is an abstract default implementation of a voter. | ||
* | ||
* @author Roman Marintšenko <inoryy@gmail.com> | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
abstract class Voter implements VoterInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsAttribute($attribute) | ||
{ | ||
throw new \BadMethodCallException('supportsAttribute method is deprecated since version 2.8, to be removed in 3.0'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, to implements the interface :/ |
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsClass($class) | ||
{ | ||
throw new \BadMethodCallException('supportsClass method is deprecated since version 2.8, to be removed in 3.0'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function vote(TokenInterface $token, $object, array $attributes) | ||
{ | ||
// abstain vote by default in case none of the attributes are supported | ||
$vote = self::ACCESS_ABSTAIN; | ||
|
||
foreach ($attributes as $attribute) { | ||
if (!$this->supports($attribute, $object)) { | ||
continue; | ||
} | ||
|
||
// as soon as at least one attribute is supported, default is to deny access | ||
$vote = self::ACCESS_DENIED; | ||
|
||
if ($this->voteOnAttribute($attribute, $object, $token)) { | ||
// grant access as soon as at least one attribute returns a positive response | ||
return self::ACCESS_GRANTED; | ||
} | ||
} | ||
|
||
return $vote; | ||
} | ||
|
||
/** | ||
* Determines if the attribute and subject are supported by this voter. | ||
* | ||
* @param string $attribute An attribute | ||
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type | ||
* | ||
* @return bool True if the attribute and subject are supported, false otherwise | ||
*/ | ||
abstract protected function supports($attribute, $subject); | ||
|
||
/** | ||
* Perform a single access check operation on a given attribute, subject and token. | ||
* | ||
* @param string $attribute | ||
* @param mixed $subject | ||
* @param TokenInterface $token | ||
* | ||
* @return bool | ||
*/ | ||
abstract protected function voteOnAttribute($attribute, $subject, TokenInterface $token); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're deprecating
AbstractVoter
entirely, then we don't need to talk about it at all, right? The upgrade path would be to switch toVoter
and make the changes needed there, correct? If so, I think we should have one simple, before and after (beforeAbstractVoter
after withVoter
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people were using AbstractVoter in 2.7, they can read how to upgrade to 2.8;
Then they could upgrade with the new Voter. Like that it's done step by step.
But I can merge all steps together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, we should maybe just revert the changes made on AbstractVoter for 2.8 entirely, but keep the deprecations. Ie remove the
supports
method & co. Don't you think ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a real BC break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How that? SF 2.8 is not released, how can it be à BC break to revert the changes made on 2.8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the implementation sticks on the implementation of the 2.7 version.