Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59f49b2

Browse filesBrowse files
committed
Rename AuthenticatingListener
1 parent 60d396f commit 59f49b2
Copy full SHA for 59f49b2

File tree

2 files changed

+18
-12
lines changed
Filter options

2 files changed

+18
-12
lines changed

‎src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<!-- Listeners -->
4545

46-
<service id="Symfony\Component\Security\Http\EventListener\AuthenticatingListener">
46+
<service id="security.listener.verify_authenticator_credentials" class="Symfony\Component\Security\Http\EventListener\VerifyAuthenticatorCredentialsListener">
4747
<tag name="kernel.event_subscriber" />
4848
<argument type="service" id="security.encoder_factory" />
4949
</service>

‎src/Symfony/Component/Security/Http/EventListener/AuthenticatingListener.php renamed to ‎src/Symfony/Component/Security/Http/EventListener/VerifyAuthenticatorCredentialsListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/EventListener/VerifyAuthenticatorCredentialsListener.php
+17-11Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
66
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
7+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
78
use Symfony\Component\Security\Core\Exception\LogicException;
89
use Symfony\Component\Security\Http\Authenticator\CustomAuthenticatedInterface;
910
use Symfony\Component\Security\Http\Authenticator\PasswordAuthenticatedInterface;
@@ -19,7 +20,7 @@
1920
* @final
2021
* @experimental in 5.1
2122
*/
22-
class AuthenticatingListener implements EventSubscriberInterface
23+
class VerifyAuthenticatorCredentialsListener implements EventSubscriberInterface
2324
{
2425
private $encoderFactory;
2526

@@ -28,22 +29,22 @@ public function __construct(EncoderFactoryInterface $encoderFactory)
2829
$this->encoderFactory = $encoderFactory;
2930
}
3031

31-
public static function getSubscribedEvents(): array
32-
{
33-
return [VerifyAuthenticatorCredentialsEvent::class => ['onAuthenticating', 128]];
34-
}
35-
3632
public function onAuthenticating(VerifyAuthenticatorCredentialsEvent $event): void
3733
{
3834
$authenticator = $event->getAuthenticator();
3935
if ($authenticator instanceof PasswordAuthenticatedInterface) {
4036
// Use the password encoder to validate the credentials
4137
$user = $event->getUser();
42-
$event->setCredentialsValid($this->encoderFactory->getEncoder($user)->isPasswordValid(
43-
$user->getPassword(),
44-
$authenticator->getPassword($event->getCredentials()),
45-
$user->getSalt()
46-
));
38+
$presentedPassword = $authenticator->getPassword($event->getCredentials());
39+
if ('' === $presentedPassword) {
40+
throw new BadCredentialsException('The presented password cannot be empty.');
41+
}
42+
43+
if (null === $user->getPassword()) {
44+
return;
45+
}
46+
47+
$event->setCredentialsValid($this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt()));
4748

4849
return;
4950
}
@@ -65,4 +66,9 @@ public function onAuthenticating(VerifyAuthenticatorCredentialsEvent $event): vo
6566

6667
throw new LogicException(sprintf('Authenticator %s does not have valid credentials. Authenticators must implement one of the authenticated interfaces (%s, %s or %s).', \get_class($authenticator), PasswordAuthenticatedInterface::class, TokenAuthenticatedInterface::class, CustomAuthenticatedInterface::class));
6768
}
69+
70+
public static function getSubscribedEvents(): array
71+
{
72+
return [VerifyAuthenticatorCredentialsEvent::class => ['onAuthenticating', 128]];
73+
}
6874
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.