Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 619d8e4

Browse files
committed
[SecurityBundle] Improve authenticators tab
1 parent 1a16ebc commit 619d8e4

File tree

2 files changed

+124
-43
lines changed

2 files changed

+124
-43
lines changed

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

+118-43
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,57 @@
2929
padding: 0 0 8px 0;
3030
}
3131
32+
#collector-content .authenticator-name {
33+
align-items: center;
34+
display: flex;
35+
gap: 16px;
36+
}
37+
38+
#collector-content .authenticators .toggle-button {
39+
margin-left: auto;
40+
}
41+
#collector-content .authenticators .sf-toggle-on .toggle-button {
42+
transform: rotate(180deg);
43+
}
44+
#collector-content .authenticators .toggle-button svg {
45+
display: block;
46+
}
47+
48+
#collector-content .authenticators th,
49+
#collector-content .authenticators td {
50+
vertical-align: baseline;
51+
}
52+
#collector-content .authenticators th,
53+
#collector-content .authenticators td {
54+
vertical-align: baseline;
55+
}
56+
57+
#collector-content .authenticators .label {
58+
display: block;
59+
text-align: center;
60+
}
61+
62+
#collector-content .authenticator-data {
63+
box-shadow: none;
64+
margin: 0;
65+
}
66+
67+
#collector-content .authenticator-data tr:first-child th,
68+
#collector-content .authenticator-data tr:first-child td {
69+
border-top: 0;
70+
}
71+
3272
#collector-content .authenticators .badge {
3373
color: var(--white);
3474
display: inline-block;
35-
text-align: center;
75+
margin: 4px 0;
3676
}
3777
#collector-content .authenticators .badge.badge-resolved {
3878
background-color: var(--green-500);
3979
}
4080
#collector-content .authenticators .badge.badge-not_resolved {
4181
background-color: var(--yellow-500);
4282
}
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-
}
5083
</style>
5184
{% endblock %}
5285

@@ -355,48 +388,90 @@
355388
<div class="tab-content">
356389
{% if collector.authenticators|default([]) is not empty %}
357390
<table class="authenticators">
391+
<colgroup>
392+
<col>
393+
<col style="width: 100%">
394+
</colgroup>
358395
<thead>
359396
<tr>
360-
<th>Authenticator</th>
361-
<th>Supports</th>
362-
<th>Authenticated</th>
363-
<th>Duration</th>
364-
<th>Passport</th>
365-
<th>Badges</th>
397+
<th scope="col">Status</th>
398+
<th scope="col">Authenticator</th>
366399
</tr>
367400
</thead>
368-
369-
{% set previous_event = (collector.listeners|first) %}
370-
{% for authenticator in collector.authenticators %}
371-
{% if loop.first or authenticator != previous_event %}
372-
{% if not loop.first %}
373-
</tbody>
374-
{% endif %}
375-
376-
<tbody>
377-
{% set previous_event = authenticator %}
378-
{% endif %}
379-
380-
<tr>
381-
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
382-
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports is same as (false) ? 'no' : 'yes') ~ '.svg') }}</td>
383-
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
384-
<td class="no-wrap">{{ authenticator.duration is null ? '(none)' : '%0.2f ms'|format(authenticator.duration * 1000) }}</td>
385-
<td class="font-normal">{{ authenticator.passport ? profiler_dump(authenticator.passport) : '(none)' }}</td>
386-
<td class="font-normal">
387-
{% for badge in authenticator.badges ?? [] %}
388-
<span class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
389-
{{ badge.stub|abbr_class }}
390-
</span>
401+
{% for i, authenticator in collector.authenticators %}
402+
<tr class="sf-toggle"
403+
data-toggle-selector="#authenticator-{{ i }}"
404+
data-toggle-initial="{{ authenticator.authenticated is not null ? 'display' }}"
405+
>
406+
<td class="font-normal text-small">
407+
{% if authenticator.authenticated %}
408+
{% set status_text, label_status = 'success', 'success' %}
409+
{% elseif authenticator.authenticated is null %}
410+
{% set status_text, label_status = 'skipped', false %}
391411
{% else %}
392-
(none)
393-
{% endfor %}
412+
{% set status_text, label_status = 'failure', 'error' %}
413+
{% endif %}
414+
<span class="label {{ label_status ? 'status-' ~ label_status }}">{{ status_text }}</span>
415+
</td>
416+
<td>
417+
<span class="authenticator-name">
418+
{{ profiler_dump(authenticator.stub) }}
419+
<button class="btn btn-link toggle-button" type="button">
420+
{{ source('@WebProfiler/Icon/chevron-down.svg') }}
421+
</button>
422+
</span>
423+
<div id="authenticator-{{ i }}" class="font-normal">
424+
{% if authenticator.supports is same as(false) %}
425+
<div class="empty">
426+
<p>This authenticator did not support the request.</p>
427+
</div>
428+
{% elseif authenticator.authenticated is null %}
429+
<div class="empty">
430+
<p>An authenticator ran before this one.</p>
431+
</div>
432+
{% else %}
433+
<table class="authenticator-data">
434+
<colgroup>
435+
<col>
436+
<col style="width: 100%">
437+
</colgroup>
438+
<tr>
439+
<th scope="row">Lazy</th>
440+
<td>{{ authenticator.supports is null ? 'yes' : 'no' }}</td>
441+
</tr>
442+
<tr>
443+
<th scope="row">Duration</th>
444+
<td>{{ '%0.2f ms'|format(authenticator.duration * 1000) }}</td>
445+
</tr>
446+
{% if authenticator.passport %}
447+
<tr>
448+
<th scope="row">Passport</th>
449+
<td>{{ profiler_dump(authenticator.passport) }}</td>
450+
</tr>
451+
{% endif %}
452+
{% if authenticator.badges %}
453+
<tr>
454+
<th scope="row">Badges</th>
455+
<td>
456+
{% for badge in authenticator.badges %}
457+
<span class="badge badge-{{ badge.resolved ? 'resolved' : 'not_resolved' }}">
458+
{{ badge.stub|abbr_class }}
459+
</span>
460+
{% endfor %}
461+
</td>
462+
</tr>
463+
{% endif %}
464+
{% if authenticator.exception %}
465+
<tr>
466+
<th scope="row">Exception</th>
467+
<td>{{ profiler_dump(authenticator.exception) }}</td>
468+
</tr>
469+
{% endif %}
470+
</table>
471+
{% endif %}
472+
</div>
394473
</td>
395474
</tr>
396-
397-
{% if loop.last %}
398-
</tbody>
399-
{% endif %}
400475
{% endfor %}
401476
</table>
402477
{% else %}

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

+6
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)