title: how to generate 403 error code in symfony before filter
body: <p>i'm trying to use the before filter of symfony 2.7 to do authentication. my event listener is as follows</p>
  
  <pre><code>class TokenListener {                                                                                                  
  protected $dm;                                                                                                     
  
  function __construct() {                                                                                           
  }                                                                                                                  
  public function setDocumentManager(DocumentManager $dm) {                                                          
      $this-&gt;dm = $dm;                                                                                               
  }                                                                                                                  
  
  public function onKernelController(FilterControllerEvent $event) {                                                 
      $controller = $event-&gt;getController();                                                                         
  
      if (!is_array($controller)) {                                                                                  
          return;                                                                                                    
      }                                                                                                              
  
      if ($controller[0] instanceof TokenAuthenticatedController) {                                                  
  
  
          $content = $event-&gt;getRequest()-&gt;getContent();                                                                                                                           
  
          $json = json_decode($content,true);                                                                        
          $authId = $json['authId'];                                                                                 
          $authToken = $json['authToken'];                                                                           
  
          echo "authId: {$authId}, authToken: {$authToken}\n";                                                       
  
          $user = $this-&gt;dm-&gt;getRepository('HcUserBundle:User')                                                      
              -&gt;createQueryBuilder()                                                                                 
              -&gt;field('authId')-&gt;equals($authId)                                                                      
              -&gt;getQuery()                                                                                           
              -&gt;getSingleResult();                                                                                   
  
  
          if (!isset($user) || $user-&gt;getAuthToken() != $authToken) {                                                
              throw new AccessDeniedException('This action needs a valid token!');                                   
          }                                                                                                         
      }                                                                                                              
  }                                                                                                                  
  }   
  </code></pre>
  
  <p>but i got 500 error, and symfony error log says </p>
  
  <blockquote>
    <p>Uncaught PHP Exception Symfony\Component\Security\Core\Exception\AccessDeniedException: "This action needs a valid token!"</p>
  </blockquote>
  
  <p>instead of getting a 403 error, I also tried to use the <code>AccessDeniedHttpException</code> and have the same problem, does anyone know how to generate a 403 response here? Thanks</p>