title: How to force user logout symfony2
body: <p>I want to force a user to logout in symfony2 after checking that it has not enough capabilities for access into a specific secured area.</p>
  
  <p>I've tried with :</p>
  
  <pre><code>$this-&gt;get('request')-&gt;getSession()-&gt;invalidate();
  </code></pre>
  
  <p>but it seems that something goes wrong, the user still logged in until I logged him out using /logout route.</p>
  
  <p>I've to mention that I'm using KayueWordpressBundle to connect my symfony app with a wordpress based website to create a custom back office.</p>
  
  <p>Here is my security.yml file </p>
  
  <pre><code>security:
  firewalls:
      dev:
          pattern:  ^/(_(profiler|wdt)|css|images|js)/
          security: false
      login_firewall:
          pattern:    ^/$
          anonymous:  ~
      secured_area:
          pattern:    ^/
          kayue_wordpress: ~
          form_login:
              check_path: /login_check
              login_path: /
          logout:
              path:   /logout
              target: /
  access_control:
      - { path: ^/admin, roles: ROLE_ADMIN }
  
  providers:
      wordpress:
          entity: { class: Kayue\WordpressBundle\Entity\User, property: username }
  
  encoders:
      Kayue\WordpressBundle\Entity\User:
          id: kayue_wordpress.security.encoder.phpass
  </code></pre>
  
  <p>How can I do this please ?</p>
  
  <p>Thank you </p>