Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security] Refactor logout listener to dispatch an event instead
- Loading branch information
Showing
26 changed files
with
590 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Symfony/Bundle/SecurityBundle/EventListener/FirewallEventBubblingListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?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\Bundle\SecurityBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Security\Http\Event\LogoutEvent; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* A listener that dispatches all security events from the firewall-specific | ||
* dispatcher on the global event dispatcher. | ||
* | ||
* @author Wouter de Jong <wouter@wouterj.nl> | ||
*/ | ||
class FirewallEventBubblingListener implements EventSubscriberInterface | ||
{ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
LogoutEvent::class => 'bubbleEvent', | ||
]; | ||
} | ||
|
||
public function bubbleEvent($event): void | ||
{ | ||
$this->eventDispatcher->dispatch($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Symfony/Bundle/SecurityBundle/Security/LegacyLogoutHandlerListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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\Bundle\SecurityBundle\Security; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Security\Http\Event\LogoutEvent; | ||
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; | ||
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface; | ||
|
||
/** | ||
* @author Wouter de Jong <wouter@wouterj.nl> | ||
* | ||
* @internal | ||
*/ | ||
class LegacyLogoutHandlerListener implements EventSubscriberInterface | ||
{ | ||
private $logoutHandler; | ||
|
||
public function __construct(object $logoutHandler) | ||
{ | ||
if (!$logoutHandler instanceof LogoutSuccessHandlerInterface && !$logoutHandler instanceof LogoutHandlerInterface) { | ||
throw new \InvalidArgumentException(sprintf('An instance of "%s" or "%s" must be passed to "%s", "%s" given.', LogoutHandlerInterface::class, LogoutSuccessHandlerInterface::class, __METHOD__, get_debug_type($logoutHandler))); | ||
} | ||
|
||
$this->logoutHandler = $logoutHandler; | ||
} | ||
|
||
public function onLogout(LogoutEvent $event): void | ||
{ | ||
if ($this->logoutHandler instanceof LogoutSuccessHandlerInterface) { | ||
$event->setResponse($this->logoutHandler->onLogoutSuccess($event->getRequest())); | ||
} elseif ($this->logoutHandler instanceof LogoutHandlerInterface) { | ||
$this->logoutHandler->logout($event->getRequest(), $event->getResponse(), $event->getToken()); | ||
} | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
LogoutEvent::class => 'onLogout', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.