Skip to content

Commit a35afd0

Browse files
committed
feature #14378 [DX] Added a logout link in the security panel of the web debug toolbar (javiereguiluz)
This PR was squashed before being merged into the 2.8 branch (closes #14378). Discussion ---------- [DX] Added a logout link in the security panel of the web debug toolbar | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - While developing applications, it's common to login/logout users continuously to test security features. I usually type `/logout` in the URL, but this is boring and, depending on the application, not always works. This PR adds a small *Logout* link in the security panel when you are logged in the application: ![logged](https://cloud.githubusercontent.com/assets/73419/7184976/6c66831a-e460-11e4-86a9-eb5a48c9aa4c.png) Anonymous users won't see anything: ![anonymous](https://cloud.githubusercontent.com/assets/73419/7184982/74a95b60-e460-11e4-8b35-72d8336355fb.png) Commits ------- 192523a [DX] Added a logout link in the security panel of the web debug toolbar
2 parents 437496a + aa2e7b8 commit a35afd0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

DataCollector/SecurityDataCollector.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function collect(Request $request, Response $response, \Exception $except
5050
'enabled' => false,
5151
'authenticated' => false,
5252
'token_class' => null,
53+
'provider_key' => null,
5354
'user' => '',
5455
'roles' => array(),
5556
'inherited_roles' => array(),
@@ -60,6 +61,7 @@ public function collect(Request $request, Response $response, \Exception $except
6061
'enabled' => true,
6162
'authenticated' => false,
6263
'token_class' => null,
64+
'provider_key' => null,
6365
'user' => '',
6466
'roles' => array(),
6567
'inherited_roles' => array(),
@@ -80,6 +82,7 @@ public function collect(Request $request, Response $response, \Exception $except
8082
'enabled' => true,
8183
'authenticated' => $token->isAuthenticated(),
8284
'token_class' => get_class($token),
85+
'provider_key' => method_exists($token, 'getProviderKey') ? $token->getProviderKey() : null,
8386
'user' => $token->getUsername(),
8487
'roles' => array_map(function (RoleInterface $role) { return $role->getRole();}, $assignedRoles),
8588
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
@@ -159,6 +162,16 @@ public function getTokenClass()
159162
return $this->data['token_class'];
160163
}
161164

165+
/**
166+
* Get the provider key (i.e. the name of the active firewall).
167+
*
168+
* @return string The provider key
169+
*/
170+
public function getProviderKey()
171+
{
172+
return $this->data['provider_key'];
173+
}
174+
162175
/**
163176
* {@inheritdoc}
164177
*/

Resources/views/Collector/security.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<span>{{ collector.tokenClass|abbr_class }}</span>
3434
</div>
3535
{% endif %}
36+
{% if collector.providerKey %}
37+
<div class="sf-toolbar-info-piece">
38+
<b>Actions</b>
39+
<span><a href="{{ logout_path(collector.providerKey) }}">Logout</a></span>
40+
</div>
41+
{% endif %}
3642
{% elseif collector.enabled %}
3743
<div class="sf-toolbar-info-piece">
3844
<span>You are not authenticated.</span>

0 commit comments

Comments
 (0)