14
14
use Symfony \Component \Security \Acl \Model \SecurityIdentityRetrievalStrategyInterface ;
15
15
use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
16
16
use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
17
+ use Symfony \Component \Security \Core \Authentication \Token \NullToken ;
17
18
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
18
19
use Symfony \Component \Security \Core \Authorization \Voter \AuthenticatedVoter ;
19
20
use Symfony \Component \Security \Core \Role \RoleHierarchyInterface ;
@@ -42,24 +43,22 @@ public function __construct(RoleHierarchyInterface $roleHierarchy, Authenticatio
42
43
*
43
44
* @return RoleSecurityIdentity[]
44
45
*/
45
- public function getSecurityIdentities (? TokenInterface $ token )
46
+ public function getSecurityIdentities (TokenInterface $ token )
46
47
{
47
48
$ sids = [];
48
49
49
50
// add user security identity
50
- if (!$ token instanceof AnonymousToken && null !== $ token ) {
51
+ if (!$ token instanceof AnonymousToken && ! $ token instanceof NullToken ) {
51
52
try {
52
53
$ sids [] = UserSecurityIdentity::fromToken ($ token );
53
54
} catch (\InvalidArgumentException $ e ) {
54
55
// ignore, user has no user security identity
55
56
}
56
57
}
57
58
58
- if (null !== $ token ) {
59
- // add all reachable roles
60
- foreach ($ this ->roleHierarchy ->getReachableRoleNames ($ token ->getRoleNames ()) as $ role ) {
61
- $ sids [] = new RoleSecurityIdentity ($ role );
62
- }
59
+ // add all reachable roles
60
+ foreach ($ this ->roleHierarchy ->getReachableRoleNames ($ token ->getRoleNames ()) as $ role ) {
61
+ $ sids [] = new RoleSecurityIdentity ($ role );
63
62
}
64
63
65
64
// add built-in special roles
@@ -77,7 +76,7 @@ public function getSecurityIdentities(?TokenInterface $token)
77
76
return $ sids ;
78
77
}
79
78
80
- private function isNotAuthenticated (? TokenInterface $ token ): bool
79
+ private function isNotAuthenticated (TokenInterface $ token ): bool
81
80
{
82
81
if (\defined ('\Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter::PUBLIC_ACCESS ' )) {
83
82
return !$ this ->authenticationTrustResolver ->isAuthenticated ($ token );
0 commit comments