diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig.html b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig.html index 9221d12c1ebc..4d37492c57fb 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig.html +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig.html @@ -18,4 +18,12 @@ {% block panel %}

Security

+ {% if collector.authenticated %} + {{ collector.user }}
+ Roles: {{ collector.roles|yaml_encode }} + {% elseif collector.enabled %} + No token. + {% else %} + The security component is disabled. + {% endif %} {% endblock %} diff --git a/src/Symfony/Component/HttpKernel/DataCollector/SecurityDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/SecurityDataCollector.php index cf89f691aaee..4166dd06045d 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/SecurityDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/SecurityDataCollector.php @@ -39,18 +39,21 @@ public function collect(Request $request, Response $response, \Exception $except 'enabled' => false, 'authenticated' => false, 'user' => '', + 'roles' => array(), ); } elseif (null === $token = $this->context->getToken()) { $this->data = array( 'enabled' => true, 'authenticated' => false, 'user' => '', + 'roles' => array(), ); } else { $this->data = array( 'enabled' => true, 'authenticated' => $token->isAuthenticated(), 'user' => (string) $token->getUser(), + 'roles' => array_map(function ($role){ return $role->getRole();}, $token->getRoles()), ); } } @@ -75,6 +78,16 @@ public function getUser() return $this->data['user']; } + /** + * Gets the roles of the user. + * + * @return array The roles + */ + public function getRoles() + { + return $this->data['roles']; + } + /** * Checks if the user is authenticated or not. *