/**
  * Get current user info.
  *
  * @return null|array
  */
 private function getUserData()
 {
     if (null === $this->tokenStorage) {
         return null;
     }
     if ($this->tokenStorage->getToken() && $this->tokenStorage->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $userData = array();
         $user = $this->tokenStorage->getToken()->getUser();
         if (!$user) {
             return null;
         }
         if (method_exists($user, 'getId')) {
             $userData['id'] = $user->getId();
         } else {
             // id is required
             $userData['id'] = $user->getUsername();
         }
         $userData['username'] = $user->getUsername();
         if (method_exists($user, 'getEmail')) {
             $userData['email'] = $user->getEmail();
         }
         return $userData;
     }
     return null;
 }
 /**
  * Gets the resource if the current user is granted and if the resource exists.
  *
  * @param string $resourceId The resource id
  * @param string $grant      The grant, by default is view
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  *
  * @return Object
  */
 protected function getResourceIfAllowed($resourceId, $grant = 'view')
 {
     $resource = $this->repository->find($resourceId, false);
     if (!$this->context->isGranted($grant, $resource)) {
         throw new AccessDeniedException();
     }
     return $resource;
 }
 public function configureOptions(OptionsResolver $resolver)
 {
     if ($this->authorizationChecker instanceof AuthorizationCheckerInterface) {
         if (!$this->tokenStorage->getToken()) {
             return;
         }
         if (!$this->authorizationChecker->isGranted($this->role)) {
             return;
         }
     } else {
         if (!$this->tokenStorage->getToken()) {
             return;
         }
         if (!$this->tokenStorage->isGranted($this->role)) {
             return;
         }
     }
     $resolver->setDefaults(array('csrf_protection' => false));
 }
 /**
  * isViewable
  *
  * @param mixed $entity
  *
  * @return bool
  */
 public function isViewable($entity)
 {
     $editPermission = $entity instanceof Document ? 'DOCUMENT_EDIT' : 'NODE_EDIT';
     return $this->securityContext->isGranted('VIEW', $entity) && ($this->securityContext->isGranted($editPermission, $entity) || $entity->isEnabled());
 }