Skip to content

Commit a718b28

Browse files
wouterjfabpot
authored andcommitted
[Security] Deprecate isGranted()/decide() on more than one attribute
1 parent 62f60fc commit a718b28

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Authorization/AccessDecisionManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function __construct(iterable $voters = [], string $strategy = self::STRA
5757
*/
5858
public function decide(TokenInterface $token, array $attributes, $object = null)
5959
{
60+
if (\count($attributes) > 1) {
61+
@trigger_error('Passing more than one Security attribute to '.__METHOD__.' is deprecated since Symfony 4.4. Use multiple decide() calls or the expression language (e.g. "has_role(...) or has_role(...)") instead.', \E_USER_DEPRECATED);
62+
}
63+
6064
return $this->{$this->strategy}($token, $attributes, $object);
6165
}
6266

Authorization/AuthorizationChecker.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ final public function isGranted($attributes, $subject = null): bool
5555

5656
if (!\is_array($attributes)) {
5757
$attributes = [$attributes];
58+
} else {
59+
@trigger_error('Passing an array of Security attributes to '.__METHOD__.' is deprecated since Symfony 4.4. Use multiple isGranted() calls or the expression language (e.g. "has_role(...) or has_role(...)") instead.', \E_USER_DEPRECATED);
5860
}
5961

6062
return $this->accessDecisionManager->decide($token, $attributes, $subject);

Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions,
3737
/**
3838
* @dataProvider getStrategiesWith2RolesTests
3939
*/
40-
public function testStrategiesWith2Roles($token, $strategy, $voter, $expected)
40+
public function testLegacyStrategiesWith2Roles($token, $strategy, $voter, $expected)
4141
{
4242
$manager = new AccessDecisionManager([$voter], $strategy);
4343

0 commit comments

Comments
 (0)