Skip to content

Commit 71ad719

Browse files
Merge branch '3.2' into 3.3
* 3.2: [DI] Handle root namespace in service definitions Use rawurlencode() to transform the Cookie into a string [Security] Fix authentication.failure event not dispatched on AccountStatusException
2 parents c598b1a + 82fbfd4 commit 71ad719

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

Authentication/AuthenticationProviderManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public function authenticate(TokenInterface $token)
8181
break;
8282
}
8383
} catch (AccountStatusException $e) {
84-
$e->setToken($token);
84+
$lastException = $e;
8585

86-
throw $e;
86+
break;
8787
} catch (AuthenticationException $e) {
8888
$lastException = $e;
8989
}

Tests/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
16+
use Symfony\Component\Security\Core\AuthenticationEvents;
17+
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
18+
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
1619
use Symfony\Component\Security\Core\Exception\ProviderNotFoundException;
1720
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1821
use Symfony\Component\Security\Core\Exception\AccountStatusException;
@@ -125,6 +128,50 @@ public function testEraseCredentialFlag()
125128
$this->assertEquals('bar', $token->getCredentials());
126129
}
127130

131+
public function testAuthenticateDispatchesAuthenticationFailureEvent()
132+
{
133+
$token = new UsernamePasswordToken('foo', 'bar', 'key');
134+
$provider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
135+
$provider->expects($this->once())->method('supports')->willReturn(true);
136+
$provider->expects($this->once())->method('authenticate')->willThrowException($exception = new AuthenticationException());
137+
138+
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
139+
$dispatcher
140+
->expects($this->once())
141+
->method('dispatch')
142+
->with(AuthenticationEvents::AUTHENTICATION_FAILURE, $this->equalTo(new AuthenticationFailureEvent($token, $exception)));
143+
144+
$manager = new AuthenticationProviderManager(array($provider));
145+
$manager->setEventDispatcher($dispatcher);
146+
147+
try {
148+
$manager->authenticate($token);
149+
$this->fail('->authenticate() should rethrow exceptions');
150+
} catch (AuthenticationException $e) {
151+
$this->assertSame($token, $exception->getToken());
152+
}
153+
}
154+
155+
public function testAuthenticateDispatchesAuthenticationSuccessEvent()
156+
{
157+
$token = new UsernamePasswordToken('foo', 'bar', 'key');
158+
159+
$provider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
160+
$provider->expects($this->once())->method('supports')->willReturn(true);
161+
$provider->expects($this->once())->method('authenticate')->willReturn($token);
162+
163+
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
164+
$dispatcher
165+
->expects($this->once())
166+
->method('dispatch')
167+
->with(AuthenticationEvents::AUTHENTICATION_SUCCESS, $this->equalTo(new AuthenticationEvent($token)));
168+
169+
$manager = new AuthenticationProviderManager(array($provider));
170+
$manager->setEventDispatcher($dispatcher);
171+
172+
$this->assertSame($token, $manager->authenticate($token));
173+
}
174+
128175
protected function getAuthenticationProvider($supports, $token = null, $exception = null)
129176
{
130177
$provider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();

0 commit comments

Comments
 (0)