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
;
9 class WallabagRestController
extends FOSRestController
12 * Retrieve version number.
16 * @return JsonResponse
18 public function getVersionAction()
20 $version = $this->container
->getParameter('wallabag_core.version');
21 $json = $this->get('serializer')->serialize($version, 'json');
22 return (new JsonResponse())->setJson($json);
25 protected function validateAuthentication()
27 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
28 throw new AccessDeniedException();
33 * Validate that the first id is equal to the second one.
34 * If not, throw exception. It means a user try to access information from an other user.
36 * @param int $requestUserId User id from the requested source
38 protected function validateUserAccess($requestUserId)
40 $user = $this->get('security.token_storage')->getToken()->getUser();
41 if ($requestUserId != $user->getId()) {
42 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId());