title: Tell whether route is behind firewall in Symfony2
body: <p>I'm currently writing an event listener in Symfony2, which listens for the <code>kernel.response</code> event, and adds a cookie to it if: a) a user is logged in, and b) no such cookie currently exists. It takes the service container as an argument. </p>
  
  <p>However, I'm getting an error when the listener responds to events not behind a firewall (such as those in the dev toolbar) since the token is empty and an <code>AuthenticationCredentialsNotFoundException</code> is thrown. However, I can't for the life of me figure out how to tell whether the route is behind a firewall or not. Could anyone help?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public function onKernelResponse(FilterResponseEvent $event) {
      // does the request have a device cookie?
      if ($this-&gt;container-&gt;get('security.authorization_checker')-&gt;isGranted('IS_AUTHENTICATED_FULLY')
          &amp;&amp; !$this-&gt;getRequest()-&gt;cookies-&gt;has(DeviceManager::COOKIE_PREFIX.'id')) {
          // no. Create one.
          $DeviceManager          =   $this-&gt;container-&gt;get('salus_user.device_manager');
          $Cookie                 =   $DeviceManager-&gt;createDeviceCookie();
          $Response               =   $event-&gt;getResponse();
          $Response-&gt;headers-&gt;setCookie($Cookie); // and save it
      }
      // else, yes, we don't need to do anything
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>AuthenticationCredentialsNotFoundException in classes.php line 2888:
  
  The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.
  </code></pre>