1212namespace Symfony \Component \Security \Core \Authorization \Voter ;
1313
1414use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
15+ use Symfony \Component \Security \Core \Authentication \Token \SwitchUserToken ;
1516use 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 ;
0 commit comments