/**
  * Get HTTP cookie for $model.
  *
  * @param CookieInterface $cookieModel
  * @param Request         $request
  *
  * @return array|null
  */
 protected function getHttpCookie(CookieInterface $cookieModel, Request $request)
 {
     $modelName = $cookieModel->getName();
     if (null === $request->cookies || !$request->cookies->has($modelName)) {
         return null;
     }
     $cookie = $request->cookies->get($modelName);
     return $cookie;
 }
 /**
  * Save messages from flash-bag service to flash-bag cookie.
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST !== $event->getRequestType() || $event->getRequest()->isXmlHttpRequest()) {
         return;
     }
     if (!$this->flashBagService->isDirty()) {
         return;
     }
     $messages = $this->flashBagService->all();
     $this->flashBagCookie->setValue($messages);
     $response = $event->getResponse();
     $response->headers->setCookie($this->flashBagCookie->toCookie());
 }
 /**
  * {@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;
 }