title: this->getUser() returns null after validating Form
body: <p>I'm building a form with customized option based on who is logged in.
  The goal is to send an Invitation.</p>
  
  <p>The kind of invitation you can send is determined by the getIsRefFrom() method (which is a method available for "User" objects.)</p>
  
  <p>Here is my Controller</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use AppBundle\Entity\Invitation;
  use AppBundle\Form\InvitationType;
  use AppBundle\Entity\User;
  use Symfony\Component\HttpFoundation\Response;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  
  /**
   * Invitation controller.
   *
   * @Route("/private/invitation")
   */
  class InvitationController extends Controller 
  {
  ...
      public function newAction(Request $request)
      {
  
          $invitation = new Invitation();
          $user = $this-&gt;getUser();
          $userStruct = $user-&gt;getIsRefFrom();
          $form = $this-&gt;createForm('AppBundle\Form\InvitationType', $invitation, array('userStruct' =&gt; $userStruct));         
  
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {     
  
              return new Response("&lt;body&gt;Hi&lt;/body&gt;");
  
          }
  
          return $this-&gt;render('invitation/new.html.twig', array(
              'invitation' =&gt; $invitation,
              'form' =&gt; $form-&gt;createView(),
          ));
      }
  
  ...
  }
  </code></pre>
  
  <p>And here is my Form Type</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  
  class InvitationType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {       
  
          $builder
               //showing content of userStruct in a select field
              -&gt;add('structure', EntityType::class,  array(
                      'label' =&gt; 'Structure:',
                      'class' =&gt; 'AppBundle:Structure',
                      'choices' =&gt; $options['userStruct'],
                      'placeholder' =&gt; 'Faites un choix',
                      'property' =&gt; 'libelle',
                      'mapped' =&gt; false
              ))
  
  
          -&gt;add('destinataire');
      }
  
      /**
       * @param OptionsResolver $resolver
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'AppBundle\Entity\Invitation',
              'userStruct' =&gt; 'AppBundle\Entity\Structure',
          ));
      }
  }
  </code></pre>
  
  <p>The form displays OK, $this->getUser() returns my user, and the content of $user->getIsRefFrom() is correctly displayed in the form.</p>
  
  <p>Moreover, the debug toolbar indicates that I am correctly logged in, as I fill in the form.</p>
  
  <p>But when I <strike>validate</strike> submit the form, I get an error saying "Error: Call to a member function getIsRefFrom() on null " because obviously $this->getUser(); is now null. </p>
  
  <p>The debug toolbar now indicates n/a (not logged in, no security context...)</p>
  
  <p>It looks like the security context is not available at this point.</p>
  
  <p>More info :</p>
  
  <ul>
  <li>I use be_simple_sso_auth (cas auth bundle). </li>
  <li>I have only one firewall (derriere_CAS), which covers the whole app, except login page which are enabled via ACL (see security.yml below)</li>
  <li>Authentication works fine.</li>
  </ul>
  
  <p>Here is my security.yml</p>
  
  <pre><code>security:
    encoders:
      AppBundle\Entity\User: 
        algorithm: bcrypt
  
    role_hierarchy:
          ROLE_ADMIN: [ROLE_USER]
  
    providers:
      users:
        entity: {class: AppBundle\Entity\User, property: username } 
  
  
  
    firewalls:
          # disables authentication for assets and the profiler, adapt it according to your needs
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
  
          derriere_CAS:
              methods: GET
              pattern: ^/
              anonymous: ~
              trusted_sso:
                manager: connect_sso 
                login_path: /private/login/
                check_path: /private/login/check
                login_action: false
                logout_action: false
                create_users: true
                created_users_roles: [ 'ROLE_USER' ]
                failure_path: /erreur_identification
              logout:
                path: /logout_sso
                target: /
  
    access_control:
        - { path: ^/private/login, role: IS_AUTHENTICATED_ANONYMOUSLY } 
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }  
  </code></pre>
  
  <p>Maybe I'm doing something wrong.
  I would appreciate any help or idea.
  Thank you.</p>