瀏覽代碼

Added the roles in the Security panel of the profiler

Christophe Coevoet 14 年之前
父節點
當前提交
105d5918bc

+ 8 - 0
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig.html

@@ -18,4 +18,12 @@ Security
 
 {% block panel %}
     <h2>Security</h2>
+    {% if collector.authenticated %}
+        <strong>{{ collector.user }}</strong><br />
+        <strong>Roles</strong>: {{ collector.roles|yaml_encode }}
+    {% elseif collector.enabled %}
+        <em>No token.</em>
+    {% else %}
+        <em>The security component is disabled.</em>
+    {% endif %}
 {% endblock %}

+ 13 - 0
src/Symfony/Component/HttpKernel/DataCollector/SecurityDataCollector.php

@@ -39,18 +39,21 @@ class SecurityDataCollector extends DataCollector
                 '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 @@ class SecurityDataCollector extends DataCollector
         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.
      *