Skip to content

Commit fee9b30

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 ------- 2324da2 [Security] Add badge resolution to profiler
2 parents 2cfaa9d + 2324da2 commit fee9b30

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@
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+
}
37+
#collector-content .authenticators .badge.badge-resolved {
38+
background-color: var(--green-500);
39+
}
40+
#collector-content .authenticators .badge.badge-not_resolved {
41+
background-color: var(--yellow-500);
42+
}
43+
44+
#collector-content .authenticators svg[data-icon-name="icon-tabler-check"] {
45+
color: var(--green-500);
46+
}
47+
#collector-content .authenticators svg[data-icon-name="icon-tabler-x"] {
48+
color: var(--red-500);
49+
}
3150
</style>
3251
{% endblock %}
3352

@@ -316,13 +335,15 @@
316335
<h3 class="tab-title">Authenticators</h3>
317336
<div class="tab-content">
318337
{% if collector.authenticators|default([]) is not empty %}
319-
<table>
338+
<table class="authenticators">
320339
<thead>
321340
<tr>
322341
<th>Authenticator</th>
323342
<th>Supports</th>
343+
<th>Authenticated</th>
324344
<th>Duration</th>
325345
<th>Passport</th>
346+
<th>Badges</th>
326347
</tr>
327348
</thead>
328349

@@ -340,8 +361,18 @@
340361
<tr>
341362
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
342363
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports ? 'yes' : 'no') ~ '.svg') }}</td>
364+
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
343365
<td class="no-wrap">{{ '%0.2f'|format(authenticator.duration * 1000) }} ms</td>
344366
<td class="font-normal">{{ authenticator.passport ? profiler_dump(authenticator.passport) : '(none)' }}</td>
367+
<td class="font-normal">
368+
{% for badge in authenticator.badges ?? [] %}
369+
<span class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
370+
{{ badge.stub|abbr_class }}
371+
</span>
372+
{% else %}
373+
(none)
374+
{% endfor %}
375+
</td>
345376
</tr>
346377

347378
{% 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy