8000 merged branch lmcd/wdt-token (PR #6431) · loicfrering/symfony@eedafad · GitHub
[go: up one dir, main page]

Skip to content

Commit eedafad

Browse files
committed
merged branch lmcd/wdt-token (PR symfony#6431)
This PR was merged into the master branch. Commits ------- 4663450 Use abbr_class 15c52f5 Show class name of security token in WDT Discussion ---------- Show class name for security token in WDT I found this to be really useful when creating custom authentication providers Example: ![token](https://f.cloud.github.com/assets/363540/23829/2f28c1ac-4a70-11e2-91d4-e3ac27201b4f.png)
2 parents 06c3222 + 4663450 commit eedafad

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,23 @@ public function collect(Request $request, Response $response, \Exception $except
3939
$this->data = array(
4040
'enabled' => false,
4141
'authenticated' => false,
42+
'token_class' => null,
4243
'user' => '',
4344
'roles' => array(),
4445
);
4546
} elseif (null === $token = $this->context->getToken()) {
4647
$this->data = array(
4748
'enabled' => true,
4849
'authenticated' => false,
50+
'token_class' => null,
4951
'user' => '',
5052
'roles' => array(),
5153
);
5254
} else {
5355
$this->data = array(
5456
'enabled' => true,
5557
'authenticated' => $token->isAuthenticated(),
58+
'token_class' => get_class($token),
5659
'user' => $token->getUsername(),
5760
'roles' => array_map(function ($role){ return $role->getRole();}, $token->getRoles()),
5861
);
@@ -99,6 +102,16 @@ public function isAuthenticated()
99102
return $this->data['authenticated'];
100103
}
101104

105+
/**
106+
* Get the class name of the security token.
107+
*
108+
* @return String The token
109+
*/
110+
public function getTokenClass()
111+
{
112+
return $this->data['token_class'];
113+
}
114+
102115
/**
103116
* {@inheritdoc}
104117
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<b>Authenticated</b>
1919
<span class="sf-toolbar-status sf-toolbar-status-{{ authentication_color_code }}">{{ authentication_color_text }}</span>
2020
</div>
21+
{% if collector.tokenClass != null %}
22+
<div class="sf-toolbar-info-piece">
23+
<b>Token class</b>
24+
{{ collector.tokenClass|abbr_class }}
25+
</div>
26+
{% endif %}
2127
{% elseif collector.enabled %}
2228
You are not authenticated.
2329
{% else %}
@@ -61,6 +67,12 @@
6167
<th>Roles</th>
6268
<td>{{ collector.roles|yaml_encode }}</td>
6369
</tr>
70+
{% if collector.tokenClass != null %}
71+
<tr>
72+
<th>Token class</th>
73+
<td>{{ collector.tokenClass }}</td>
74+
</tr>
75+
{% endif %}
6476
</table>
6577
{% elseif collector.enabled %}
6678
<p>

0 commit comments

Comments
 (0)
0