Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use event dispatcher in the Logout firewall listener
This provides several advantages: * An official system to hook into the logout listener (instead of the current handlers) * A unified hook (instead of success handler + handlers) * A small clean-up of the RememberMeServices
- Loading branch information
Showing
24 changed files
with
565 additions
and
98 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
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,53 @@ | ||
<?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\Http\Event; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* @author Wouter de Jong <wouter@wouterj.nl> | ||
*/ | ||
class LogoutEvent extends Event | ||
{ | ||
private $request; | ||
private $response; | ||
private $token; | ||
|
||
public function __construct(Request $request, ?TokenInterface $token) | ||
{ | ||
$this->request = $request; | ||
$this->token = $token; | ||
} | ||
|
||
public function getRequest(): Request | ||
{ | ||
return $this->request; | ||
} | ||
|
||
public function getToken(): ?TokenInterface | ||
{ | ||
return $this->token; | ||
} | ||
|
||
public function setResponse(Response $response): void | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
public function getResponse(): ?Response | ||
{ | ||
return $this->response; | ||
} | ||
} |
Oops, something went wrong.