Skip to content

Commit 2820a9f

Browse files
committed
Use TokenStorageInterface intead of deprecated SecurityContext
1 parent df40031 commit 2820a9f

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Uecode/Bundle/ApiKeyBundle/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
arguments: [""]
1616
uecode.api_key.listener.api_key:
1717
class: %uecode.api_key.listener.api_key.class%
18-
arguments: ["@security.context", "@security.authentication.manager", "@uecode.api_key.extractor"]
18+
arguments: ["@security.token_storage", "@security.authentication.manager", "@uecode.api_key.extractor"]
1919

2020
uecode.api_key.extractor.query:
2121
class: %uecode.api_key.extractor.query.class%

src/Uecode/Bundle/ApiKeyBundle/Security/Firewall/ApiKeyListener.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
77
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
88
use Symfony\Component\Security\Core\Exception\AuthenticationException;
9-
use Symfony\Component\Security\Core\SecurityContextInterface;
9+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1010
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
1111
use Uecode\Bundle\ApiKeyBundle\Security\Authentication\Token\ApiKeyUserToken;
1212
use Uecode\Bundle\ApiKeyBundle\Extractor\KeyExtractor;
@@ -17,9 +17,9 @@
1717
class ApiKeyListener implements ListenerInterface
1818
{
1919
/**
20-
* @var SecurityContextInterface
20+
* @var TokenStorageInterface
2121
*/
22-
protected $securityContext;
22+
protected $tokenStorage;
2323

2424
/**
2525
* @var AuthenticationManagerInterface
@@ -31,9 +31,9 @@ class ApiKeyListener implements ListenerInterface
3131
*/
3232
protected $keyExtractor;
3333

34-
public function __construct(SecurityContextInterface $context, AuthenticationManagerInterface $manager, KeyExtractor $keyExtractor)
34+
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $manager, KeyExtractor $keyExtractor)
3535
{
36-
$this->securityContext = $context;
36+
$this->tokenStorage = $tokenStorage;
3737
$this->authenticationManager = $manager;
3838
$this->keyExtractor = $keyExtractor;
3939
}
@@ -61,13 +61,13 @@ public function handle(GetResponseEvent $event)
6161

6262
try {
6363
$authToken = $this->authenticationManager->authenticate($token);
64-
$this->securityContext->setToken($authToken);
64+
$this->tokenStorage->setToken($authToken);
6565

6666
return;
6767
} catch (AuthenticationException $failed) {
68-
$token = $this->securityContext->getToken();
68+
$token = $this->tokenStorage->getToken();
6969
if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) {
70-
$this->securityContext->setToken(null);
70+
$this->tokenStorage->setToken(null);
7171
}
7272

7373
$message = $failed->getMessage();

0 commit comments

Comments
 (0)