3 namespace Wallabag\ApiBundle\Controller
;
5 use FOS\RestBundle\Controller\FOSRestController
;
6 use Nelmio\ApiDocBundle\Annotation\ApiDoc
;
7 use Symfony\Component\HttpFoundation\JsonResponse
;
8 use Symfony\Component\Security\Core\Exception\AccessDeniedException
;
10 class WallabagRestController
extends FOSRestController
13 * Retrieve version number.
17 * @deprecated Should use info endpoint instead
19 * @return JsonResponse
21 public function getVersionAction()
23 $version = $this->container
->getParameter('wallabag_core.version');
24 $json = $this->get('jms_serializer')->serialize($version, 'json');
26 return (new JsonResponse())->setJson($json);
30 * Retrieve information about the wallabag instance.
34 * @return JsonResponse
36 public function getInfoAction()
39 'appname' => 'wallabag',
40 'version' => $this->container
->getParameter('wallabag_core.version'),
41 'allowed_registration' => $this->container
->getParameter('wallabag_user.registration_enabled'),
44 return (new JsonResponse())->setJson($this->get('jms_serializer')->serialize($info, 'json'));
47 protected function validateAuthentication()
49 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
50 throw new AccessDeniedException();
55 * Validate that the first id is equal to the second one.
56 * If not, throw exception. It means a user try to access information from an other user.
58 * @param int $requestUserId User id from the requested source
60 protected function validateUserAccess($requestUserId)
62 $user = $this->get('security.token_storage')->getToken()->getUser();
63 if ($requestUserId !== $user->getId()) {
64 throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId());