merged branch xkobal/master (PR #8830)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8830).

Discussion
----------

clearToken exception is thrown at wrong place.

The PR https://github.com/symfony/symfony/pull/8528 has added a problem when logger is enabled.

The log message for clearToken exception throw actually a fatal error because $failed doesn't exist in clearToken method. I have moved the log message to the handle method.

Commits
-------

701c25b clearToken exception is thrown at wrong place.
This commit is contained in:
Fabien Potencier 2013-08-26 16:47:55 +02:00
commit c0f56f8353
1 changed files with 6 additions and 4 deletions

View File

@ -63,7 +63,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
try {
list($user, $credentials) = $this->getPreAuthenticatedData($request);
} catch (BadCredentialsException $exception) {
$this->clearToken();
$this->clearToken($exception);
return;
}
@ -91,21 +91,23 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
$this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent);
}
} catch (AuthenticationException $failed) {
$this->clearToken();
$this->clearToken($failed);
}
}
/**
* Clears a PreAuthenticatedToken for this provider (if present)
*
* @param AuthenticationException $exception
*/
protected function clearToken()
private function clearToken(AuthenticationException $exception)
{
$token = $this->securityContext->getToken();
if ($token instanceof PreAuthenticatedToken && $this->providerKey === $token->getProviderKey()) {
$this->securityContext->setToken(null);
if (null !== $this->logger) {
$this->logger->info(sprintf("Cleared security context due to exception: %s", $failed->getMessage()));
$this->logger->info(sprintf("Cleared security context due to exception: %s", $exception->getMessage()));
}
}
}