<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Http\Event\LogoutEvent;
/**
*
* @author "wendell.zheng <wxzheng@ustc.edu.cn>"
*/
class CasLogoutSubscriber implements EventSubscriberInterface
{
protected $url;
protected $casUrl;
public function __construct(string $url, string $casUrl)
{
$this->url = $url;
$this->casUrl = $casUrl;
}
public static function getSubscribedEvents(): array
{
return [
LogoutEvent::class => 'onLogout'
];
}
public function onLogout(LogoutEvent $event): void
{
if (strpos($event->getRequest()->getRequestUri(), 'cas') !== false) {
$event->setResponse(new RedirectResponse($this->casUrl . 'logout?service=' . $this->url));
}
}
}