|
6 | 6 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
7 | 7 | use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; |
8 | 8 | use Symfony\Component\Security\Core\Exception\AuthenticationException; |
9 | | -use Symfony\Component\Security\Core\SecurityContextInterface; |
| 9 | +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
10 | 10 | use Symfony\Component\Security\Http\Firewall\ListenerInterface; |
11 | 11 | use Uecode\Bundle\ApiKeyBundle\Security\Authentication\Token\ApiKeyUserToken; |
12 | 12 | use Uecode\Bundle\ApiKeyBundle\Extractor\KeyExtractor; |
|
17 | 17 | class ApiKeyListener implements ListenerInterface |
18 | 18 | { |
19 | 19 | /** |
20 | | - * @var SecurityContextInterface |
| 20 | + * @var TokenStorageInterface |
21 | 21 | */ |
22 | | - protected $securityContext; |
| 22 | + private $tokenStorage; |
23 | 23 |
|
24 | 24 | /** |
25 | 25 | * @var AuthenticationManagerInterface |
26 | 26 | */ |
27 | | - protected $authenticationManager; |
| 27 | + private $authenticationManager; |
28 | 28 |
|
29 | 29 | /** |
30 | 30 | * @var KeyExtractor |
31 | 31 | */ |
32 | | - protected $keyExtractor; |
| 32 | + private $keyExtractor; |
33 | 33 |
|
34 | | - public function __construct(SecurityContextInterface $context, AuthenticationManagerInterface $manager, KeyExtractor $keyExtractor) |
| 34 | + public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $manager, KeyExtractor $keyExtractor) |
35 | 35 | { |
36 | | - $this->securityContext = $context; |
| 36 | + $this->tokenStorage = $tokenStorage; |
37 | 37 | $this->authenticationManager = $manager; |
38 | 38 | $this->keyExtractor = $keyExtractor; |
39 | 39 | } |
@@ -61,13 +61,13 @@ public function handle(GetResponseEvent $event) |
61 | 61 |
|
62 | 62 | try { |
63 | 63 | $authToken = $this->authenticationManager->authenticate($token); |
64 | | - $this->securityContext->setToken($authToken); |
| 64 | + $this->tokenStorage->setToken($authToken); |
65 | 65 |
|
66 | 66 | return; |
67 | 67 | } catch (AuthenticationException $failed) { |
68 | | - $token = $this->securityContext->getToken(); |
| 68 | + $token = $this->tokenStorage->getToken(); |
69 | 69 | if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) { |
70 | | - $this->securityContext->setToken(null); |
| 70 | + $this->tokenStorage->setToken(null); |
71 | 71 | } |
72 | 72 |
|
73 | 73 | $message = $failed->getMessage(); |
|
0 commit comments