Skip to content

Commit 2f6e5c4

Browse files
committed
feature #51585 [Security] Add badge resolution to profiler (Jean-Beru)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Security] Add badge resolution to profiler | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #36668 | License | MIT | Doc PR | This PR add badges resolution status in Security profiler as mentioned in #36668 (" See which badges are resolved and which aren't"). ### CSRF error ![image](https://github.com/symfony/symfony/assets/6114779/fbadfdeb-451f-4ac1-bd59-23f0cb121e6d) ### Wrong credentials ![image](https://github.com/symfony/symfony/assets/6114779/49246ffa-4152-448c-b82e-eebd43bad9d8) ### Authentication successful ![image](https://github.com/symfony/symfony/assets/6114779/1cb5f9a7-5dc2-460c-a744-0f89fb6b8e3b) Commits ------- 2324da29e7 [Security] Add badge resolution to profiler
2 parents a25e9f7 + 046b9f7 commit 2f6e5c4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Authenticator/Debug/TraceableAuthenticator.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1818
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
1919
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
20+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
2021
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
2122
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2223
use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
@@ -29,14 +30,13 @@
2930
*/
3031
final class TraceableAuthenticator implements AuthenticatorInterface, InteractiveAuthenticatorInterface, AuthenticationEntryPointInterface
3132
{
32-
private AuthenticatorInterface $authenticator;
3333
private ?Passport $passport = null;
3434
private ?float $duration = null;
3535
private ClassStub|string $stub;
36+
private ?bool $authenticated = null;
3637

37-
public function __construct(AuthenticatorInterface $authenticator)
38+
public function __construct(private AuthenticatorInterface $authenticator)
3839
{
39-
$this->authenticator = $authenticator;
4040
}
4141

4242
public function getInfo(): array
@@ -46,6 +46,16 @@ public function getInfo(): array
4646
'passport' => $this->passport,
4747
'duration' => $this->duration,
4848
'stub' => $this->stub ??= class_exists(ClassStub::class) ? new ClassStub($this->authenticator::class) : $this->authenticator::class,
49+
'authenticated' => $this->authenticated,
50+
'badges' => array_map(
51+
static function (BadgeInterface $badge): array {
52+
return [
53+
'stub' => class_exists(ClassStub::class) ? new ClassStub($badge::class) : $badge::class,
54+
'resolved' => $badge->isResolved(),
55+
];
56+
},
57+
$this->passport->getBadges(),
58+
),
4959
];
5060
}
5161

@@ -70,11 +80,15 @@ public function createToken(Passport $passport, string $firewallName): TokenInte
7080

7181
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
7282
{
83+
$this->authenticated = true;
84+
7385
return $this->authenticator->onAuthenticationSuccess($request, $token, $firewallName);
7486
}
7587

7688
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
7789
{
90+
$this->authenticated = false;
91+
7892
return $this->authenticator->onAuthenticationFailure($request, $exception);
7993
}
8094

Authenticator/Debug/TraceableAuthenticatorManagerListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function authenticate(RequestEvent $event): void
5353
'stub' => $this->hasVardumper ? new ClassStub($skippedAuthenticator::class) : $skippedAuthenticator::class,
5454
'passport' => null,
5555
'duration' => 0,
56+
'authenticated' => null,
57+
'badges' => [],
5658
];
5759
}
5860

0 commit comments

Comments
 (0)