diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index 87112deffa..dbfcb931ae 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -6,6 +6,7 @@ The CHANGELOG for version 5.4 and newer can be found in the security sub-package 5.3 --- + * Add `getPassport()` method and a second `$passport` constructor argument to `AuthenticationTokenCreatedEvent` * The authenticator system is no longer experimental * Login Link functionality is no longer experimental * Add `RememberMeConditionsListener` to check if remember me is requested and supported, and set priority of `RememberMeListener` to -63 diff --git a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php index 539cc8ee10..f18dbf4856 100644 --- a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php +++ b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php @@ -74,7 +74,7 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent $token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport(new UserBadge(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(), function () use ($user) { return $user; }), $badges), $this->firewallName); // announce the authenticated token - $token = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($token))->getAuthenticatedToken(); + $token = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($token, $passport))->getAuthenticatedToken(); // authenticate this in the system return $this->handleAuthenticationSuccess($token, $passport, $request, $authenticator); @@ -188,7 +188,7 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent $authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName); // announce the authenticated token - $authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken))->getAuthenticatedToken(); + $authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken, $passport))->getAuthenticatedToken(); if (true === $this->eraseCredentials) { $authenticatedToken->eraseCredentials(); diff --git a/src/Symfony/Component/Security/Http/Event/AuthenticationTokenCreatedEvent.php b/src/Symfony/Component/Security/Http/Event/AuthenticationTokenCreatedEvent.php index a2f0de3f53..98db3ebc2f 100644 --- a/src/Symfony/Component/Security/Http/Event/AuthenticationTokenCreatedEvent.php +++ b/src/Symfony/Component/Security/Http/Event/AuthenticationTokenCreatedEvent.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Http\Event; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; use Symfony\Contracts\EventDispatcher\Event; /** @@ -22,10 +23,12 @@ use Symfony\Contracts\EventDispatcher\Event; class AuthenticationTokenCreatedEvent extends Event { private $authenticatedToken; + private $passport; - public function __construct(TokenInterface $token) + public function __construct(TokenInterface $token, PassportInterface $passport) { $this->authenticatedToken = $token; + $this->passport = $passport; } public function getAuthenticatedToken(): TokenInterface @@ -37,4 +40,9 @@ class AuthenticationTokenCreatedEvent extends Event { $this->authenticatedToken = $authenticatedToken; } + + public function getPassport(): PassportInterface + { + return $this->passport; + } }