10000 [Security] Call logout handlers even if token is null by MatTheCat · Pull Request #24489 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Call logout handlers even if token is null #24489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Core\Authentication\Token;

/**
* DummyToken allows fixing #7104 without introducing any BC break.
*
* @author Mathieu Lechat <math.lechat@gmail.com>
*
* @internal
*/
class DummyToken extends AbstractToken
{
public function __construct()
{
parent::__construct(array());

$this->setUser('dummy');
}

/**
* {@inheritdoc}
*/
public function getCredentials()
{
return null;
}
}
11 changes: 7 additions & 4 deletions src/Symfony/Component/Security/Http/Firewall/LogoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authentication\Token\DummyToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
use Symfony\Component\Security\Core\Exception\LogoutException;
Expand Down Expand Up @@ -109,10 +110,12 @@ public function handle(GetResponseEvent $event)
}

// handle multiple logout attempts gracefully
if ($token = $this->tokenStorage->getToken()) {
foreach ($this->handlers as $handler) {
$handler->logout($request, $response, $token);
}
$token = $this->tokenStorage->getToken();
if (null === $token) {
$token = new DummyToken();
}
foreach ($this->handlers as $handler) {
$handler->logout($request, $response, $token);
}

$this->tokenStorage->setToken(null);
Expand Down
0