title: Symfony2 - Redirect response from request EventListener in dev mode while ignoring built in request events
body: <p>I am building my own user management system in Symfony2 (not using FOSUserBundle) and want to be able to force users to change their password.</p>
  
  <p>I have setup an EventListener to listen to the <code>kernal.request</code> event, then I perform some logic in the listener to determine if the user needs to change their password; if they do, then they are redirected to a "Change Password" route.</p>
  
  <p>I add the service to my <code>config.yml</code> to listen on the <code>kernal.request</code>:</p>
  
  <pre><code>password_change_listener:
      class: Acme\AdminBundle\EventListener\PasswordChangeListener
          arguments: [ @service_container ]
          tags:
              - { name: kernel.event_listener, event: kernel.request, method: onMustChangepasswordEvent }
  </code></pre>
  
  <p>And then the listener:</p>
  
  <pre><code>public function onMustChangepasswordEvent(GetResponseEvent $event) {
  
    $securityContext = $this-&gt;container-&gt;get('security.context');
  
    // if not logged in, no need to change password
    if ( !$securityContext-&gt;isGranted('IS_AUTHENTICATED_REMEMBERED') )
      return;
  
    // If already on the change_password page, no need to change password
    $changePasswordRoute = 'change_password';
    $_route  = $event-&gt;getRequest()-&gt;get('_route');
    if ($changePasswordRoute == $_route)
      return;
  
    // Check the user object to see if user needs to change password
    $user = $this-&gt;getUser();
    if (!$user-&gt;getMustChangePassword())
      return;
  
    // If still here, redirect to the change password page
    $url = $this-&gt;container-&gt;get('router')-&gt;generate($changePasswordRoute);
    $response = new RedirectResponse($url);
    $event-&gt;setResponse($response);
  }
  </code></pre>
  
  <p>The problem I am having is that in dev mode, my listener is also redirecting the profiler bar and assetic request events. It works when I dump assets and clear cache and view the site in production mode.</p>
  
  <p>Is there a way I can ignore the events from assetic/profiler bar/any other internal controllers? Or a better way to redirect a user to the change_password page (not only on login success)?</p>
  
  <p>Going crazy thinking up wild hack solutions, but surely there is a way to handle this elegantly in Symfony2?</p>