-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Security] Trigger a deprecation when a voter is missing the VoterInterface #22629
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 4 commits
0df7c95
c8b5f80
4a13ef5
ab0ab44
b187304
40ac4ec
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,8 @@ | ||
UPGRADE FROM 3.3 to 3.4 | ||
======================= | ||
|
||
Security | ||
-------- | ||
|
||
* Using voters that do not implement the `VoterInterface`is now deprecated in | ||
the `AccessDecisionManager` and this functionality will be removed in 4.0. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ private function decideAffirmative(TokenInterface $token, array $attributes, $ob | |
{ | ||
$deny = 0; | ||
foreach ($this->voters as $voter) { | ||
$result = $voter->vote($token, $object, $attributes); | ||
$result = $this->vote($voter, $token, $object, $attributes); | ||
switch ($result) { | ||
case VoterInterface::ACCESS_GRANTED: | ||
return true; | ||
|
@@ -125,7 +125,7 @@ private function decideConsensus(TokenInterface $token, array $attributes, $obje | |
$grant = 0; | ||
$deny = 0; | ||
foreach ($this->voters as $voter) { | ||
$result = $voter->vote($token, $object, $attributes); | ||
$result = $this->vote($voter, $token, $object, $attributes); | ||
|
||
switch ($result) { | ||
case VoterInterface::ACCESS_GRANTED: | ||
|
@@ -166,7 +166,7 @@ private function decideUnanimous(TokenInterface $token, array $attributes, $obje | |
$grant = 0; | ||
foreach ($this->voters as $voter) { | ||
foreach ($attributes as $attribute) { | ||
$result = $voter->vote($token, $object, array($attribute)); | ||
$result = $this->vote($voter, $token, $object, array($attribute)); | ||
|
||
switch ($result) { | ||
case VoterInterface::ACCESS_GRANTED: | ||
|
@@ -190,4 +190,25 @@ private function decideUnanimous(TokenInterface $token, array $attributes, $obje | |
|
||
return $this->allowIfAllAbstainDecisions; | ||
} | ||
|
||
/** | ||
* TokenInterface vote proxy method. | ||
* | ||
* Acts as a BC layer when the VoterInterface is not implemented on the voter. | ||
*/ | ||
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. I would add a note to remove this method in 4.0 (to avoid forgetting about it). 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. I could make the method itself deprecated with a full-fledged warning, even though it's private. Would make it easier to detect. |
||
private function vote($voter, TokenInterface $token, $subject, $attributes) | ||
{ | ||
if ($voter instanceof VoterInterface) { | ||
return $voter->vote($token, $subject, $attributes); | ||
} | ||
|
||
if (method_exists($voter, 'vote')) { | ||
@trigger_error(sprintf('Calling vote() on an voter without %1$s is deprecated as of 3.4 and will be removed in 4.0. Implement the %1$s on your voter.', VoterInterface::class), E_USER_DEPRECATED); | ||
|
||
// making the assumption that the signature matches | ||
return $voter->vote($token, $subject, $attributes); | ||
} | ||
|
||
throw new \BadMethodCallException(sprintf('%s should implement the %s interface when used as voter.', get_class($voter), VoterInterface::class)); | ||
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. I would still qualify it a 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. I would like to have it because it's a component that can be used without the DIC 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. It's still a safeguard :) sure it adds some DX value, but nowhere near the value added by the pass (validation at compile time). Practically for the component this is just creating cosmetic errors, which we dont do elsewhere really. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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\Tests\Authorization\Stub; | ||
|
||
/** | ||
* @author Iltar van der Berg <kjarli@gmail.com> | ||
*/ | ||
class VoterWithoutInterface | ||
{ | ||
public function vote() | ||
{ | ||
} | ||
} |
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.
What about using the annotations?