/**
  * Hook into the kernel process.
  *
  * @param FilterResponseEvent $event
  */
 public function onResponseFilter(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     if ($this->isProperRequest($request, $response)) {
         $apiKey = $this->extractApiKeyFromResponse($response);
         $user = $this->userRepository->findOneBy(['apiKey' => $apiKey]);
         if (!$user) {
             throw new \InvalidArgumentException(sprintf('Cannot find user for api key "%s"!', $apiKey));
         }
         $this->fixCookie($user, $request, $response);
     }
 }
 /**
  * Attempts to load a user by its activation key and username.
  *
  * @param string $activationKey
  * @param string $username
  *
  * @return User
  */
 private function findUserByActivationKeyAndUsername($activationKey, $username)
 {
     if (!($user = $this->userRepository->findUserByUsernameAndActivationKey($username, $activationKey))) {
         throw $this->createActivationException();
     } elseif ($this->isActivationExpired($user)) {
         $this->entityManager->remove($user);
         $this->entityManager->flush($user);
         throw $this->createActivationException();
     }
     return $user;
 }