16
16
use Psr \Log \LoggerInterface ;
17
17
use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
18
18
use Symfony \Component \HttpFoundation \Response ;
19
+ use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolver ;
20
+ use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
19
21
use Symfony \Component \Security \Http \Authentication \SimplePreAuthenticatorInterface ;
20
22
use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
23
+ use Symfony \Component \Security \Core \Authentication \Token \RememberMeToken ;
21
24
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
22
25
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
23
26
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
@@ -42,8 +45,9 @@ class SimplePreAuthenticationListener implements ListenerInterface
42
45
private $ logger ;
43
46
private $ dispatcher ;
44
47
private $ sessionStrategy ;
48
+ private $ trustResolver ;
45
49
46
- public function __construct (TokenStorageInterface $ tokenStorage , AuthenticationManagerInterface $ authenticationManager , string $ providerKey , SimplePreAuthenticatorInterface $ simpleAuthenticator , LoggerInterface $ logger = null , EventDispatcherInterface $ dispatcher = null )
50
+ public function __construct (TokenStorageInterface $ tokenStorage , AuthenticationManagerInterface $ authenticationManager , string $ providerKey , SimplePreAuthenticatorInterface $ simpleAuthenticator , LoggerInterface $ logger = null , EventDispatcherInterface $ dispatcher = null , AuthenticationTrustResolverInterface $ trustResolver = null )
47
51
{
48
52
if (empty ($ providerKey )) {
49
53
throw new \InvalidArgumentException ('$providerKey must not be empty. ' );
@@ -55,6 +59,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
55
59
$ this ->simpleAuthenticator = $ simpleAuthenticator ;
56
60
$ this ->logger = $ logger ;
57
61
$ this ->dispatcher = $ dispatcher ;
62
+ $ this ->trustResolver = $ trustResolver ?: new AuthenticationTrustResolver (AnonymousToken::class, RememberMeToken::class);
58
63
}
59
64
60
65
/**
@@ -78,7 +83,7 @@ public function handle(GetResponseEvent $event)
78
83
$ this ->logger ->info ('Attempting SimplePreAuthentication. ' , array ('key ' => $ this ->providerKey , 'authenticator ' => get_class ($ this ->simpleAuthenticator )));
79
84
}
80
85
81
- if (null !== $ this ->tokenStorage ->getToken () && !$ this ->tokenStorage -> getToken () instanceof AnonymousToken ) {
86
+ if (( null !== $ token = $ this ->tokenStorage ->getToken ()) && !$ this ->trustResolver -> isAnonymous ( $ token ) ) {
82
87
return ;
83
88
}
84
89
0 commit comments