Triggering RememberMe's loginFail() when token cannot be created
This commit is contained in:
parent
4279f53e34
commit
e3412e6a67
@ -68,7 +68,25 @@ class RememberMeListener implements ListenerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
if (null === $token = $this->rememberMeServices->autoLogin($request)) {
|
try {
|
||||||
|
if (null === $token = $this->rememberMeServices->autoLogin($request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (AuthenticationException $e) {
|
||||||
|
if (null !== $this->logger) {
|
||||||
|
$this->logger->warning(
|
||||||
|
'The token storage was not populated with remember-me token as the'
|
||||||
|
.' RememberMeServices was not able to create a token from the remember'
|
||||||
|
.' me information.', array('exception' => $e)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rememberMeServices->loginFail($request);
|
||||||
|
|
||||||
|
if (!$this->catchExceptions) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,43 @@ class RememberMeListenerTest extends TestCase
|
|||||||
$listener->handle($event);
|
$listener->handle($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggersLoginFail()
|
||||||
|
{
|
||||||
|
list($listener, $tokenStorage, $service, $manager) = $this->getListener();
|
||||||
|
|
||||||
|
$tokenStorage
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getToken')
|
||||||
|
->will($this->returnValue(null))
|
||||||
|
;
|
||||||
|
|
||||||
|
$exception = new AuthenticationException('Authentication failed.');
|
||||||
|
$service
|
||||||
|
->expects($this->once())
|
||||||
|
->method('autoLogin')
|
||||||
|
->will($this->throwException($exception))
|
||||||
|
;
|
||||||
|
|
||||||
|
$service
|
||||||
|
->expects($this->once())
|
||||||
|
->method('loginFail')
|
||||||
|
;
|
||||||
|
|
||||||
|
$manager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('authenticate')
|
||||||
|
;
|
||||||
|
|
||||||
|
$event = $this->getGetResponseEvent();
|
||||||
|
$event
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getRequest')
|
||||||
|
->will($this->returnValue(new Request()))
|
||||||
|
;
|
||||||
|
|
||||||
|
$listener->handle($event);
|
||||||
|
}
|
||||||
|
|
||||||
public function testOnCoreSecurity()
|
public function testOnCoreSecurity()
|
||||||
{
|
{
|
||||||
list($listener, $tokenStorage, $service, $manager) = $this->getListener();
|
list($listener, $tokenStorage, $service, $manager) = $this->getListener();
|
||||||
|
Reference in New Issue
Block a user