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

Skip to content

Commit 002a527

Browse files
committed
[SecurityBundle] Improve authenticators tab
1 parent 2cb470e commit 002a527

File tree

2 files changed

+81
-40
lines changed

2 files changed

+81
-40
lines changed

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

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,27 @@
2929
padding: 0 0 8px 0;
3030
}
3131
32+
#collector-content .authenticators .sf-toggle + .sf-toggle {
33+
margin-left: 10px;
34+
}
35+
36+
#collector-content .authenticators .toggleable {
37+
background: var(--code-block-background);
38+
border-radius: 4px;
39+
padding: 5px;
40+
}
41+
#collector-content .authenticators .toggleable + .toggleable {
42+
margin-top: 10px;
43+
}
44+
45+
#collector-content .authenticators .badges {
46+
margin: 10px 0 0;
47+
}
48+
3249
#collector-content .authenticators .badge {
3350
color: var(--white);
3451
display: inline-block;
52+
margin-bottom: 0;
3553
text-align: center;
3654
}
3755
#collector-content .authenticators .badge.badge-resolved {
@@ -40,13 +58,6 @@
4058
#collector-content .authenticators .badge.badge-not_resolved {
4159
background-color: var(--yellow-500);
4260
}
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-
}
5061
</style>
5162
{% endblock %}
5263

@@ -336,49 +347,73 @@
336347
<div class="tab-content">
337348
{% if collector.authenticators|default([]) is not empty %}
338349
<table class="authenticators">
350+
<colgroup>
351+
<col>
352+
<col style="width: 100%">
353+
</colgroup>
339354
<thead>
340355
<tr>
356+
<th>Status</th>
341357
<th>Authenticator</th>
342-
<th>Supports</th>
343-
<th>Authenticated</th>
344-
<th>Duration</th>
345-
<th>Passport</th>
346-
<th>Badges</th>
347358
</tr>
348359
</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-
360+
<tbody>
361+
{% for i, authenticator in collector.authenticators %}
361362
<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>
363+
<td class="font-normal text-small">
364+
{% if authenticator.authenticated %}
365+
{% set status_text, label_status = 'successful', 'success' %}
366+
{% elseif authenticator.supports is not same as(false) %}
367+
{% set status_text, label_status = 'unsuccessful', 'error' %}
372368
{% else %}
373-
(none)
374-
{% endfor %}
369+
{% set status_text, label_status = 'skipped', false %}
370+
{% endif %}
371+
<div class="label {{ label_status ? 'status-' ~ label_status }}">{{ status_text }}</div>
372+
{{ authenticator.duration is not null ? '%0.2f ms'|format(authenticator.duration * 1000) }}
373+
{{ authenticator.supports is null ? '(lazy)' }}
374+
</td>
375+
<td>
376+
{{ profiler_dump(authenticator.stub) }}
377+
378+
<div class="font-normal">
379+
{% if authenticator.passport %}
380+
<button
381+
class="btn btn-link text-small sf-toggle"
382+
data-toggle-selector="#authenticator-{{ i }}-passport"
383+
data-toggle-alt-content="Hide passport"
384+
>View passport</button>
385+
{% endif %}
386+
{% if authenticator.exception ?? null %}
387+
<button
388+
class="btn btn-link text-small sf-toggle"
389+
data-toggle-selector="#authenticator-{{ i }}-exception"
390+
data-toggle-alt-content="Hide exception"
391+
>View exception</button>
392+
{% endif %}
393+
</div>
394+
{% if authenticator.passport %}
395+
<div class="toggleable" id="authenticator-{{ i }}-passport">
396+
{{ profiler_dump(authenticator.passport) }}
397+
{% if authenticator.badges %}
398+
<div class="badges">
399+
{% for badge in authenticator.badges %}
400+
<span class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
401+
{{ badge.stub|abbr_class }}
402+
</span>
403+
{% endfor %}
404+
</div>
405+
{% endif %}
406+
</div>
407+
{% endif %}
408+
{% if authenticator.exception ?? null %}
409+
<div class="toggleable" id="authenticator-{{ i }}-exception">
410+
{{ profiler_dump(authenticator.exception) }}
411+
</div>
412+
{% endif %}
375413
</td>
376414
</tr>
377-
378-
{% if loop.last %}
379-
</tbody>
380-
{% endif %}
381415
{% endfor %}
416+
</tbody>
382417
</table>
383418
{% else %}
384419
<div class="empty">

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