title: onAuthenticationSuccess redirectresponse to login
body: <p>Its on symfony 2.8, i'm trying to use an API and even though i'm entering the onAuthenticationSuccess method after filling the rights parameters, the redirection always goes to the login page and so, doesnt do the job.</p>
  
  <p>I think its a security issue or a route issue but my knowledge is limited.</p>
  
  <p>here is the function i'm entering before being redirected: </p>
  
  <pre><code>/**
   * {@inheritdoc}
   *
   * @throws InvalidParameterException
   * @throws MissingMandatoryParametersException
   * @throws RouteNotFoundException
   * @throws ServiceCircularReferenceException
   * @throws ServiceNotFoundException
   * @throws InitializeDataStudioException
   * @throws DBALException
   * @throws ORMInvalidArgumentException
   * @throws OptimisticLockException
   * @throws \InvalidArgumentException
   * @throws \Exception
   */
  
  public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
  {
      if ($request-&gt;getMethod() === 'POST') {
          return null;
      }
  
      $route = $request-&gt;get('_route');
      $request-&gt;query-&gt;remove('boid');
      $request-&gt;query-&gt;remove('uid');
      $request-&gt;query-&gt;remove('securityString');
      $request-&gt;query-&gt;remove('sessid');
      $parameters = array_merge($request-&gt;query-&gt;all(), $request-&gt;attributes-&gt;all());
      $url = $this-&gt;router-&gt;generate($route, $parameters);
  
      /** @var DatabaseManager $dbManager */
      $dbManager = $this-&gt;container-&gt;get('app.database.manager');
  
      if ($dbManager-&gt;getListUniqueKey() !== null) {
          /** @var ExistingDataLoader $dataLoader */
          $dataLoader = $this-&gt;container-&gt;get('app.database.loader.existing_data');
          /** @var EntityManager $em */
          $em = $this-&gt;container-&gt;get('doctrine')-&gt;getManager('default');
          /** @var CustomTable $listTable */
          $listTable = $em-&gt;getRepository('AppBundle:CustomTable')-&gt;findOneBy(['type' =&gt; Table::TYPE_LIST]);
  
          $dataLoader-&gt;load($listTable);
      }
  
      return new RedirectResponse($url);
  }
  </code></pre>
  
  <p>I'm being redirected to another route then to the login page.</p>
  
  <p>security.yml :</p>
  
  <h1>To get started with security, check out the documentation:</h1>
  
  <h1><a href="http://symfony.com/doc/current/book/security.html" rel="nofollow noreferrer">http://symfony.com/doc/current/book/security.html</a></h1>
  
  <p>security:</p>
  
  <pre><code># http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
  providers:
      ds_provider:
          id: app.security.dynamic_user_provider
  
  firewalls:
      # disables authentication for assets and the profiler, adapt it according to your needs
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
  
      main:
          anonymous: ~
          logout:
              path: /logout
              target: /
          guard:
              authenticators:
                  - app.security.token_authenticator
          # activate different ways to authenticate
  
          # http_basic: ~
          # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
  
          # form_login: ~
          # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
  
  access_control:
      - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/data-studio, roles: ROLE_SUPER_ADMIN }
  </code></pre>
  
  <p>the routes i'm trying to access : </p>
  
  <p>data-studio/api/calculated-fields/2/edit?dailyUpdate=1&amp;dailyUpdateTime=01:00&amp;boid=xxx&amp;uid=xxx&amp;securityString=xxxxxxxxx&amp;sessid=xxxxxxxxx</p>
  
  <p>redirecting to : </p>
  
  <p>/data-studio/api/calculated-fields/2/edit?dailyUpdate=1&amp;dailyUpdateTime=01%3A00&amp;_route=api_calculated_field_edit&amp;_route_params%5Bid%5D=2</p>
  
  <p>then :</p>
  
  <p>/login</p>
  
  <hr>
  
  <p>When entering onAuthenticationSuccess i dump the token and i can see that i'm correctly authenticated with the role "ROLE_SUPER_ADMIN" :</p>
  
  <pre><code>  ["roles":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=&gt;
    array(1) {
      [0]=&gt;
      object(Symfony\Component\Security\Core\Role\Role)#375 (1) {
        ["role":"Symfony\Component\Security\Core\Role\Role":private]=&gt;
        string(16) "ROLE_SUPER_ADMIN"
      }
    }
    ["authenticated":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=&gt;
    bool(true)
    ["attributes":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=&gt;
    array(0) {
    }
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Cheers</p>