private function logAccessToken(ActionLog $log, TokenInterface $token)
 {
     if (!$token instanceof OAuthToken) {
         return;
     }
     $accessTokenRepo = $this->em->getRepository('LoginCidadaoOAuthBundle:AccessToken');
     $accessToken = $accessTokenRepo->findOneBy(array('token' => $token->getToken()));
     $log->setAccessToken($token->getToken());
     $log->setClientId($accessToken->getClient()->getId());
     $log->setUserId($accessToken->getUser()->getId());
 }
 /**
  *
  * @param ActionLog $log
  * @return ImpersonationReport | RedirectResponse
  * @throws AccessDeniedException
  */
 private function getNewReport(ActionLog $log)
 {
     $reportRepo = $this->getDoctrine()->getRepository('LoginCidadaoCoreBundle:ImpersonationReport');
     $personRepo = $this->getDoctrine()->getRepository('LoginCidadaoCoreBundle:Person');
     $report = new ImpersonationReport();
     $existingReport = $reportRepo->findOneBy(array('actionLog' => $log));
     if ($existingReport instanceof ImpersonationReport) {
         $this->addFlash('error', "This action was already reported.");
         return $this->redirectToRoute('lc_admin_impersonation_report_index');
     }
     $impersonatorId = $log->getClientId();
     if ($impersonatorId !== $this->getUser()->getId()) {
         throw $this->createAccessDeniedException("You cannot fill other person's report!");
     }
     $targetUser = $personRepo->find($log->getUserId());
     $report->setTarget($targetUser)->setActionLog($log);
     return $report;
 }