From 15c52f507eeb2131a7c6c4e2c6cbb237d86b74fd Mon Sep 17 00:00:00 2001 From: Lee McDermott Date: Thu, 20 Dec 2012 06:23:44 +0000 Subject: [PATCH] Show class name of security token in WDT --- .../DataCollector/SecurityDataCollector.php | 15 +++++++++++++++ .../Resources/views/Collector/security.html.twig | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php b/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php index 609f8db31a71..696c70d2e448 100644 --- a/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php +++ b/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php @@ -39,6 +39,7 @@ public function collect(Request $request, Response $response, \Exception $except $this->data = array( 'enabled' => false, 'authenticated' => false, + 'token_class' => null, 'user' => '', 'roles' => array(), ); @@ -46,13 +47,17 @@ public function collect(Request $request, Response $response, \Exception $except $this->data = array( 'enabled' => true, 'authenticated' => false, + 'token_class' => null, 'user' => '', 'roles' => array(), ); } else { + $class = explode('\\', get_class($token)); + $this->data = array( 'enabled' => true, 'authenticated' => $token->isAuthenticated(), + 'token_class' => end($class), 'user' => $token->getUsername(), 'roles' => array_map(function ($role){ return $role->getRole();}, $token->getRoles()), ); @@ -99,6 +104,16 @@ public function isAuthenticated() return $this->data['authenticated']; } + /** + * Get the class name of the security token (without namespace). + * + * @return String The token + */ + public function getTokenClass() + { + return $this->data['token_class']; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig index 730436b2d526..08d0a7747d91 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig +++ b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig @@ -18,6 +18,12 @@ Authenticated {{ authentication_color_text }} + {% if collector.tokenClass != null %} +
+ Token class + {{ collector.tokenClass }} +
+ {% endif %} {% elseif collector.enabled %} You are not authenticated. {% else %} @@ -61,6 +67,12 @@ Roles {{ collector.roles|yaml_encode }} + {% if collector.tokenClass != null %} + + Token class + {{ collector.tokenClass }} + + {% endif %} {% elseif collector.enabled %}