3 namespace Wallabag\ApiBundle\Controller
;
5 use FOS\RestBundle\Controller\FOSRestController
;
6 use Symfony\Component\Security\Core\Exception\AccessDeniedException
;
7 use Wallabag\CoreBundle\Entity\Entry
;
8 use Nelmio\ApiDocBundle\Annotation\ApiDoc
;
9 use Symfony\Component\HttpFoundation\JsonResponse
;
11 class WallabagRestController
extends FOSRestController
14 * Retrieve version number.
18 * @return JsonResponse
20 public function getVersionAction()
22 $version = $this->container
->getParameter('wallabag_core.version');
23 $json = $this->get('serializer')->serialize($version, 'json');
25 return (new JsonResponse())->setJson($json);
28 protected function validateAuthentication()
30 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
31 throw new AccessDeniedException();
36 * Validate that the first id is equal to the second one.
37 * If not, throw exception. It means a user try to access information from an other user.
39 * @param int $requestUserId User id from the requested source
41 protected function validateUserAccess($requestUserId)
43 $user = $this->get('security.token_storage')->getToken()->getUser();
44 if ($requestUserId != $user->getId()) {
45 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId());