Skip to content

Commit

Permalink
Merge pull request #9 from gmorel/feature/9
Browse files Browse the repository at this point in the history
sf2 compliance: replace deprecated SecurityContextInterface
  • Loading branch information
tyx committed Mar 30, 2015
2 parents 990828f + ec624a0 commit 4108cf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<service id="rezzza.security.request_signature.provider" class="%rezzza.security.request_signature.provider.class%" public="false" />

<service id="rezzza.security.request_signature.listener" class="%rezzza.security.request_signature.listener.class%" public="false">
<argument type="service" id="security.context"/>
<argument type="service" id="security.token_storage"/>
<argument type="service" id="security.authentication.manager" />
<argument /> <!-- injected via RequestSignatureFactory -->
<argument /> <!-- injected via RequestSignatureFactory -->
Expand Down
17 changes: 8 additions & 9 deletions Security/Firewall/RequestSignatureListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Rezzza\SecurityBundle\Security\RequestSignatureToken;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Psr\Log\LoggerInterface;

/**
* RequestSignatureListener
Expand All @@ -21,21 +20,21 @@
*/
class RequestSignatureListener implements ListenerInterface
{
protected $securityContext;
protected $tokenStorage;
protected $authenticationManager;
protected $signatureQueryParameters;
protected $ignored;
protected $logger;

public function __construct(
SecurityContextInterface $securityContext,
TokenStorageInterface $tokenStorage,
AuthenticationManagerInterface $authenticationManager,
SignatureQueryParameters $signatureQueryParameters,
$ignored,
LoggerInterface $logger = null
)
{
$this->securityContext = $securityContext;
$this->tokenStorage = $tokenStorage;
$this->authenticationManager = $authenticationManager;
$this->signatureQueryParameters = $signatureQueryParameters;
$this->ignored = $ignored;
Expand All @@ -45,11 +44,11 @@ public function __construct(
public function handle(GetResponseEvent $event)
{
if (true === $this->ignored) {
if (null !== $this->securityContext->getToken()) {
if (null !== $this->tokenStorage->getToken()) {
return;
}

$this->securityContext->setToken(new AnonymousToken('request_signature', 'anon.', array()));
$this->tokenStorage->setToken(new AnonymousToken('request_signature', 'anon.', array()));

return;
}
Expand All @@ -64,7 +63,7 @@ public function handle(GetResponseEvent $event)
$authToken->requestContent = rawurldecode($request->getContent());

try {
return $this->securityContext->setToken(
return $this->tokenStorage->setToken(
$this->authenticationManager->authenticate($authToken)
);
} catch (AuthenticationException $e) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
}],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": "2.*",
"symfony/security-bundle" : "~2.0",
"symfony/framework-bundle": "~2.6",
"symfony/security-bundle" : "~2.6",
"doctrine/common": "~2.2"
},
"require-dev": {
Expand Down

0 comments on commit 4108cf9

Please sign in to comment.