public function testHandleWithASimilarAuthenticatedToken()
 {
     $request = new Request(array(), array(), array(), array(), array(), array('PHP_AUTH_USER' => 'TheUsername'));
     $token = new UsernamePasswordToken('TheUsername', 'ThePassword', 'TheProviderKey', array('ROLE_FOO'));
     $context = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $context->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $authenticationManager = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface');
     $authenticationManager->expects($this->never())->method('authenticate');
     $listener = new BasicAuthenticationListener($context, $authenticationManager, 'TheProviderKey', $this->getMock('Symfony\\Component\\Security\\Http\\EntryPoint\\AuthenticationEntryPointInterface'));
     $event = $this->getMock('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent', array(), array(), '', false);
     $event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $listener->handle($event);
 }
 /**
  * @param GetResponseEvent $event
  */
 public function handle(GetResponseEvent $event)
 {
     parent::handle($event);
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($session->has('requested_logout')) {
         $session->invalidate();
         $this->securityTokenStorage->setToken(null);
         $event->setResponse($this->authenticationEntryPoint->start($request));
     }
 }
 public function testHandleWithADifferentAuthenticatedToken()
 {
     $request = new Request(array(), array(), array(), array(), array(), array('PHP_AUTH_USER' => 'TheUsername', 'PHP_AUTH_PW' => 'ThePassword'));
     $token = new PreAuthenticatedToken('TheUser', 'TheCredentials', 'TheProviderKey', array('ROLE_FOO'));
     $tokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface')->getMock();
     $tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $tokenStorage->expects($this->never())->method('setToken');
     $response = new Response();
     $authenticationEntryPoint = $this->getMockBuilder('Symfony\\Component\\Security\\Http\\EntryPoint\\AuthenticationEntryPointInterface')->getMock();
     $authenticationEntryPoint->expects($this->any())->method('start')->with($this->equalTo($request), $this->isInstanceOf('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException'))->will($this->returnValue($response));
     $listener = new BasicAuthenticationListener($tokenStorage, new AuthenticationProviderManager(array($this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Provider\\AuthenticationProviderInterface')->getMock())), 'TheProviderKey', $authenticationEntryPoint);
     $event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $event->expects($this->once())->method('setResponse')->with($this->equalTo($response));
     $listener->handle($event);
 }