/**
  * Performs authentication if cookie is present.
  *
  * @param GetResponseEvent $event
  *
  * @return bool|\ONGR\SettingsBundle\Security\Authentication\Token\SessionlessToken
  */
 private function authenticateCookie(GetResponseEvent $event)
 {
     $cookieData = $this->authCookie->getValue();
     if ($cookieData !== null) {
         if (!$this->authCookieService->validateCookie($cookieData)) {
             return false;
         }
         $token = new SessionlessToken($cookieData['username'], $cookieData['expiration'], $event->getRequest()->getClientIp(), $cookieData['signature']);
         try {
             $authenticatedToken = $this->authenticationProvider->authenticate($token);
         } catch (AuthenticationException $e) {
             return false;
         }
         return $authenticatedToken;
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(GetResponseEvent $event)
 {
     $cookieData = $this->cookie->getValue();
     if (!$this->authCookieService->validateCookie($cookieData)) {
         $this->tokenStorage->setToken(null);
         return false;
     }
     $token = new SessionlessToken($cookieData['username'], $cookieData['expiration'], $event->getRequest()->getClientIp(), $cookieData['signature']);
     try {
         $regeneratedToken = $this->authenticationManager->authenticate($token);
         $this->tokenStorage->setToken($regeneratedToken);
     } catch (AuthenticationException $e) {
         $this->cookie->setClear(true);
         $this->tokenStorage->setToken(null);
         return false;
     }
     return $regeneratedToken;
 }
 /**
  * Validate that validation is correct.
  *
  * @param array $value
  * @param array $expectedResult
  *
  * @dataProvider getValidateCookieCases()
  */
 public function testValidateCookie($value, $expectedResult)
 {
     $this->assertSame($expectedResult, $this->service->validateCookie($value));
 }