Skip to content

Commit 37c6f0c

Browse files
committed
Add event to potentially modify authenticated token before it becomes effective
1 parent 3e57f1f commit 37c6f0c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2828
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
2929
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
30+
use Symfony\Component\Security\Http\Event\InspectAuthenticatedTokenEvent;
3031
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
3132
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
3233
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
@@ -167,6 +168,10 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
167168

168169
// create the authenticated token
169170
$authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName);
171+
172+
// announce the authenticated token
173+
$authenticatedToken = $this->eventDispatcher->dispatch(new InspectAuthenticatedTokenEvent($authenticatedToken))->getAuthenticatedToken();
174+
170175
if (true === $this->eraseCredentials) {
171176
$authenticatedToken->eraseCredentials();
172177
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Http\Event;
4+
5+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6+
use Symfony\Contracts\EventDispatcher\Event;
7+
8+
class InspectAuthenticatedTokenEvent extends Event
9+
{
10+
private $authenticatedToken;
11+
12+
public function __construct(TokenInterface $token)
13+
{
14+
$this->authenticatedToken = $token;
15+
}
16+
17+
public function getAuthenticatedToken(): TokenInterface
18+
{
19+
return $this->authenticatedToken;
20+
}
21+
22+
public function setAuthenticatedToken(TokenInterface $authenticatedToken): void
23+
{
24+
$this->authenticatedToken = $authenticatedToken;
25+
}
26+
}

0 commit comments

Comments
 (0)