|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Symfony\Component\HttpKernel\Security\Firewall;
|
|
|
|
|
|
+use Symfony\Component\HttpKernel\Security\Logout\LogoutHandlerInterface;
|
|
|
use Symfony\Component\Security\SecurityContext;
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
use Symfony\Component\EventDispatcher\Event;
|
|
@@ -26,10 +27,12 @@ class LogoutListener implements ListenerInterface
|
|
|
protected $securityContext;
|
|
|
protected $logoutPath;
|
|
|
protected $targetUrl;
|
|
|
+ protected $handlers;
|
|
|
|
|
|
/**
|
|
|
* Constructor
|
|
|
*
|
|
|
+ * @param SecurityContext $securityContext
|
|
|
* @param string $logoutPath The path that starts the logout process
|
|
|
* @param string $targetUrl The URL to redirect to after logout
|
|
|
*/
|
|
@@ -38,7 +41,19 @@ class LogoutListener implements ListenerInterface
|
|
|
$this->securityContext = $securityContext;
|
|
|
$this->logoutPath = $logoutPath;
|
|
|
$this->targetUrl = $targetUrl;
|
|
|
+ $this->handlers = array();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a logout handler
|
|
|
+ *
|
|
|
+ * @param LogoutHandlerInterface $handler
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addHandler(LogoutHandlerInterface $handler)
|
|
|
+ {
|
|
|
+ $this->handlers[] = $handler;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Registers a core.security listener.
|
|
@@ -59,7 +74,7 @@ class LogoutListener implements ListenerInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ * Performs the logout if requested
|
|
|
*
|
|
|
* @param Event $event An Event instance
|
|
|
*/
|
|
@@ -70,13 +85,17 @@ class LogoutListener implements ListenerInterface
|
|
|
if ($this->logoutPath !== $request->getPathInfo()) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- $this->securityContext->setToken(null);
|
|
|
- $request->getSession()->invalidate();
|
|
|
-
|
|
|
+
|
|
|
$response = new Response();
|
|
|
$response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
|
|
|
-
|
|
|
+
|
|
|
+ $token = $this->securityContext->getToken();
|
|
|
+
|
|
|
+ foreach ($this->handlers as $handler) {
|
|
|
+ $handler->logout($request, $response, $token);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->securityContext->setToken(null);
|
|
|
$event->setReturnValue($response);
|
|
|
|
|
|
return true;
|