for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FSi\Bundle\AdminSecurityBundle\EventListener;
use FSi\Bundle\AdminSecurityBundle\Event\AdminSecurityEvents;
use FSi\Bundle\AdminSecurityBundle\Event\ChangePasswordEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class LogoutUserListener implements EventSubscriberInterface
{
* @var RequestStack
private $requestStack;
* @var TokenStorageInterface
private $tokenStorage;
* @param RequestStack $requestStack
* @param TokenStorageInterface $tokenStorage
public function __construct(RequestStack $requestStack, TokenStorageInterface $tokenStorage)
$this->requestStack = $requestStack;
$this->tokenStorage = $tokenStorage;
}
* {@inheritdoc}
public static function getSubscribedEvents()
return [
AdminSecurityEvents::CHANGE_PASSWORD => 'onChangePassword'
];
* @param ChangePasswordEvent $event
public function onChangePassword(ChangePasswordEvent $event)
$token = $this->tokenStorage->getToken();
if ($token && $token->getUser() === $event->getUser()) {
$this->requestStack->getMasterRequest()->getSession()->invalidate();
$this->tokenStorage->setToken(null);