12
12
namespace Symfony \Component \Security \Core \Authorization \Voter ;
13
13
14
14
use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
15
+ use Symfony \Component \Security \Core \Authentication \Token \SwitchUserToken ;
15
16
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
16
17
17
18
/**
@@ -28,6 +29,9 @@ class AuthenticatedVoter implements VoterInterface
28
29
const IS_AUTHENTICATED_FULLY = 'IS_AUTHENTICATED_FULLY ' ;
29
30
const IS_AUTHENTICATED_REMEMBERED = 'IS_AUTHENTICATED_REMEMBERED ' ;
30
31
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 ' ;
31
35
32
36
private $ authenticationTrustResolver ;
33
37
@@ -45,7 +49,10 @@ public function vote(TokenInterface $token, $subject, array $attributes)
45
49
foreach ($ attributes as $ attribute ) {
46
50
if (null === $ attribute || (self ::IS_AUTHENTICATED_FULLY !== $ attribute
47
51
&& 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 )) {
49
56
continue ;
50
57
}
51
58
@@ -68,6 +75,18 @@ public function vote(TokenInterface $token, $subject, array $attributes)
68
75
|| $ this ->authenticationTrustResolver ->isFullFledged ($ token ))) {
69
76
return VoterInterface::ACCESS_GRANTED ;
70
77
}
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
+ }
71
90
}
72
91
73
92
return $ result ;
0 commit comments