title: Programmatically logout current user
body: <p>I am trying to programmatically logout the current user from inside a listener.
  I read <a href="https://stackoverflow.com/questions/8455398/symfony-2-logout-userinterfaceerasecredentials/8456507#8456507">here</a> that </p>
  
  <pre><code>$this-&gt;get('security.context')-&gt;setToken(null);
  $this-&gt;get('request')-&gt;getSession()-&gt;invalidate();
  </code></pre>
  
  <p>does the trick but then I can't call <code>$this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser();</code> anymore as the token is now <code>NULL</code>.</p>
  
  <p>How can I log out the user but still let the application run normally?
  I have calls to getUser() in my controller functions so I should set back the token to something corresponding to an non authenticated user. How can I do this?</p>
  
  <p>Also, if there is a way to programmatically start a new session and set a flash message to inform the user he has been logged out, it would be awesome.</p>