8000 Added IS_ANONYMOUS, IS_REMEMBERED, IS_IMPERSONATOR · symfony/symfony@aa8289d · GitHub
[go: up one dir, main page]

Skip to content

Commit aa8289d

Browse files
HeahDudewouterj
authored andcommitted
Added IS_ANONYMOUS, IS_REMEMBERED, IS_IMPERSONATOR
1 parent 9908317 commit aa8289d

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Added access decision strategy to override access decisions by voter service priority
8+
* Added `IS_ANONYMOUS`, `IS_REMEMBERED`, `IS_IMPERSONATOR`
89

910
5.0.0
1011
-----

src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
1515
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
16+
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
1617
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1718

1819
/**

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Authorization\Voter;
1313

1414
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
15+
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
1516
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1617

1718
/**
@@ -28,6 +29,9 @@ class AuthenticatedVoter implements VoterInterface
2829
const IS_AUTHENTICATED_FULLY = 'IS_AUTHENTICATED_FULLY';
2930
const IS_AUTHENTICATED_REMEMBERED = 'IS_AUTHENTICATED_REMEMBERED';
3031
const IS_AUTHENTICATED_ANONYMOUSLY = 'IS_AUTHENTICATED_ANONYMOUSLY';
32+
const IS_ANONYMOUS = 'IS_ANONYMOUS';
33+
const IS_IMPERSONATOR = 'IS_IMPERSONATOR';
34+
const IS_REMEMBERED = 'IS_REMEMBERED';
3135

3236
private $authenticationTrustResolver;
3337

@@ -45,7 +49,10 @@ public function vote(TokenInterface $token, $subject, array $attributes)
4549
foreach ($attributes as $attribute) {
4650
if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute
4751
&& self::IS_AUTHENTICATED_REMEMBERED !== $attribute
48-
&& self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute)) {
52+
&& self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute
53+
&& self::IS_ANONYMOUS !== $attribute
54+
&& self::IS_IMPERSONATOR !== $attribute
55+
&& self::IS_REMEMBERED !== $attribute)) {
4956
continue;
5057
}
5158

@@ -68,6 +75,18 @@ public function vote(TokenInterface $token, $subject, array $attributes)
6875
|| $this->authenticationTrustResolver->isFullFledged($token))) {
6976
return VoterInterface::ACCESS_GRANTED;
7077
}
78+
79+
if (self::IS_REMEMBERED === $attribute && $this->authenticationTrustResolver->isRememberMe($token)) {
80+
return VoterInterface::ACCESS_GRANTED;
81+
}
82+
83+
if (self::IS_ANONYMOUS === $attribute && $this->authenticationTrustResolver->isAnonymous($token)) {
84+
return VoterInterface::ACCESS_GRANTED;
85+
}
86+
87+
if (self::IS_IMPERSONATOR === $attribute && $token instanceof SwitchUserToken) {
88+
return VoterInterface::ACCESS_GRANTED;
89+
}
7190
}
7291

7392
return $result;

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ public function getVoteTests()
4646
['remembered', ['IS_AUTHENTICATED_REMEMBERED'], VoterInterface::ACCESS_GRANTED],
4747
['anonymously', ['IS_AUTHENTICATED_REMEMBERED'], VoterInterface::ACCESS_DENIED],
4848

49+
['fully', ['IS_REMEMBERED'], VoterInterface::ACCESS_DENIED],
50+
['remembered', ['IS_REMEMBERED'], VoterInterface::ACCESS_GRANTED],
51+
['anonymously', ['IS_REMEMBERED'], VoterInterface::ACCESS_DENIED],
52+
4953
['fully', ['IS_AUTHENTICATED_FULLY'], VoterInterface::ACCESS_GRANTED],
5054
['remembered', ['IS_AUTHENTICATED_FULLY'], VoterInterface::ACCESS_DENIED],
5155
['anonymously', ['IS_AUTHENTICATED_FULLY'], VoterInterface::ACCESS_DENIED],
56+
57+
['fully', ['IS_ANONYMOUS'], VoterInterface::ACCESS_DENIED],
58+
['remembered', ['IS_ANONYMOUS'], VoterInterface::ACCESS_DENIED],
59+
['anonymously', ['IS_ANONYMOUS'], VoterInterface::ACCESS_GRANTED],
5260
];
5361
}
5462

0 commit comments

Comments
 (0)
0