8000 [SecurityBundle] Improve authenticators tab · MatTheCat/symfony@db6b852 · GitHub
[go: up one dir, main page]

Skip to content

Commit db6b852

Browse files
committed
[SecurityBundle] Improve authenticators tab
1 parent 2a2174e commit db6b852

File tree

2 files changed

+91
-50
lines changed

2 files changed

+91
-50
lines changed

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

Lines changed: 85 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,41 @@
2929
padding: 0 0 8px 0;
3030
}
3131
32+
#collector-content .authenticators {
33+
padding-left: 1.25em;
34+
}
35+
#collector-content .authenticator {
36+
display: flex;
37+
flex-direction: column;
38+
gap: .5em;
39+
padding-left: .5em;
40+
}
41+
#collector-content .authenticator-successful {
42+
list-style-type: '🟢';
43+
}
44+
#collector-content .authenticator-unsuccessful {
45+
list-style-type: '🔴';
46+
}
47+
#collector-content .authenticator-skipped {
48+
list-style-type: '';
49+
}
50+
#collector-content .authenticator-late {
51+
list-style-type: '';
52+
}
53+
54+
#collector-content .menu {
55+
display: flex;
56+
flex-wrap: wrap;
57+
gap: .25em .5em;
58+
}
59+
60+
#collector-content .authenticators .badges {
61+
padding: 1em 0 0;
62+
}
3263
#collector-content .authenticators .badge {
3364
color: var(--white);
3465
display: inline-block;
66+
margin-bottom: 0;
3567
text-align: center;
3668
}
3769
#collector-content .authenticators .badge.badge-resolved {
@@ -40,13 +72,6 @@
4072
#collector-content .authenticators .badge.badge-not_resolved {
4173
background-color: var(--yellow-500);
4274
}
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-
}
5075
</style>
5176
{% endblock %}
5277

@@ -335,51 +360,61 @@
335360
<h3 class="tab-title">Authenticators</h3>
336361
<div class="tab-content">
337362
{% if collector.authenticators|default([]) is not empty %}
338-
<table class="authenticators">
339-
<thead>
340-
<tr>
341-
<th>Authenticator</th>
342-
<th>Supports</th>
343-
<th>Authenticated</th>
344-
<th>Duration</th>
345-
<th>Passport</th>
346-
<th>Badges</th>
347-
</tr>
348-
</thead>
349-
350-
{% set previous_event = (collector.listeners|first) %}
351-
{% for authenticator in collector.authenticators %}
352-
{% if loop.first or authenticator != previous_event %}
353-
{% if not loop.first %}
354-
</tbody>
355-
{% endif %}
356-
357-
<tbody>
358-
{% set previous_event = authenticator %}
359-
{% endif %}
360-
361-
<tr>
362-
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
363-
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports is same as (false) ? 'no' : 'yes') ~ '.svg') }}</td>
364-
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
365-
<td class="no-wrap">{{ authenticator.duration is null ? '(none)' : '%0.2f ms'|format(authenticator.duration * 1000) }}</td>
366-
<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>
376-
</tr>
377-
378-
{% if loop.last %}
379-
</tbody>
363+
<ul class="authenticators">
364+
{% for i, authenticator in collector.authenticators %}
365+
{% if authenticator.authenticated %}
366+
{% set status, text = 'successful', 'authenticated a user' %}
367+
{% elseif authenticator.exception %}
368+
{% set status, text = 'unsuccessful', 'failed to authenticate a user' %}
369+
{% elseif authenticator.supports is same as(false) %}
370+
{% set status, text = 'skipped', 'was skipped' %}
371+
{% else %}
372+
{% set status, text = 'late', 'came after a response was set' %}
380373
{% endif %}
374+
<li class="authenticator authenticator-{{ status }}">
375+
{{ authenticator.stub|abbr_class }}
376+
{{ authenticator.supports is null ? '(lazy)' }}
377+
{{ text }}
378+
<div class="text-small">
379+
{% if authenticator.passport %}
380+
<a
381+
href="#"
382+
class="sf-toggle"
383+
data-toggle-selector="#authenticator-{{ i }}-passport"
384+
data-toggle-alt-content="Hide passport"
385+
>View passport</a>
386+
{% endif %}
387+
{% if authenticator.exception %}
388+
<a
389+
href="#"
390+
class="sf-toggle"
391+
data-toggle-selector="#authenticator-{{ i }}-exception"
392+
data-toggle-alt-content="Hide exception"
393+
>View exception</a>
394+
{% endif %}
395+
</div>
396+
{% if authenticator.passport %}
397+
<div class="card" id="authenticator-{{ i }}-passport">
398+
{{ profiler_dump(authenticator.passport) }}
399+
{% if authenticator.badges %}
400+
<ul class="badges">
401+
{% for badge in authenticator.badges %}
402+
<li class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
403+
{{ badge.stub|abbr_class }}
404+
</li>
405+
{% endfor %}
406+
</ul>
407+
{% endif %}
408+
</div>
409+
{% endif %}
410+
{% if authenticator.exception %}
411+
<div class="card" id="authenticator-{{ i }}-exception">
412+
{{ profiler_dump(authenticator.exception) }}
413+
</div>
414+
{% endif %}
415+
</li>
381416
{% endfor %}
382-
</table>
417+
</ul>
383418
{% else %}
384419
<div class="empty">
385420
<p>No authenticators have been recorded. Check previous profiles on your authentication endpoint.</p>

src/Symfony/Component/Security/Http/Authenticator/Debug/TraceableAuthenticator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class TraceableAuthenticator implements AuthenticatorInterface, Interactiv
3535
private ?float $duration = null;
3636
private ClassStub|string $stub;
3737
private ?bool $authenticated = null;
38+
private ?AuthenticationException $exception = null;
3839

3940
public function __construct(private AuthenticatorInterface $authenticator)
4041
{
@@ -57,6 +58,7 @@ static function (BadgeInterface $badge): array {
5758
},
5859
$this->passport?->getBadges() ?? [],
5960
),
61+
'exception' => $this->exception,
6062
];
6163
}
6264

@@ -92,6 +94,10 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
9294
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
9395
{
9496
$this->authenticated = false;
97+
$this->exception = $exception->getPrevious() instanceof AuthenticationException
98+
? $exception->getPrevious()
99+
: $exception
100+
;
95101

96102
return $this->authenticator->onAuthenticationFailure($request, $exception);
97103
}

0 commit comments

Comments
 (0)
0