title: Empty User Object from Symfony after login
body: <p>I created a login page with Symfony and Twig. Now, I'm trying to retrieve the Username after the login. But it seems, that the User Object which I return from my SecurityController is empty and so Twig has a rendering problem. What do I need to do to get that UserObject? </p>
  
  <p><strong>security.yml</strong></p>
  
  <pre><code>security:
  
      encoders:
          UserBundle\Entity\User:
              algorithm: bcrypt
  
      providers:
          in_memory:
              memory: ~
  
          user_db_provider:
              entity:
                  class: UserBundle:User
                  property: username
  
      firewalls:
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
  
          main:
              anonymous: ~
  
              http_basic: ~
              provider: user_db_provider
  
              form_login:
                  login_path: /login
                  check_path: /login_check
  
              logout:
                  path: /logout
                  target: /
  </code></pre>
  
  <p><strong>SecurityController</strong></p>
  
  <p>class SecurityController extends Controller{</p>
  
  <pre><code>    /**
       * @Route("/login", name="login_form")
       */
      public function loginAction(){
  
          $authenticationUtils = $this-&gt;get('security.authentication_utils');
          $error = $authenticationUtils-&gt;getLastAuthenticationError();
  
          $user = $this-&gt;getUser();
  
  
          return $this-&gt;render(':security:login.html.twig',
                  array(
                          'user' =&gt; $user,
                          'error'=&gt; $error,
                  )
          );
      }
  
  /**
   * @Route("/login_check", name="login_check")
   */
  public function loginCheckAction() {}
  
  /**
   * @Route ("/logout", name="logout")
   */
  public function logoutAction(){}}
  </code></pre>
  
  <p><strong>User</strong> (Serialize, getter/setter methods are implemented)</p>
  
  <pre><code>/**
   * @Table("users")
   * @Entity
   */
  class User implements UserInterface, \Serializable {
  
          /**
           * @Column(name="id", type="integer")
           * @Id
           * @GeneratedValue(strategy="AUTO")
           */
          private $id;
  
          /**
           * @Column(length=25)
           */
          private $username;
  
          /**
           * @Column(length=64)
           */
          private $password;
  
          /**
           * @var array
           * @Column(name="roles", type="json_array")
           */
          private $roles = array();
  </code></pre>
  
  <p>Twig-Template</p>
  
  <pre><code>    {% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
      &lt;div class="form-group"&gt;
          {{ user.username }}
          &lt;a href="{{ path('logout') }}"&gt;Logout&lt;/a&gt;
      &lt;/div&gt;
  {% else %}
  &lt;form class="navbar-form navbar-left" action="{{ path('login_check') }}" method="post"&gt;
      &lt;div class="form-group"&gt;
          &lt;input type="text" class="form-control" name="_username" placeholder="Username"/&gt;
          &lt;input type="password" class="form-control" name="_password" placeholder="Password"/&gt;
          &lt;button type="submit" class="btn btn-default"&gt;Log In&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  {% endif %}
  {% if error is defined %}
  &lt;p class="navbar-text navbar-right"&gt;{{ error.messageKey|trans(error.messageData, 'security')}}&lt;/p&gt;
  {% endif %}
  </code></pre>