title: Symfony FOS user bundle - Switch User failed: "Username "*" does not exist."
body: <p>It really is what the headline states - I can't figure out why user switching isn't working.
  In my security.yml I have:</p>
  
  <pre><code>firewalls:
      # disables authentication for assets and the profiler, adapt it according to your needs
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
  
      main:
          pattern: ^/
          form_login:
              provider:                       fos_userbundle                  # using FOSUserBundle for user authentication
              check_path:                     fos_user_security_check
              login_path:                     fos_user_security_login
              csrf_token_generator:           security.csrf.token_manager     # CSRF token - can be changed?
              default_target_path:            default_logged_in_target        # default route to go to after login
  #                default_target_path:            fos_user_profile_show
              always_use_default_target_path: true                            # ignore the requested url and allways go to default route after login
          logout:
                path:                         fos_user_security_logout
                target:                       default_loged_out_target
  
          logout:       true
          anonymous:    true
          switch_user:  true
  </code></pre>
  
  <p>Calling the URL</p>
  
  <pre><code>[ProjectPath]/account?_switch_user=testuser
  </code></pre>
  
  <p>results in the error</p>
  
  <pre><code>Switch User failed: "Username "testuser" does not exist."
  </code></pre>
  
  <p>"testuser" however is a perfectly valid user and I can log in normaly with that user when logging in the standard way.
  The user I am logged in with when calling the URL with "_switch_user" does have the role "ROLE_ALLOWED_TO_SWITCH" - however this doesn't seem to be the problem.
  I am stuck here.
  Any hints are highly appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The stacktrace shows that in "SwitchUserListener.php" the call to</p>
  
  <pre><code>$this-&gt;tokenStorage-&gt;setToken($this-&gt;attemptSwitchUser($request));
  </code></pre>
  
  <p>fails and is catched resulting in the given error.</p>