]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ApiBundle/Controller/WallabagRestController.php
Jump to Symfony 3.3 & update others deps
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / WallabagRestController.php
CommitLineData
f8bf8952
NL
1<?php
2
769e19dc 3namespace Wallabag\ApiBundle\Controller;
f8bf8952 4
fcb1fba5 5use FOS\RestBundle\Controller\FOSRestController;
864c1dd2
JB
6use Nelmio\ApiDocBundle\Annotation\ApiDoc;
7use Symfony\Component\HttpFoundation\JsonResponse;
001cc716 8use Symfony\Component\Security\Core\Exception\AccessDeniedException;
f8bf8952 9
fcb1fba5 10class WallabagRestController extends FOSRestController
f8bf8952 11{
2b477030 12 /**
6f8310b4
TC
13 * Retrieve version number.
14 *
15 * @ApiDoc()
2b477030 16 *
60faee00 17 * @return JsonResponse
2b477030
V
18 */
19 public function getVersionAction()
20 {
21 $version = $this->container->getParameter('wallabag_core.version');
f40c88eb 22 $json = $this->get('jms_serializer')->serialize($version, 'json');
864c1dd2 23
60faee00 24 return (new JsonResponse())->setJson($json);
2b477030 25 }
769e19dc 26
900c8448 27 protected function validateAuthentication()
ac8cf632 28 {
18f8f32f 29 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
77273253 30 throw new AccessDeniedException();
ac8cf632 31 }
ac8cf632
JB
32 }
33
769e19dc
J
34 /**
35 * Validate that the first id is equal to the second one.
4346a860 36 * If not, throw exception. It means a user try to access information from an other user.
769e19dc 37 *
4346a860 38 * @param int $requestUserId User id from the requested source
769e19dc 39 */
900c8448 40 protected function validateUserAccess($requestUserId)
769e19dc 41 {
18f8f32f 42 $user = $this->get('security.token_storage')->getToken()->getUser();
f808b016
JB
43 if ($requestUserId !== $user->getId()) {
44 throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId());
769e19dc
J
45 }
46 }
7df80cb3 47}