title: How to get 403 HTTP_FORBIDDEN in REST request?
body: <p>The FOSRestBundle is working perfectly in my project but without authentification. Now, my goal is to make my requests with auth.</p>
  
  <p>To do so, I added this firewall in security.yml</p>
  
  <pre><code>firewalls:
      # ...    
      rest_api:
          pattern: ^/api/
          stateless: true
          http_basic:
              provider: fos_userbundle
      # ...    
  access_control:
      # ...    
      - { path: ^/api/, role: IS_AUTHENTICATED_FULLY }
  </code></pre>
  
  <p>To check this, I used this shell command: </p>
  
  <pre><code>curl -i http://localhost/tuto/web/app_dev.php/api/test/1
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>HTTP/1.1 302 Found
  Date: Fri, 11 Apr 2014 13:56:08 GMT
  Server: Apache/2.2.22 (Ubuntu)
  X-Powered-By: PHP/5.4.9-4ubuntu2.4
  Set-Cookie: PHPSESSID=4dtr168vmj1eg523a07kbkjkh1; path=/
  Cache-Control: no-cache
  Location: http://localhost/tuto/web/app_dev.php/login
  Vary: Accept-Language
  X-Debug-Token: 220df7
  Transfer-Encoding: chunked
  Content-Type: application/json
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
          &lt;meta http-equiv="refresh" content="1;url=http://localhost/tuto/web/app_dev.php/login" /&gt;
  
          &lt;title&gt;Redirecting to http://localhost/tuto/web/app_dev.php/login&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          Redirecting to &lt;a href="http://localhost/tuto/web/app_dev.php/login"&gt;http://localhost/tuto/web/app_dev.php/login&lt;/a&gt;.
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As you can see, the returned code is 302 FOUND since it is URL is redirected to <code>http://localhost/tuto/web/app_dev.php/login</code> as I am using FOSUserBundle.</p>
  
  <p>This is strange since I defined my action() method as follows:</p>
  
  <pre><code>/**
   * @Rest\View
   * @Rest\Get("/api/test/{id}",
   *      requirements={"id" = "\d+"},
   *      defaults={"id" = 1}
   * )
   */
  public function getAction($id) {
      $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
      if(!($user instanceof \Minn\UserBundle\Entity\User)){
          throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException();
      }
      $repo = $this-&gt;getDoctrine()-&gt;
              getManager()-&gt;
              getRepository("MinnAdsAPIBundle:Test");
      $entity = $repo-&gt;find($id);
      if (!$entity) {
          throw $this-&gt;createNotFoundException('Unable to find test entity!');
      }
      return array('test' =&gt; $entity);
  }
  </code></pre>
  
  <p>So, is there any idea to fix my action() method?</p>
  
  <p>Thanks.</p>
  
  <p>By the way, what is the shell command to check my action with authentification?</p>
  
  <p>I tried this command <code>curl -i http://localhost/tuto/web/app_dev.php/api/test/1 --user user:password</code> but still I have 302 FOUND.</p>