10000 [DX][Security] Add badge resolution to profiler · symfony/symfony@4385473 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4385473

Browse files
committed
[DX][Security] Add badge resolution to profiler
1 parent 8141036 commit 4385473

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@
2828
border: 0;
2929
padding: 0 0 8px 0;
3030
}
31+
32+
#collector-content .authenticators .badge {
33+
color: var(--white);
34+
display: inline-block;
35+
text-align: center;
36+
min-width: 60px;
37+
}
38+
39+
#collector-content .authenticators .badge.badge-resolved {
40+
background-color: var(--green-500);
41+
}
42+
43+
#collector-content .authenticators .badge.badge-not_resolved {
44+
background-color: var(--red-500);
45+
}
3146
</style>
3247
{% endblock %}
3348

@@ -316,13 +331,15 @@
316331
<h3 class="tab-title">Authenticators</h3>
317332
<div class="tab-content">
318333
{% if collector.authenticators|default([]) is not empty %}
319-
<table>
334+
<table class="authenticators">
320335
<thead>
321336
<tr>
322337
<th>Authenticator</th>
323338
<th>Supports</th>
339+
<th>Authenticated</th>
324340
<th>Duration</th>
325341
<th>Passport</th>
342+
<th>Badges</th>
326343
</tr>
327344
</thead>
328345

@@ -340,8 +357,18 @@
340357
<tr>
341358
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
342359
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports ? 'yes' : 'no') ~ '.svg') }}</td>
360+
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
343361
<td class="no-wrap">{{ '%0.2f'|format(authenticator.duration * 1000) }} ms</td>
344362
<td class="font-normal">{{ authenticator.passport ? profiler_dump(authenticator.passport) : '(none)' }}</td>
363+
<td class="font-normal">
364+
{% for badge in authenticator.badges ?? [] %}
365+
<span class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
366+
{{ badge.stub|abbr_class }}
367+
</span>
368+
{% else %}
369+
(none)
370+
{% endfor %}
371+
</td>
345372
</tr>
346373

347374
{% if loop.last %}

src/Symfony/Component/Security/Http/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

src/Symfony/Component/Security/Http/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)
0