]>
Commit | Line | Data |
---|---|---|
f8bf8952 NL |
1 | <?php |
2 | ||
769e19dc | 3 | namespace Wallabag\ApiBundle\Controller; |
f8bf8952 | 4 | |
fcb1fba5 | 5 | use FOS\RestBundle\Controller\FOSRestController; |
864c1dd2 JB |
6 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | |
001cc716 | 8 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
f8bf8952 | 9 | |
fcb1fba5 | 10 | class 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'); | |
2b477030 | 22 | $json = $this->get('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(); |
fcb1fba5 NL |
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 | } |