title: How can I throw a 403 exception in Symfony2?
body: <p>I am doing a check if there is a specific token in my request URI and throw a <code>Symfony\Component\Security\Core\Exception\AccessDeniedException</code> if there is no token or the token is wrong.</p>
  
  <pre><code>if(!isset($token) &amp;&amp; $token != 'whatever') {
    throw new AccessDeniedException('No token given or token is wrong.');
  }
  </code></pre>
  
  <p>But when I use this <code>AccessDeniedException</code>, Symfony2 simply redirects to the login page. Instead, I would like to have a dedicated 403 error page (I already created <code>app/Resources/TwigBundle/views/Exceptions/error403.html.twig</code> file).</p>
  
  <p>What would I have to change in order to achieve this? Do I have to use a PHP native Exception? But how can I tell to pass a 403 error code?</p>
  
  <p>Does Symfony2 maybe have a specific 403-Exception which doesn't simply redirect to login?</p>