Skip to content

Commit

Permalink
[Security] LogoutListener should not invoke handlers' logout() method…
Browse files Browse the repository at this point in the history
… if token is empty

If a user was not authenticated and visited the logout path, a null value was passed to the handler's logout() method, resulting in a catchable fatal error.
  • Loading branch information
jmikola authored and fabpot committed Dec 30, 2010
1 parent 8800a9a commit 46b1b5b
Showing 1 changed file with 13 additions and 13 deletions.
Expand Up @@ -27,7 +27,7 @@ class LogoutListener implements ListenerInterface
protected $securityContext;
protected $logoutPath;
protected $targetUrl;
protected $handlers;
protected $handlers;

/**
* Constructor
Expand All @@ -43,17 +43,17 @@ public function __construct(SecurityContext $securityContext, $logoutPath, $targ
$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.
Expand All @@ -65,14 +65,14 @@ public function register(EventDispatcher $dispatcher)
{
$dispatcher->connect('core.security', array($this, 'handle'), 0);
}

/**
* {@inheritDoc}
*/
public function unregister(EventDispatcher $dispatcher)
{
}

/**
* Performs the logout if requested
*
Expand All @@ -85,16 +85,16 @@ public function handle(Event $event)
if ($this->logoutPath !== $request->getPathInfo()) {
return;
}

$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);

if ($token = $this->securityContext->getToken()) {
foreach ($this->handlers as $handler) {
$handler->logout($request, $response, $token);
}
}

$this->securityContext->setToken(null);
$event->setReturnValue($response);

Expand Down

0 comments on commit 46b1b5b

Please sign in to comment.