Rename AuthenticatingListener
This commit is contained in:
parent
60d396f2d1
commit
59f49b20ca
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<!-- Listeners -->
|
<!-- Listeners -->
|
||||||
|
|
||||||
<service id="Symfony\Component\Security\Http\EventListener\AuthenticatingListener">
|
<service id="security.listener.verify_authenticator_credentials" class="Symfony\Component\Security\Http\EventListener\VerifyAuthenticatorCredentialsListener">
|
||||||
<tag name="kernel.event_subscriber" />
|
<tag name="kernel.event_subscriber" />
|
||||||
<argument type="service" id="security.encoder_factory" />
|
<argument type="service" id="security.encoder_factory" />
|
||||||
</service>
|
</service>
|
||||||
|
@ -4,6 +4,7 @@ namespace Symfony\Component\Security\Http\EventListener;
|
|||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
|
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||||
use Symfony\Component\Security\Http\Authenticator\CustomAuthenticatedInterface;
|
use Symfony\Component\Security\Http\Authenticator\CustomAuthenticatedInterface;
|
||||||
use Symfony\Component\Security\Http\Authenticator\PasswordAuthenticatedInterface;
|
use Symfony\Component\Security\Http\Authenticator\PasswordAuthenticatedInterface;
|
||||||
@ -19,7 +20,7 @@ use Symfony\Component\Security\Http\Event\VerifyAuthenticatorCredentialsEvent;
|
|||||||
* @final
|
* @final
|
||||||
* @experimental in 5.1
|
* @experimental in 5.1
|
||||||
*/
|
*/
|
||||||
class AuthenticatingListener implements EventSubscriberInterface
|
class VerifyAuthenticatorCredentialsListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
private $encoderFactory;
|
private $encoderFactory;
|
||||||
|
|
||||||
@ -28,22 +29,22 @@ class AuthenticatingListener implements EventSubscriberInterface
|
|||||||
$this->encoderFactory = $encoderFactory;
|
$this->encoderFactory = $encoderFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubscribedEvents(): array
|
|
||||||
{
|
|
||||||
return [VerifyAuthenticatorCredentialsEvent::class => ['onAuthenticating', 128]];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onAuthenticating(VerifyAuthenticatorCredentialsEvent $event): void
|
public function onAuthenticating(VerifyAuthenticatorCredentialsEvent $event): void
|
||||||
{
|
{
|
||||||
$authenticator = $event->getAuthenticator();
|
$authenticator = $event->getAuthenticator();
|
||||||
if ($authenticator instanceof PasswordAuthenticatedInterface) {
|
if ($authenticator instanceof PasswordAuthenticatedInterface) {
|
||||||
// Use the password encoder to validate the credentials
|
// Use the password encoder to validate the credentials
|
||||||
$user = $event->getUser();
|
$user = $event->getUser();
|
||||||
$event->setCredentialsValid($this->encoderFactory->getEncoder($user)->isPasswordValid(
|
$presentedPassword = $authenticator->getPassword($event->getCredentials());
|
||||||
$user->getPassword(),
|
if ('' === $presentedPassword) {
|
||||||
$authenticator->getPassword($event->getCredentials()),
|
throw new BadCredentialsException('The presented password cannot be empty.');
|
||||||
$user->getSalt()
|
}
|
||||||
));
|
|
||||||
|
if (null === $user->getPassword()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$event->setCredentialsValid($this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt()));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -65,4 +66,9 @@ class AuthenticatingListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
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));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents(): array
|
||||||
|
{
|
||||||
|
return [VerifyAuthenticatorCredentialsEvent::class => ['onAuthenticating', 128]];
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user