From 769e19dc4ab1a068e8165a7b237f42a78a6d312f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 29 Mar 2015 10:53:10 +0200 Subject: Move API stuff in ApiBundle --- .../Controller/WallabagRestController.php | 370 +++++++++++++++++++ .../DependencyInjection/Configuration.php | 29 ++ .../Security/Factory/WsseFactory.php | 40 ++ .../DependencyInjection/WallabagApiExtension.php | 25 ++ .../ApiBundle/Resources/config/routing.yml | 0 .../ApiBundle/Resources/config/routing_rest.yml | 4 + .../ApiBundle/Resources/config/services.yml | 12 + .../Authentication/Provider/WsseProvider.php | 78 ++++ .../Authentication/Token/WsseUserToken.php | 23 ++ .../ApiBundle/Security/Firewall/WsseListener.php | 62 ++++ .../Controller/WallabagRestControllerTest.php | 410 +++++++++++++++++++++ src/Wallabag/ApiBundle/WallabagApiBundle.php | 18 + .../Controller/WallabagRestController.php | 360 ------------------ .../Security/Factory/WsseFactory.php | 40 -- .../DependencyInjection/WallabagCoreExtension.php | 6 +- .../CoreBundle/Resources/config/routing_rest.yml | 4 - .../CoreBundle/Resources/config/services.yml | 12 - .../Authentication/Provider/WsseProvider.php | 78 ---- .../Authentication/Token/WsseUserToken.php | 23 -- .../CoreBundle/Security/Firewall/WsseListener.php | 62 ---- .../Tests/Command/InstallCommandTest.php | 4 +- .../Tests/Controller/ConfigControllerTest.php | 4 +- .../Tests/Controller/EntryControllerTest.php | 4 +- .../Tests/Controller/SecurityControllerTest.php | 4 +- .../Controller/WallabagRestControllerTest.php | 214 ----------- .../CoreBundle/Tests/WallabagCoreTestCase.php | 32 ++ src/Wallabag/CoreBundle/Tests/WallabagTestCase.php | 32 -- src/Wallabag/CoreBundle/WallabagCoreBundle.php | 9 - 28 files changed, 1114 insertions(+), 845 deletions(-) create mode 100644 src/Wallabag/ApiBundle/Controller/WallabagRestController.php create mode 100644 src/Wallabag/ApiBundle/DependencyInjection/Configuration.php create mode 100644 src/Wallabag/ApiBundle/DependencyInjection/Security/Factory/WsseFactory.php create mode 100644 src/Wallabag/ApiBundle/DependencyInjection/WallabagApiExtension.php create mode 100644 src/Wallabag/ApiBundle/Resources/config/routing.yml create mode 100644 src/Wallabag/ApiBundle/Resources/config/routing_rest.yml create mode 100644 src/Wallabag/ApiBundle/Resources/config/services.yml create mode 100644 src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php create mode 100644 src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php create mode 100644 src/Wallabag/ApiBundle/Security/Firewall/WsseListener.php create mode 100644 src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php create mode 100644 src/Wallabag/ApiBundle/WallabagApiBundle.php delete mode 100644 src/Wallabag/CoreBundle/Controller/WallabagRestController.php delete mode 100644 src/Wallabag/CoreBundle/DependencyInjection/Security/Factory/WsseFactory.php delete mode 100644 src/Wallabag/CoreBundle/Resources/config/routing_rest.yml delete mode 100644 src/Wallabag/CoreBundle/Security/Authentication/Provider/WsseProvider.php delete mode 100644 src/Wallabag/CoreBundle/Security/Authentication/Token/WsseUserToken.php delete mode 100644 src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php delete mode 100644 src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php create mode 100644 src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php delete mode 100644 src/Wallabag/CoreBundle/Tests/WallabagTestCase.php (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php new file mode 100644 index 00000000..21e4552d --- /dev/null +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -0,0 +1,370 @@ +getDoctrine() + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($label); + + if (is_null($tagEntity)) { + $tagEntity = new Tag($this->getUser()); + $tagEntity->setLabel($label); + } + + // only add the tag on the entry if the relation doesn't exist + if (!$entry->getTags()->contains($tagEntity)) { + $entry->addTag($tagEntity); + } + } + } + + /** + * Retrieve salt for a giver user. + * + * @ApiDoc( + * parameters={ + * {"name"="username", "dataType"="string", "required"=true, "description"="username"} + * } + * ) + * @return array + */ + public function getSaltAction($username) + { + $user = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername($username); + + if (is_null($user)) { + throw $this->createNotFoundException(); + } + + return array($user->getSalt() ?: null); + } + + /** + * Retrieve all entries. It could be filtered by many options. + * + * @ApiDoc( + * parameters={ + * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."}, + * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."}, + * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, + * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, + * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, + * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, + * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, + * } + * ) + * @return Entry + */ + public function getEntriesAction(Request $request) + { + $isArchived = $request->query->get('archive'); + $isStarred = $request->query->get('star'); + $sort = $request->query->get('sort', 'created'); + $order = $request->query->get('order', 'desc'); + $page = (int) $request->query->get('page', 1); + $perPage = (int) $request->query->get('perPage', 30); + $tags = $request->query->get('tags', []); + + $pager = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); + + $pager->setCurrentPage($page); + $pager->setMaxPerPage($perPage); + + $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); + $paginatedCollection = $pagerfantaFactory->createRepresentation( + $pager, + new Route('api_get_entries', [], $absolute = true) + ); + + $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Retrieve a single entry + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + * @return Entry + */ + public function getEntryAction(Entry $entry) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Create an entry + * + * @ApiDoc( + * parameters={ + * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, + * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, + * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, + * } + * ) + * @return Entry + */ + public function postEntriesAction(Request $request) + { + $url = $request->request->get('url'); + + $content = Extractor::extract($url); + $entry = new Entry($this->getUser()); + $entry->setUrl($url); + $entry->setTitle($request->request->get('title') ?: $content->getTitle()); + $entry->setContent($content->getBody()); + + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Change several properties of an entry + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * }, + * parameters={ + * {"name"="title", "dataType"="string", "required"=false}, + * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, + * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."}, + * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."}, + * } + * ) + * @return Entry + */ + public function patchEntriesAction(Entry $entry, Request $request) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $title = $request->request->get("title"); + $isArchived = $request->request->get("archive"); + $isStarred = $request->request->get("star"); + + if (!is_null($title)) { + $entry->setTitle($title); + } + + if (!is_null($isArchived)) { + $entry->setArchived($isArchived); + } + + if (!is_null($isStarred)) { + $entry->setStarred($isStarred); + } + + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } + + $em = $this->getDoctrine()->getManager(); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Delete **permanently** an entry + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + * @return Entry + */ + public function deleteEntriesAction(Entry $entry) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $em = $this->getDoctrine()->getManager(); + $em->remove($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Retrieve all tags for an entry + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + */ + public function getEntriesTagsAction(Entry $entry) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Add one or more tags to an entry + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * }, + * parameters={ + * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, + * } + * ) + */ + public function postEntriesTagsAction(Request $request, Entry $entry) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Permanently remove one tag for an entry + * + * @ApiDoc( + * requirements={ + * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag ID"}, + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + */ + public function deleteEntriesTagsAction(Entry $entry, Tag $tag) + { + $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); + + $entry->removeTag($tag); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Retrieve all tags + * + * @ApiDoc() + */ + public function getTagsAction() + { + $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Permanently remove one tag from **every** entry + * + * @ApiDoc( + * requirements={ + * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"} + * } + * ) + */ + public function deleteTagAction(Tag $tag) + { + $this->validateUserAccess($tag->getUser()->getId(), $this->getUser()->getId()); + + $em = $this->getDoctrine()->getManager(); + $em->remove($tag); + $em->flush(); + + $json = $this->get('serializer')->serialize($tag, 'json'); + + return $this->renderJsonResponse($json); + } + + /** + * Validate that the first id is equal to the second one. + * If not, throw exception. It means a user try to access information from an other user + * + * @param integer $requestUserId User id from the requested source + * @param integer $currentUserId User id from the retrieved source + */ + private function validateUserAccess($requestUserId, $currentUserId) + { + if ($requestUserId != $currentUserId) { + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$currentUserId); + } + } + + /** + * Send a JSON Response. + * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string + * + * @param string $json + * + * @return Response + */ + private function renderJsonResponse($json) + { + return new Response($json, 200, array('application/json')); + } +} diff --git a/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php b/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php new file mode 100644 index 00000000..80a07ca2 --- /dev/null +++ b/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('wallabag_api'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/Wallabag/ApiBundle/DependencyInjection/Security/Factory/WsseFactory.php b/src/Wallabag/ApiBundle/DependencyInjection/Security/Factory/WsseFactory.php new file mode 100644 index 00000000..402eb869 --- /dev/null +++ b/src/Wallabag/ApiBundle/DependencyInjection/Security/Factory/WsseFactory.php @@ -0,0 +1,40 @@ +setDefinition($providerId, new DefinitionDecorator('wsse.security.authentication.provider')) + ->replaceArgument(0, new Reference($userProvider)) + ; + + $listenerId = 'security.authentication.listener.wsse.'.$id; + $listener = $container->setDefinition($listenerId, new DefinitionDecorator('wsse.security.authentication.listener')); + + return array($providerId, $listenerId, $defaultEntryPoint); + } + + public function getPosition() + { + return 'pre_auth'; + } + + public function getKey() + { + return 'wsse'; + } + + public function addConfiguration(NodeDefinition $node) + { + } +} diff --git a/src/Wallabag/ApiBundle/DependencyInjection/WallabagApiExtension.php b/src/Wallabag/ApiBundle/DependencyInjection/WallabagApiExtension.php new file mode 100644 index 00000000..c5cc204e --- /dev/null +++ b/src/Wallabag/ApiBundle/DependencyInjection/WallabagApiExtension.php @@ -0,0 +1,25 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } + + public function getAlias() + { + return 'wallabag_api'; + } +} diff --git a/src/Wallabag/ApiBundle/Resources/config/routing.yml b/src/Wallabag/ApiBundle/Resources/config/routing.yml new file mode 100644 index 00000000..e69de29b diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml new file mode 100644 index 00000000..5f43f971 --- /dev/null +++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml @@ -0,0 +1,4 @@ +entries: + type: rest + resource: "WallabagApiBundle:WallabagRest" + name_prefix: api_ diff --git a/src/Wallabag/ApiBundle/Resources/config/services.yml b/src/Wallabag/ApiBundle/Resources/config/services.yml new file mode 100644 index 00000000..6854a444 --- /dev/null +++ b/src/Wallabag/ApiBundle/Resources/config/services.yml @@ -0,0 +1,12 @@ +services: + wsse.security.authentication.provider: + class: Wallabag\ApiBundle\Security\Authentication\Provider\WsseProvider + public: false + arguments: ['', '%kernel.cache_dir%/security/nonces'] + + wsse.security.authentication.listener: + class: Wallabag\ApiBundle\Security\Firewall\WsseListener + public: false + tags: + - { name: monolog.logger, channel: wsse } + arguments: ['@security.context', '@security.authentication.manager', '@logger'] diff --git a/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php b/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php new file mode 100644 index 00000000..8e49167a --- /dev/null +++ b/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php @@ -0,0 +1,78 @@ +userProvider = $userProvider; + $this->cacheDir = $cacheDir; + + // If cache directory does not exist we create it + if (!is_dir($this->cacheDir)) { + mkdir($this->cacheDir, 0777, true); + } + } + + public function authenticate(TokenInterface $token) + { + $user = $this->userProvider->loadUserByUsername($token->getUsername()); + + if (!$user) { + throw new AuthenticationException("Bad credentials. Did you forgot your username?"); + } + + if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) { + $authenticatedToken = new WsseUserToken($user->getRoles()); + $authenticatedToken->setUser($user); + + return $authenticatedToken; + } + + throw new AuthenticationException('The WSSE authentication failed.'); + } + + protected function validateDigest($digest, $nonce, $created, $secret) + { + // Check created time is not in the future + if (strtotime($created) > time()) { + throw new AuthenticationException("Back to the future..."); + } + + // Expire timestamp after 5 minutes + if (time() - strtotime($created) > 300) { + throw new AuthenticationException("Too late for this timestamp... Watch your watch."); + } + + // Validate nonce is unique within 5 minutes + if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 300 > time()) { + throw new NonceExpiredException('Previously used nonce detected'); + } + + file_put_contents($this->cacheDir.'/'.$nonce, time()); + + // Validate Secret + $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true)); + + if ($digest !== $expected) { + throw new AuthenticationException("Bad credentials ! Digest is not as expected."); + } + + return $digest === $expected; + } + + public function supports(TokenInterface $token) + { + return $token instanceof WsseUserToken; + } +} diff --git a/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php b/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php new file mode 100644 index 00000000..aa68dbdc --- /dev/null +++ b/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php @@ -0,0 +1,23 @@ +setAuthenticated(count($roles) > 0); + } + + public function getCredentials() + { + return ''; + } +} diff --git a/src/Wallabag/ApiBundle/Security/Firewall/WsseListener.php b/src/Wallabag/ApiBundle/Security/Firewall/WsseListener.php new file mode 100644 index 00000000..50587837 --- /dev/null +++ b/src/Wallabag/ApiBundle/Security/Firewall/WsseListener.php @@ -0,0 +1,62 @@ +securityContext = $securityContext; + $this->authenticationManager = $authenticationManager; + $this->logger = $logger; + } + + public function handle(GetResponseEvent $event) + { + $request = $event->getRequest(); + + $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; + if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) { + return; + } + + $token = new WsseUserToken(); + $token->setUser($matches[1]); + + $token->digest = $matches[2]; + $token->nonce = $matches[3]; + $token->created = $matches[4]; + + try { + $authToken = $this->authenticationManager->authenticate($token); + + $this->securityContext->setToken($authToken); + + return; + } catch (AuthenticationException $failed) { + $failedMessage = 'WSSE Login failed for '.$token->getUsername().'. Why ? '.$failed->getMessage(); + $this->logger->err($failedMessage); + + // Deny authentication with a '403 Forbidden' HTTP response + $response = new Response(); + $response->setStatusCode(403); + $response->setContent($failedMessage); + $event->setResponse($response); + + return; + } + } +} diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php new file mode 100644 index 00000000..ea8ee072 --- /dev/null +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -0,0 +1,410 @@ +getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername('admin'); + + self::$salt = $user->getSalt(); + } + + /** + * Generate HTTP headers for authenticate user on API + * + * @param string $username + * @param string $password + * + * @return array + */ + private function generateHeaders($username, $password) + { + $encryptedPassword = sha1($password.$username.self::$salt); + $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); + + $now = new \DateTime('now', new \DateTimeZone('UTC')); + $created = (string) $now->format('Y-m-d\TH:i:s\Z'); + $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); + + return array( + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', + ); + } + + public function testGetSalt() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:User') + ->findOneByUsername('admin'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey(0, $content); + $this->assertEquals($user->getSalt(), $content[0]); + + $client->request('GET', '/api/salts/notfound.json'); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + } + + public function testWithBadHeaders() + { + $client = $this->createClient(); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsArchived(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $badHeaders = array( + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', + ); + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + } + + public function testGetOneEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneBy(array('user' => 1, 'isArchived' => false)); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertEquals($entry->getTitle(), $content['title']); + $this->assertEquals($entry->getUrl(), $content['url']); + $this->assertCount(count($entry->getTags()), $content['tags']); + + $this->assertTrue( + $client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + + public function testGetOneEntryWrongUser() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneBy(array('user' => 2, 'isArchived' => false)); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + } + + public function testGetEntries() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('GET', '/api/entries', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertGreaterThanOrEqual(1, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertTrue( + $client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + + public function testGetStarredEntries() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('GET', '/api/entries', array('archive' => 1), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertEmpty($content['_embedded']['items']); + $this->assertEquals(0, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertEquals(1, $content['pages']); + + $this->assertTrue( + $client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + + public function testDeleteEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertEquals($entry->getTitle(), $content['title']); + $this->assertEquals($entry->getUrl(), $content['url']); + + // We'll try to delete this entry again + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + } + + public function testPostEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('POST', '/api/entries.json', array( + 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', + 'tags' => 'google', + ), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); + $this->assertEquals(false, $content['is_archived']); + $this->assertEquals(false, $content['is_starred']); + $this->assertCount(1, $content['tags']); + } + + public function testPatchEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + // hydrate the tags relations + $nbTags = count($entry->getTags()); + + $client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( + 'title' => 'New awesome title', + 'tags' => 'new tag '.uniqid(), + 'star' => true, + 'archive' => false, + ), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertEquals($entry->getId(), $content['id']); + $this->assertEquals($entry->getUrl(), $content['url']); + $this->assertEquals('New awesome title', $content['title']); + $this->assertGreaterThan($nbTags, count($content['tags'])); + } + + public function testGetTagsEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneWithTags(1); + + $entry = $entry[0]; + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $tags = array(); + foreach ($entry->getTags() as $tag) { + $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); + } + + $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); + + $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); + } + + public function testPostTagsOnEntry() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $nbTags = count($entry->getTags()); + + $newTags = 'tag1,tag2,tag3'; + + $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('tags', $content); + $this->assertEquals($nbTags+3, count($content['tags'])); + + $entryDB = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->find($entry->getId()); + + $tagsInDB = array(); + foreach ($entryDB->getTags()->toArray() as $tag) { + $tagsInDB[$tag->getId()] = $tag->getLabel(); + } + + foreach (explode(',', $newTags) as $tag) { + $this->assertContains($tag, $tagsInDB); + } + } + + public function testDeleteOneTagEntrie() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + // hydrate the tags relations + $nbTags = count($entry->getTags()); + $tag = $entry->getTags()[0]; + + $client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('tags', $content); + $this->assertEquals($nbTags-1, count($content['tags'])); + } + + public function testGetUserTags() + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('GET', '/api/tags.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content); + $this->assertArrayHasKey('id', $content[0]); + $this->assertArrayHasKey('label', $content[0]); + + return end($content); + } + + /** + * @depends testGetUserTags + */ + public function testDeleteUserTag($tag) + { + $client = $this->createClient(); + $headers = $this->generateHeaders('admin', 'mypassword'); + + $client->request('DELETE', '/api/tags/'.$tag['id'].'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('label', $content); + $this->assertEquals($tag['label'], $content['label']); + } +} diff --git a/src/Wallabag/ApiBundle/WallabagApiBundle.php b/src/Wallabag/ApiBundle/WallabagApiBundle.php new file mode 100644 index 00000000..2484f277 --- /dev/null +++ b/src/Wallabag/ApiBundle/WallabagApiBundle.php @@ -0,0 +1,18 @@ +getExtension('security'); + $extension->addSecurityListenerFactory(new WsseFactory()); + } +} diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php deleted file mode 100644 index 14f42c48..00000000 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ /dev/null @@ -1,360 +0,0 @@ -getDoctrine() - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($label); - - if (is_null($tagEntity)) { - $tagEntity = new Tag($this->getUser()); - $tagEntity->setLabel($label); - } - - // only add the tag on the entry if the relation doesn't exist - if (!$entry->getTags()->contains($tagEntity)) { - $entry->addTag($tagEntity); - } - } - } - - /** - * Retrieve salt for a giver user. - * - * @ApiDoc( - * parameters={ - * {"name"="username", "dataType"="string", "required"=true, "description"="username"} - * } - * ) - * @return array - */ - public function getSaltAction($username) - { - $user = $this - ->getDoctrine() - ->getRepository('WallabagCoreBundle:User') - ->findOneByUsername($username); - - if (is_null($user)) { - throw $this->createNotFoundException(); - } - - return array($user->getSalt() ?: null); - } - /** - * Retrieve all entries. It could be filtered by many options. - * - * @ApiDoc( - * parameters={ - * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."}, - * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."}, - * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, - * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, - * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, - * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, - * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, - * } - * ) - * @return Entry - */ - public function getEntriesAction(Request $request) - { - $isArchived = $request->query->get('archive'); - $isStarred = $request->query->get('star'); - $sort = $request->query->get('sort', 'created'); - $order = $request->query->get('order', 'desc'); - $page = (int) $request->query->get('page', 1); - $perPage = (int) $request->query->get('perPage', 30); - $tags = $request->query->get('tags', array()); - - $pager = $this - ->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); - - if (0 === $pager->getNbResults()) { - throw $this->createNotFoundException(); - } - - $pager->setCurrentPage($page); - $pager->setMaxPerPage($perPage); - - $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); - $paginatedCollection = $pagerfantaFactory->createRepresentation( - $pager, - new Route('api_get_entries', [], $absolute = true) - ); - - $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Retrieve a single entry - * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * } - * ) - * @return Entry - */ - public function getEntryAction(Entry $entry) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Create an entry - * - * @ApiDoc( - * parameters={ - * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, - * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, - * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, - * } - * ) - * @return Entry - */ - public function postEntriesAction(Request $request) - { - $url = $request->request->get('url'); - - $content = Extractor::extract($url); - $entry = new Entry($this->getUser()); - $entry->setUrl($url); - $entry->setTitle($request->request->get('title') ?: $content->getTitle()); - $entry->setContent($content->getBody()); - - $tags = $request->request->get('tags', ''); - if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); - } - - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Change several properties of an entry - * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * }, - * parameters={ - * {"name"="title", "dataType"="string", "required"=false}, - * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, - * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."}, - * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."}, - * } - * ) - * @return Entry - */ - public function patchEntriesAction(Entry $entry, Request $request) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $title = $request->request->get("title"); - $isArchived = $request->request->get("archive"); - $isStarred = $request->request->get("star"); - - if (!is_null($title)) { - $entry->setTitle($title); - } - - if (!is_null($isArchived)) { - $entry->setArchived($isArchived); - } - - if (!is_null($isStarred)) { - $entry->setStarred($isStarred); - } - - $tags = $request->request->get('tags', ''); - if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); - } - - $em = $this->getDoctrine()->getManager(); - $em->flush(); - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Delete **permanently** an entry - * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * } - * ) - * @return Entry - */ - public function deleteEntriesAction(Entry $entry) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $em = $this->getDoctrine()->getManager(); - $em->remove($entry); - $em->flush(); - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Retrieve all tags for an entry - * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * } - * ) - */ - public function getEntriesTagsAction(Entry $entry) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Add one or more tags to an entry - * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * }, - * parameters={ - * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, - * } - * ) - */ - public function postEntriesTagsAction(Request $request, Entry $entry) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $tags = $request->request->get('tags', ''); - if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); - } - - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Permanently remove one tag for an entry - * - * @ApiDoc( - * requirements={ - * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"}, - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * } - * ) - */ - public function deleteEntriesTagsAction(Entry $entry, Tag $tag) - { - if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $entry->removeTag($tag); - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - - $json = $this->get('serializer')->serialize($entry, 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Retrieve all tags - * - * @ApiDoc() - */ - public function getTagsAction() - { - $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); - - return new Response($json, 200, array('application/json')); - } - - /** - * Permanently remove one tag from **every** entry - * - * @ApiDoc( - * requirements={ - * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} - * } - * ) - */ - public function deleteTagAction(Tag $tag) - { - if ($tag->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$tag->getUser()->getId().', logged user id: '.$this->getUser()->getId()); - } - - $em = $this->getDoctrine()->getManager(); - $em->remove($tag); - $em->flush(); - - $json = $this->get('serializer')->serialize($tag, 'json'); - - return new Response($json, 200, array('application/json')); - } -} diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Security/Factory/WsseFactory.php b/src/Wallabag/CoreBundle/DependencyInjection/Security/Factory/WsseFactory.php deleted file mode 100644 index 0b5bdb40..00000000 --- a/src/Wallabag/CoreBundle/DependencyInjection/Security/Factory/WsseFactory.php +++ /dev/null @@ -1,40 +0,0 @@ -setDefinition($providerId, new DefinitionDecorator('wsse.security.authentication.provider')) - ->replaceArgument(0, new Reference($userProvider)) - ; - - $listenerId = 'security.authentication.listener.wsse.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('wsse.security.authentication.listener')); - - return array($providerId, $listenerId, $defaultEntryPoint); - } - - public function getPosition() - { - return 'pre_auth'; - } - - public function getKey() - { - return 'wsse'; - } - - public function addConfiguration(NodeDefinition $node) - { - } -} diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index c6ecc99e..7493351b 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -3,15 +3,15 @@ namespace Wallabag\CoreBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader; class WallabagCoreExtension extends Extension { public function load(array $configs, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); } diff --git a/src/Wallabag/CoreBundle/Resources/config/routing_rest.yml b/src/Wallabag/CoreBundle/Resources/config/routing_rest.yml deleted file mode 100644 index d3af6b72..00000000 --- a/src/Wallabag/CoreBundle/Resources/config/routing_rest.yml +++ /dev/null @@ -1,4 +0,0 @@ -entries: - type: rest - resource: "WallabagCoreBundle:WallabagRest" - name_prefix: api_ diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index cea6c0df..d8bd8d52 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -4,18 +4,6 @@ services: tags: - { name: twig.extension } - wsse.security.authentication.provider: - class: Wallabag\CoreBundle\Security\Authentication\Provider\WsseProvider - public: false - arguments: ['', '%kernel.cache_dir%/security/nonces'] - - wsse.security.authentication.listener: - class: Wallabag\CoreBundle\Security\Firewall\WsseListener - public: false - tags: - - { name: monolog.logger, channel: wsse } - arguments: ['@security.context', '@security.authentication.manager', '@logger'] - wallabag_core.helper.detect_active_theme: class: Wallabag\CoreBundle\Helper\DetectActiveTheme arguments: diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WsseProvider.php b/src/Wallabag/CoreBundle/Security/Authentication/Provider/WsseProvider.php deleted file mode 100644 index 7e6a5dfb..00000000 --- a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WsseProvider.php +++ /dev/null @@ -1,78 +0,0 @@ -userProvider = $userProvider; - $this->cacheDir = $cacheDir; - - // If cache directory does not exist we create it - if (!is_dir($this->cacheDir)) { - mkdir($this->cacheDir, 0777, true); - } - } - - public function authenticate(TokenInterface $token) - { - $user = $this->userProvider->loadUserByUsername($token->getUsername()); - - if (!$user) { - throw new AuthenticationException("Bad credentials. Did you forgot your username?"); - } - - if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) { - $authenticatedToken = new WsseUserToken($user->getRoles()); - $authenticatedToken->setUser($user); - - return $authenticatedToken; - } - - throw new AuthenticationException('The WSSE authentication failed.'); - } - - protected function validateDigest($digest, $nonce, $created, $secret) - { - // Check created time is not in the future - if (strtotime($created) > time()) { - throw new AuthenticationException("Back to the future..."); - } - - // Expire timestamp after 5 minutes - if (time() - strtotime($created) > 300) { - throw new AuthenticationException("Too late for this timestamp... Watch your watch."); - } - - // Validate nonce is unique within 5 minutes - if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 300 > time()) { - throw new NonceExpiredException('Previously used nonce detected'); - } - - file_put_contents($this->cacheDir.'/'.$nonce, time()); - - // Validate Secret - $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true)); - - if ($digest !== $expected) { - throw new AuthenticationException("Bad credentials ! Digest is not as expected."); - } - - return $digest === $expected; - } - - public function supports(TokenInterface $token) - { - return $token instanceof WsseUserToken; - } -} diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Token/WsseUserToken.php b/src/Wallabag/CoreBundle/Security/Authentication/Token/WsseUserToken.php deleted file mode 100644 index ea6fb9bf..00000000 --- a/src/Wallabag/CoreBundle/Security/Authentication/Token/WsseUserToken.php +++ /dev/null @@ -1,23 +0,0 @@ -setAuthenticated(count($roles) > 0); - } - - public function getCredentials() - { - return ''; - } -} diff --git a/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php b/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php deleted file mode 100644 index 6ffdfaf0..00000000 --- a/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php +++ /dev/null @@ -1,62 +0,0 @@ -securityContext = $securityContext; - $this->authenticationManager = $authenticationManager; - $this->logger = $logger; - } - - public function handle(GetResponseEvent $event) - { - $request = $event->getRequest(); - - $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; - if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) { - return; - } - - $token = new WsseUserToken(); - $token->setUser($matches[1]); - - $token->digest = $matches[2]; - $token->nonce = $matches[3]; - $token->created = $matches[4]; - - try { - $authToken = $this->authenticationManager->authenticate($token); - - $this->securityContext->setToken($authToken); - - return; - } catch (AuthenticationException $failed) { - $failedMessage = 'WSSE Login failed for '.$token->getUsername().'. Why ? '.$failed->getMessage(); - $this->logger->err($failedMessage); - - // Deny authentication with a '403 Forbidden' HTTP response - $response = new Response(); - $response->setStatusCode(403); - $response->setContent($failedMessage); - $event->setResponse($response); - - return; - } - } -} diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index f689b532..7a819953 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -2,7 +2,7 @@ namespace Wallabag\CoreBundle\Tests\Command; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; use Wallabag\CoreBundle\Command\InstallCommand; use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\NullOutput; use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; -class InstallCommandTest extends WallabagTestCase +class InstallCommandTest extends WallabagCoreTestCase { public static function tearDownAfterClass() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 5030bcbd..3c158922 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class ConfigControllerTest extends WallabagTestCase +class ConfigControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 1a0d586c..8a7fdda2 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -2,10 +2,10 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; use Doctrine\ORM\AbstractQuery; -class EntryControllerTest extends WallabagTestCase +class EntryControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index 1dd05f89..e560ffdd 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php @@ -2,11 +2,11 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class SecurityControllerTest extends WallabagTestCase +class SecurityControllerTest extends WallabagCoreTestCase { public function testLogin() { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php deleted file mode 100644 index c9907065..00000000 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ /dev/null @@ -1,214 +0,0 @@ -format('Y-m-d\TH:i:s\Z'); - $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); - - return array( - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', - ); - } - - public function testGetSalt() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertNotEmpty(json_decode($client->getResponse()->getContent())); - - $client->request('GET', '/api/salts/notfound.json'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); - } - - public function testWithBadHeaders() - { - $client = $this->createClient(); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $badHeaders = array( - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', - ); - - $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); - } - - public function testGetOneEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - $this->assertContains($entry->getTitle(), $client->getResponse()->getContent()); - - $this->assertTrue( - $client->getResponse()->headers->contains( - 'Content-Type', - 'application/json' - ) - ); - } - - public function testGetEntries() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $client->request('GET', '/api/entries', array(), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); - - $this->assertContains('Google', $client->getResponse()->getContent()); - - $this->assertTrue( - $client->getResponse()->headers->contains( - 'Content-Type', - 'application/json' - ) - ); - } - - public function testDeleteEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - // We'll try to delete this entry again - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); - - $this->assertEquals(404, $client->getResponse()->getStatusCode()); - } - - public function testGetTagsEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneWithTags(1); - - $entry = $entry[0]; - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $tags = array(); - foreach ($entry->getTags() as $tag) { - $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); - } - - $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); - - $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); - } - - public function testPostTagsOnEntry() - { - $client = $this->createClient(); - $client->request('GET', '/api/salts/admin.json'); - $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]); - - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $newTags = 'tag1,tag2,tag3'; - - $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $entryDB = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->find($entry->getId()); - - $tagsInDB = array(); - foreach ($entryDB->getTags()->toArray() as $tag) { - $tagsInDB[$tag->getId()] = $tag->getLabel(); - } - - foreach (explode(',', $newTags) as $tag) { - $this->assertContains($tag, $tagsInDB); - } - } -} diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php new file mode 100644 index 00000000..e5096528 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php @@ -0,0 +1,32 @@ +client; + } + + public function setUp() + { + $this->client = static::createClient(); + } + + public function logInAs($username) + { + $crawler = $this->client->request('GET', '/login'); + $form = $crawler->filter('button[type=submit]')->form(); + $data = array( + '_username' => $username, + '_password' => 'mypassword', + ); + + $this->client->submit($form, $data); + } +} diff --git a/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php deleted file mode 100644 index 22016d8e..00000000 --- a/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php +++ /dev/null @@ -1,32 +0,0 @@ -client; - } - - public function setUp() - { - $this->client = static::createClient(); - } - - public function logInAs($username) - { - $crawler = $this->client->request('GET', '/login'); - $form = $crawler->filter('button[type=submit]')->form(); - $data = array( - '_username' => $username, - '_password' => 'mypassword', - ); - - $this->client->submit($form, $data); - } -} diff --git a/src/Wallabag/CoreBundle/WallabagCoreBundle.php b/src/Wallabag/CoreBundle/WallabagCoreBundle.php index 1deab03a..f5899e39 100644 --- a/src/Wallabag/CoreBundle/WallabagCoreBundle.php +++ b/src/Wallabag/CoreBundle/WallabagCoreBundle.php @@ -3,16 +3,7 @@ namespace Wallabag\CoreBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Wallabag\CoreBundle\DependencyInjection\Security\Factory\WsseFactory; -use Symfony\Component\DependencyInjection\ContainerBuilder; class WallabagCoreBundle extends Bundle { - public function build(ContainerBuilder $container) - { - parent::build($container); - - $extension = $container->getExtension('security'); - $extension->addSecurityListenerFactory(new WsseFactory()); - } } -- cgit v1.2.3 From 9744e97131182f413b51a0ce671ff273fc28a0bb Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 1 Apr 2015 21:53:57 +0200 Subject: Fix tests --- .../ApiBundle/Tests/Controller/WallabagRestControllerTest.php | 8 ++++---- src/Wallabag/CoreBundle/Controller/ConfigController.php | 2 +- .../CoreBundle/Tests/Controller/ConfigControllerTest.php | 2 +- src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index ea8ee072..b36ae7c6 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -1,6 +1,6 @@ getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(1, count($content)); - $this->assertEmpty($content['_embedded']['items']); - $this->assertEquals(0, $content['total']); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertGreaterThanOrEqual(1, $content['total']); $this->assertEquals(1, $content['page']); - $this->assertEquals(1, $content['pages']); + $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertTrue( $client->getResponse()->headers->contains( diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 898c291f..62ef3eea 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -133,7 +133,7 @@ class ConfigController extends Controller 'rss' => array( 'username' => $user->getUsername(), 'token' => $config->getRssToken(), - ) + ), )); } diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 3c158922..a0145780 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -397,7 +397,7 @@ class ConfigControllerTest extends WallabagCoreTestCase ); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $content = json_decode($client->getResponse()->getContent(), true);; + $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('token', $content); } diff --git a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php index 8f627b4b..b7c162a7 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class RssControllerTest extends WallabagTestCase +class RssControllerTest extends WallabagCoreTestCase { public function validateDom($xml, $nb = null) { @@ -36,13 +36,13 @@ class RssControllerTest extends WallabagTestCase { return array( array( - '/admin/YZIOAUZIAO/unread.xml' + '/admin/YZIOAUZIAO/unread.xml', ), array( - '/wallace/YZIOAUZIAO/starred.xml' + '/wallace/YZIOAUZIAO/starred.xml', ), array( - '/wallace/YZIOAUZIAO/archives.xml' + '/wallace/YZIOAUZIAO/archives.xml', ), ); } -- cgit v1.2.3 From 132f614dee55634f83d858d30759226586807566 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 1 Apr 2015 21:54:22 +0200 Subject: Avoid / in feed token Of course, it breaks the url and the route matcher for each feed route --- src/Wallabag/CoreBundle/Tools/Utils.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index de97c796..8fa74491 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -22,6 +22,7 @@ class Utils $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); } - return str_replace('+', '', $token); + // remove character which can broken the url + return str_replace(array('+', '/'), '', $token); } } -- cgit v1.2.3 From 2f3c816579968591291a60fc41c9b32284592dc8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 30 May 2015 13:40:39 +0200 Subject: Update naming strategy since Doctrine 2.5 See https://github.com/doctrine/doctrine2/commit/20fb8270dc3c84eceaf90979644fdfbe0b2e615e --- .../CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php index 861a60ea..724812fd 100644 --- a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php +++ b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php @@ -72,4 +72,12 @@ class PrefixedNamingStrategy implements NamingStrategy { return strtolower($this->classToTableName($entityName) . '_' .($referencedColumnName ?: $this->referenceColumnName())); } + + /** + * {@inheritdoc} + */ + public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null) + { + return $propertyName.'_'.$embeddedColumnName; + } } -- cgit v1.2.3 From 4346a86068781f4acdeb574d7e2af08b77b58ea7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 30 May 2015 13:52:26 +0200 Subject: CS --- .../Controller/WallabagRestController.php | 38 ++++++++------ .../DependencyInjection/Configuration.php | 2 +- .../Authentication/Provider/WsseProvider.php | 9 ++-- .../Authentication/Token/WsseUserToken.php | 1 + .../Controller/WallabagRestControllerTest.php | 8 +-- src/Wallabag/CoreBundle/Command/InstallCommand.php | 10 ++-- .../CoreBundle/Controller/EntryController.php | 16 +++--- .../CoreBundle/Controller/RssController.php | 6 +-- .../CoreBundle/Controller/SecurityController.php | 9 ++-- .../CoreBundle/DataFixtures/ORM/LoadEntryData.php | 8 +-- .../Doctrine/Mapping/PrefixedNamingStrategy.php | 8 +-- src/Wallabag/CoreBundle/Entity/Config.php | 56 +++++++++++--------- src/Wallabag/CoreBundle/Entity/Entry.php | 55 +++++++++++--------- src/Wallabag/CoreBundle/Entity/Tag.php | 15 +++--- src/Wallabag/CoreBundle/Entity/User.php | 60 ++++++++++++---------- .../CoreBundle/Form/Type/ChangePasswordType.php | 1 + src/Wallabag/CoreBundle/Form/Type/ConfigType.php | 1 + src/Wallabag/CoreBundle/Form/Type/EntryType.php | 1 + .../CoreBundle/Form/Type/ForgotPasswordType.php | 1 + src/Wallabag/CoreBundle/Form/Type/NewUserType.php | 1 + .../CoreBundle/Form/Type/ResetPasswordType.php | 1 + src/Wallabag/CoreBundle/Form/Type/RssType.php | 1 + .../CoreBundle/Form/Type/UserInformationType.php | 1 + src/Wallabag/CoreBundle/Helper/Tools.php | 12 +++-- .../CoreBundle/Repository/EntryRepository.php | 8 +-- .../CoreBundle/Repository/UserRepository.php | 2 +- .../Encoder/WallabagPasswordEncoder.php | 3 +- .../Provider/WallabagAuthenticationProvider.php | 2 +- src/Wallabag/CoreBundle/Service/Extractor.php | 23 +++++---- src/Wallabag/CoreBundle/Tools/Utils.php | 2 +- .../Twig/Extension/WallabagExtension.php | 6 ++- 31 files changed, 204 insertions(+), 163 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 21e4552d..2f5923c8 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -47,6 +47,7 @@ class WallabagRestController extends Controller * {"name"="username", "dataType"="string", "required"=true, "description"="username"} * } * ) + * * @return array */ public function getSaltAction($username) @@ -77,6 +78,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, * } * ) + * * @return Entry */ public function getEntriesAction(Request $request) @@ -109,13 +111,14 @@ class WallabagRestController extends Controller } /** - * Retrieve a single entry + * Retrieve a single entry. * * @ApiDoc( * requirements={ * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * * @return Entry */ public function getEntryAction(Entry $entry) @@ -128,7 +131,7 @@ class WallabagRestController extends Controller } /** - * Create an entry + * Create an entry. * * @ApiDoc( * parameters={ @@ -137,6 +140,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, * } * ) + * * @return Entry */ public function postEntriesAction(Request $request) @@ -164,7 +168,7 @@ class WallabagRestController extends Controller } /** - * Change several properties of an entry + * Change several properties of an entry. * * @ApiDoc( * requirements={ @@ -177,15 +181,16 @@ class WallabagRestController extends Controller * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."}, * } * ) + * * @return Entry */ public function patchEntriesAction(Entry $entry, Request $request) { $this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId()); - $title = $request->request->get("title"); - $isArchived = $request->request->get("archive"); - $isStarred = $request->request->get("star"); + $title = $request->request->get('title'); + $isArchived = $request->request->get('archive'); + $isStarred = $request->request->get('star'); if (!is_null($title)) { $entry->setTitle($title); @@ -213,13 +218,14 @@ class WallabagRestController extends Controller } /** - * Delete **permanently** an entry + * Delete **permanently** an entry. * * @ApiDoc( * requirements={ * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * * @return Entry */ public function deleteEntriesAction(Entry $entry) @@ -236,7 +242,7 @@ class WallabagRestController extends Controller } /** - * Retrieve all tags for an entry + * Retrieve all tags for an entry. * * @ApiDoc( * requirements={ @@ -254,7 +260,7 @@ class WallabagRestController extends Controller } /** - * Add one or more tags to an entry + * Add one or more tags to an entry. * * @ApiDoc( * requirements={ @@ -284,7 +290,7 @@ class WallabagRestController extends Controller } /** - * Permanently remove one tag for an entry + * Permanently remove one tag for an entry. * * @ApiDoc( * requirements={ @@ -308,7 +314,7 @@ class WallabagRestController extends Controller } /** - * Retrieve all tags + * Retrieve all tags. * * @ApiDoc() */ @@ -320,7 +326,7 @@ class WallabagRestController extends Controller } /** - * Permanently remove one tag from **every** entry + * Permanently remove one tag from **every** entry. * * @ApiDoc( * requirements={ @@ -343,10 +349,10 @@ class WallabagRestController extends Controller /** * Validate that the first id is equal to the second one. - * If not, throw exception. It means a user try to access information from an other user + * If not, throw exception. It means a user try to access information from an other user. * - * @param integer $requestUserId User id from the requested source - * @param integer $currentUserId User id from the retrieved source + * @param int $requestUserId User id from the requested source + * @param int $currentUserId User id from the retrieved source */ private function validateUserAccess($requestUserId, $currentUserId) { @@ -357,7 +363,7 @@ class WallabagRestController extends Controller /** * Send a JSON Response. - * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string + * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string. * * @param string $json * diff --git a/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php b/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php index 80a07ca2..cec45412 100644 --- a/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/ApiBundle/DependencyInjection/Configuration.php @@ -6,7 +6,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * This is the class that validates and merges configuration from your app/config files + * This is the class that validates and merges configuration from your app/config files. * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} */ diff --git a/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php b/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php index 8e49167a..db73ae2a 100644 --- a/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php +++ b/src/Wallabag/ApiBundle/Security/Authentication/Provider/WsseProvider.php @@ -1,4 +1,5 @@ userProvider->loadUserByUsername($token->getUsername()); if (!$user) { - throw new AuthenticationException("Bad credentials. Did you forgot your username?"); + throw new AuthenticationException('Bad credentials. Did you forgot your username?'); } if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) { @@ -46,12 +47,12 @@ class WsseProvider implements AuthenticationProviderInterface { // Check created time is not in the future if (strtotime($created) > time()) { - throw new AuthenticationException("Back to the future..."); + throw new AuthenticationException('Back to the future...'); } // Expire timestamp after 5 minutes if (time() - strtotime($created) > 300) { - throw new AuthenticationException("Too late for this timestamp... Watch your watch."); + throw new AuthenticationException('Too late for this timestamp... Watch your watch.'); } // Validate nonce is unique within 5 minutes @@ -65,7 +66,7 @@ class WsseProvider implements AuthenticationProviderInterface $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true)); if ($digest !== $expected) { - throw new AuthenticationException("Bad credentials ! Digest is not as expected."); + throw new AuthenticationException('Bad credentials ! Digest is not as expected.'); } return $digest === $expected; diff --git a/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php b/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php index aa68dbdc..e6d30224 100644 --- a/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php +++ b/src/Wallabag/ApiBundle/Security/Authentication/Token/WsseUserToken.php @@ -1,4 +1,5 @@ getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertEquals($nbTags+3, count($content['tags'])); + $this->assertEquals($nbTags + 3, count($content['tags'])); $entryDB = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -369,7 +369,7 @@ class WallabagRestControllerTest extends WebTestCase $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertEquals($nbTags-1, count($content['tags'])); + $this->assertEquals($nbTags - 1, count($content['tags'])); } public function testGetUserTags() diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 493842f7..491c67f9 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -225,7 +225,7 @@ class InstallCommand extends ContainerAwareCommand } /** - * Run a command + * Run a command. * * @param string $command * @param array $parameters Parameters to this command (usually 'force' => true) @@ -266,9 +266,9 @@ class InstallCommand extends ContainerAwareCommand } /** - * Check if the database already exists + * Check if the database already exists. * - * @return boolean + * @return bool */ private function isDatabasePresent() { @@ -300,9 +300,9 @@ class InstallCommand extends ContainerAwareCommand /** * Check if the schema is already created. - * If we found at least oen table, it means the schema exists + * If we found at least oen table, it means the schema exists. * - * @return boolean + * @return bool */ private function isSchemaPresent() { diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 8a8f3cd7..7fd982c9 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -50,7 +50,7 @@ class EntryController extends Controller } /** - * Shows unread entries for current user + * Shows unread entries for current user. * * @Route("/unread", name="unread") * @@ -70,7 +70,7 @@ class EntryController extends Controller } /** - * Shows read entries for current user + * Shows read entries for current user. * * @Route("/archive", name="archive") * @@ -90,7 +90,7 @@ class EntryController extends Controller } /** - * Shows starred entries for current user + * Shows starred entries for current user. * * @Route("/starred", name="starred") * @@ -110,7 +110,7 @@ class EntryController extends Controller } /** - * Shows entry content + * Shows entry content. * * @param Entry $entry * @@ -129,7 +129,7 @@ class EntryController extends Controller } /** - * Changes read status for an entry + * Changes read status for an entry. * * @param Request $request * @param Entry $entry @@ -154,7 +154,7 @@ class EntryController extends Controller } /** - * Changes favorite status for an entry + * Changes favorite status for an entry. * * @param Request $request * @param Entry $entry @@ -179,7 +179,7 @@ class EntryController extends Controller } /** - * Deletes entry + * Deletes entry. * * @param Request $request * @param Entry $entry @@ -205,7 +205,7 @@ class EntryController extends Controller } /** - * Check if the logged user can manage the given entry + * Check if the logged user can manage the given entry. * * @param Entry $entry */ diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 14f1dcb2..86754e15 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php @@ -11,7 +11,7 @@ use Wallabag\CoreBundle\Entity\Entry; class RssController extends Controller { /** - * Shows unread entries for current user + * Shows unread entries for current user. * * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") @@ -35,7 +35,7 @@ class RssController extends Controller } /** - * Shows read entries for current user + * Shows read entries for current user. * * @Route("/{username}/{token}/archive.xml", name="archive_rss") * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") @@ -59,7 +59,7 @@ class RssController extends Controller } /** - * Shows starred entries for current user + * Shows starred entries for current user. * * @Route("/{username}/{token}/starred.xml", name="starred_rss") * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") diff --git a/src/Wallabag/CoreBundle/Controller/SecurityController.php b/src/Wallabag/CoreBundle/Controller/SecurityController.php index fe511db5..a61a898b 100644 --- a/src/Wallabag/CoreBundle/Controller/SecurityController.php +++ b/src/Wallabag/CoreBundle/Controller/SecurityController.php @@ -30,9 +30,10 @@ class SecurityController extends Controller } /** - * Request forgot password: show form + * Request forgot password: show form. * * @Route("/forgot-password", name="forgot_password") + * * @Method({"GET", "POST"}) */ public function forgotPasswordAction(Request $request) @@ -73,9 +74,10 @@ class SecurityController extends Controller } /** - * Tell the user to check his email provider + * Tell the user to check his email provider. * * @Route("/forgot-password/check-email", name="forgot_password_check_email") + * * @Method({"GET"}) */ public function checkEmailAction(Request $request) @@ -93,9 +95,10 @@ class SecurityController extends Controller } /** - * Reset user password + * Reset user password. * * @Route("/forgot-password/{token}", name="forgot_password_reset") + * * @Method({"GET", "POST"}) */ public function resetAction(Request $request, $token) diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php index 54d0d6b6..547d6753 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php @@ -39,9 +39,9 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry3->setContent('This is my content /o/'); $tag1 = new Tag($this->getReference('bob-user')); - $tag1->setLabel("foo"); + $tag1->setLabel('foo'); $tag2 = new Tag($this->getReference('bob-user')); - $tag2->setLabel("bar"); + $tag2->setLabel('bar'); $entry3->addTag($tag1); $entry3->addTag($tag2); @@ -56,9 +56,9 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry4->setContent('This is my content /o/'); $tag1 = new Tag($this->getReference('admin-user')); - $tag1->setLabel("foo"); + $tag1->setLabel('foo'); $tag2 = new Tag($this->getReference('admin-user')); - $tag2->setLabel("bar"); + $tag2->setLabel('bar'); $entry4->addTag($tag1); $entry4->addTag($tag2); diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php index 724812fd..509348db 100644 --- a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php +++ b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php @@ -25,7 +25,7 @@ class PrefixedNamingStrategy implements NamingStrategy */ public function classToTableName($className) { - return strtolower($this->prefix . substr($className, strrpos($className, '\\') + 1)); + return strtolower($this->prefix.substr($className, strrpos($className, '\\') + 1)); } /** @@ -49,7 +49,7 @@ class PrefixedNamingStrategy implements NamingStrategy */ public function joinColumnName($propertyName) { - return $propertyName . '_' . $this->referenceColumnName(); + return $propertyName.'_'.$this->referenceColumnName(); } /** @@ -62,7 +62,7 @@ class PrefixedNamingStrategy implements NamingStrategy // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag" $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1); - return strtolower($this->classToTableName($sourceEntity) . '_' .$target); + return strtolower($this->classToTableName($sourceEntity).'_'.$target); } /** @@ -70,7 +70,7 @@ class PrefixedNamingStrategy implements NamingStrategy */ public function joinKeyColumnName($entityName, $referencedColumnName = null) { - return strtolower($this->classToTableName($entityName) . '_' .($referencedColumnName ?: $this->referenceColumnName())); + return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName())); } /** diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 62ea637e..025d94ef 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** - * Config + * Config. * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository") * @ORM\Table @@ -15,7 +15,7 @@ use Symfony\Component\Validator\Constraints as Assert; class Config { /** - * @var integer + * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id @@ -32,7 +32,7 @@ class Config private $theme; /** - * @var integer + * @var int * * @Assert\NotBlank() * @Assert\Range( @@ -60,7 +60,7 @@ class Config private $rssToken; /** - * @var integer + * @var int * * @ORM\Column(name="rss_limit", type="integer", nullable=true) * @Assert\Range( @@ -85,9 +85,9 @@ class Config } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -95,9 +95,10 @@ class Config } /** - * Set theme + * Set theme. + * + * @param string $theme * - * @param string $theme * @return Config */ public function setTheme($theme) @@ -108,7 +109,7 @@ class Config } /** - * Get theme + * Get theme. * * @return string */ @@ -118,9 +119,10 @@ class Config } /** - * Set itemsPerPage + * Set itemsPerPage. + * + * @param int $itemsPerPage * - * @param integer $itemsPerPage * @return Config */ public function setItemsPerPage($itemsPerPage) @@ -131,9 +133,9 @@ class Config } /** - * Get itemsPerPage + * Get itemsPerPage. * - * @return integer + * @return int */ public function getItemsPerPage() { @@ -141,9 +143,10 @@ class Config } /** - * Set language + * Set language. + * + * @param string $language * - * @param string $language * @return Config */ public function setLanguage($language) @@ -154,7 +157,7 @@ class Config } /** - * Get language + * Get language. * * @return string */ @@ -164,9 +167,10 @@ class Config } /** - * Set user + * Set user. + * + * @param \Wallabag\CoreBundle\Entity\User $user * - * @param \Wallabag\CoreBundle\Entity\User $user * @return Config */ public function setUser(\Wallabag\CoreBundle\Entity\User $user = null) @@ -177,7 +181,7 @@ class Config } /** - * Get user + * Get user. * * @return \Wallabag\CoreBundle\Entity\User */ @@ -187,9 +191,10 @@ class Config } /** - * Set rssToken + * Set rssToken. + * + * @param string $rssToken * - * @param string $rssToken * @return Config */ public function setRssToken($rssToken) @@ -200,7 +205,7 @@ class Config } /** - * Get rssToken + * Get rssToken. * * @return string */ @@ -210,9 +215,10 @@ class Config } /** - * Set rssLimit + * Set rssLimit. + * + * @param string $rssLimit * - * @param string $rssLimit * @return Config */ public function setRssLimit($rssLimit) @@ -223,7 +229,7 @@ class Config } /** - * Get rssLimit + * Get rssLimit. * * @return string */ diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 15af105d..b1998ab6 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -9,7 +9,7 @@ use Hateoas\Configuration\Annotation as Hateoas; use JMS\Serializer\Annotation\XmlRoot; /** - * Entry + * Entry. * * @XmlRoot("entry") * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") @@ -21,7 +21,7 @@ class Entry { /** @Serializer\XmlAttribute */ /** - * @var integer + * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id @@ -45,14 +45,14 @@ class Entry private $url; /** - * @var boolean + * @var bool * * @ORM\Column(name="is_archived", type="boolean") */ private $isArchived = false; /** - * @var boolean + * @var bool * * @ORM\Column(name="is_starred", type="boolean") */ @@ -94,7 +94,7 @@ class Entry private $mimetype; /** - * @var integer + * @var int * * @ORM\Column(name="reading_type", type="integer", nullable=true) */ @@ -108,7 +108,7 @@ class Entry private $domainName; /** - * @var boolean + * @var bool * * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) */ @@ -135,9 +135,9 @@ class Entry } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -145,9 +145,10 @@ class Entry } /** - * Set title + * Set title. + * + * @param string $title * - * @param string $title * @return Entry */ public function setTitle($title) @@ -158,7 +159,7 @@ class Entry } /** - * Get title + * Get title. * * @return string */ @@ -168,9 +169,10 @@ class Entry } /** - * Set url + * Set url. + * + * @param string $url * - * @param string $url * @return Entry */ public function setUrl($url) @@ -181,7 +183,7 @@ class Entry } /** - * Get url + * Get url. * * @return string */ @@ -191,9 +193,10 @@ class Entry } /** - * Set isArchived + * Set isArchived. + * + * @param string $isArchived * - * @param string $isArchived * @return Entry */ public function setArchived($isArchived) @@ -204,7 +207,7 @@ class Entry } /** - * Get isArchived + * Get isArchived. * * @return string */ @@ -221,9 +224,10 @@ class Entry } /** - * Set isStarred + * Set isStarred. + * + * @param string $isStarred * - * @param string $isStarred * @return Entry */ public function setStarred($isStarred) @@ -234,7 +238,7 @@ class Entry } /** - * Get isStarred + * Get isStarred. * * @return string */ @@ -251,9 +255,10 @@ class Entry } /** - * Set content + * Set content. + * + * @param string $content * - * @param string $content * @return Entry */ public function setContent($content) @@ -264,7 +269,7 @@ class Entry } /** - * Get content + * Get content. * * @return string */ @@ -375,7 +380,7 @@ class Entry } /** - * @return boolean + * @return bool */ public function isPublic() { @@ -383,7 +388,7 @@ class Entry } /** - * @param boolean $isPublic + * @param bool $isPublic */ public function setPublic($isPublic) { diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 9d3c7a32..afe9e1b9 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -9,7 +9,7 @@ use JMS\Serializer\Annotation\Expose; use Doctrine\Common\Collections\ArrayCollection; /** - * Tag + * Tag. * * @XmlRoot("tag") * @ORM\Table @@ -19,7 +19,7 @@ use Doctrine\Common\Collections\ArrayCollection; class Tag { /** - * @var integer + * @var int * * @Expose * @ORM\Column(name="id", type="integer") @@ -52,9 +52,9 @@ class Tag $this->entries = new ArrayCollection(); } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -62,9 +62,10 @@ class Tag } /** - * Set label + * Set label. + * + * @param string $label * - * @param string $label * @return Tag */ public function setLabel($label) @@ -75,7 +76,7 @@ class Tag } /** - * Get label + * Get label. * * @return string */ diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index ff08c8fb..00eb808a 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -12,7 +12,7 @@ use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Expose; /** - * User + * User. * * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") * @ORM\Table @@ -25,7 +25,7 @@ use JMS\Serializer\Annotation\Expose; class User implements AdvancedUserInterface, \Serializable { /** - * @var integer + * @var int * * @Expose * @ORM\Column(name="id", type="integer") @@ -142,9 +142,9 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -152,9 +152,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set username + * Set username. + * + * @param string $username * - * @param string $username * @return User */ public function setUsername($username) @@ -165,7 +166,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get username + * Get username. * * @return string */ @@ -191,9 +192,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set password + * Set password. + * + * @param string $password * - * @param string $password * @return User */ public function setPassword($password) @@ -208,7 +210,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get password + * Get password. * * @return string */ @@ -218,9 +220,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set name + * Set name. + * + * @param string $name * - * @param string $name * @return User */ public function setName($name) @@ -231,7 +234,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get name + * Get name. * * @return string */ @@ -241,9 +244,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set email + * Set email. + * + * @param string $email * - * @param string $email * @return User */ public function setEmail($email) @@ -254,7 +258,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get email + * Get email. * * @return string */ @@ -341,8 +345,7 @@ class User implements AdvancedUserInterface, \Serializable public function unserialize($serialized) { list( - $this->id, - ) = unserialize($serialized); + $this->id) = unserialize($serialized); } public function isEqualTo(UserInterface $user) @@ -370,9 +373,10 @@ class User implements AdvancedUserInterface, \Serializable return $this->isActive; } /** - * Set config + * Set config. + * + * @param \Wallabag\CoreBundle\Entity\Config $config * - * @param \Wallabag\CoreBundle\Entity\Config $config * @return User */ public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null) @@ -383,7 +387,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get config + * Get config. * * @return \Wallabag\CoreBundle\Entity\Config */ @@ -393,9 +397,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set confirmationToken + * Set confirmationToken. + * + * @param string $confirmationToken * - * @param string $confirmationToken * @return User */ public function setConfirmationToken($confirmationToken) @@ -406,7 +411,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get confirmationToken + * Get confirmationToken. * * @return string */ @@ -416,9 +421,10 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Set passwordRequestedAt + * Set passwordRequestedAt. + * + * @param \DateTime $passwordRequestedAt * - * @param \DateTime $passwordRequestedAt * @return User */ public function setPasswordRequestedAt($passwordRequestedAt) @@ -429,7 +435,7 @@ class User implements AdvancedUserInterface, \Serializable } /** - * Get passwordRequestedAt + * Get passwordRequestedAt. * * @return \DateTime */ diff --git a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php index e141789f..b4224e3d 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ChangePasswordType.php @@ -1,4 +1,5 @@ array( 'timeout' => $timeout, - 'header' => "User-Agent: ".$useragent, + 'header' => 'User-Agent: '.$useragent, 'follow_location' => true, ), 'ssl' => array( @@ -91,9 +92,10 @@ final class Tools } /** - * Encode a URL by using a salt + * Encode a URL by using a salt. * * @param $string + * * @return string */ public static function encodeString($string) diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index a8c138a9..1335e808 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -10,7 +10,7 @@ use Pagerfanta\Pagerfanta; class EntryRepository extends EntityRepository { /** - * Retrieves unread entries for a user + * Retrieves unread entries for a user. * * @param int $userId * @param int $firstResult @@ -35,7 +35,7 @@ class EntryRepository extends EntityRepository } /** - * Retrieves read entries for a user + * Retrieves read entries for a user. * * @param int $userId * @param int $firstResult @@ -61,7 +61,7 @@ class EntryRepository extends EntityRepository } /** - * Retrieves starred entries for a user + * Retrieves starred entries for a user. * * @param int $userId * @param int $firstResult @@ -87,7 +87,7 @@ class EntryRepository extends EntityRepository } /** - * Find Entries + * Find Entries. * * @param int $userId * @param bool $isArchived diff --git a/src/Wallabag/CoreBundle/Repository/UserRepository.php b/src/Wallabag/CoreBundle/Repository/UserRepository.php index aab3dedc..968d0b49 100644 --- a/src/Wallabag/CoreBundle/Repository/UserRepository.php +++ b/src/Wallabag/CoreBundle/Repository/UserRepository.php @@ -7,7 +7,7 @@ use Doctrine\ORM\EntityRepository; class UserRepository extends EntityRepository { /** - * Find a user by its username and rss roken + * Find a user by its username and rss roken. * * @param string $username * @param string $rssToken diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php b/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php index fcfe418b..e7c81fc0 100644 --- a/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php +++ b/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php @@ -7,8 +7,7 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException; /** * This override just add en extra variable (username) to be able to salt the password - * the way Wallabag v1 does. It will avoid to break compatibility with Wallabag v1 - * + * the way Wallabag v1 does. It will avoid to break compatibility with Wallabag v1. */ class WallabagPasswordEncoder extends BasePasswordEncoder { diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php b/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php index 1c7c5fae..cf3cb051 100644 --- a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php +++ b/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php @@ -45,7 +45,7 @@ class WallabagAuthenticationProvider extends UserAuthenticationProvider throw new BadCredentialsException('The credentials were changed from another session.'); } } else { - if ("" === ($presentedPassword = $token->getCredentials())) { + if ('' === ($presentedPassword = $token->getCredentials())) { throw new BadCredentialsException('The presented password cannot be empty.'); } diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php index e4ec96f6..6d43a1da 100644 --- a/src/Wallabag/CoreBundle/Service/Extractor.php +++ b/src/Wallabag/CoreBundle/Service/Extractor.php @@ -9,7 +9,7 @@ final class Extractor { public static function extract($url) { - $pageContent = Extractor::getPageContent(new Url(base64_encode($url))); + $pageContent = self::getPageContent(new Url(base64_encode($url))); $title = $pageContent['rss']['channel']['item']['title'] ?: 'Untitled'; $body = $pageContent['rss']['channel']['item']['description']; @@ -21,9 +21,10 @@ final class Extractor } /** - * Get the content for a given URL (by a call to FullTextFeed) + * Get the content for a given URL (by a call to FullTextFeed). + * + * @param Url $url * - * @param Url $url * @return mixed */ public static function getPageContent(Url $url) @@ -49,12 +50,12 @@ final class Extractor $scope = function () { extract(func_get_arg(1)); $_GET = $_REQUEST = array( - "url" => $url->getUrl(), - "max" => 5, - "links" => "preserve", - "exc" => "", - "format" => "json", - "submit" => "Create Feed", + 'url' => $url->getUrl(), + 'max' => 5, + 'links' => 'preserve', + 'exc' => '', + 'format' => 'json', + 'submit' => 'Create Feed', ); ob_start(); require func_get_arg(0); @@ -67,11 +68,11 @@ final class Extractor // Silence $scope function to avoid // issues with FTRSS when error_reporting is to high // FTRSS generates PHP warnings which break output - $json = @$scope(__DIR__."/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url)); + $json = @$scope(__DIR__.'/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php', array('url' => $url)); // Clearing and restoring context foreach ($GLOBALS as $key => $value) { - if ($key != "GLOBALS" && $key != "_SESSION") { + if ($key != 'GLOBALS' && $key != '_SESSION') { unset($GLOBALS[$key]); } } diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index 8fa74491..7e2968e7 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -5,7 +5,7 @@ namespace Wallabag\CoreBundle\Tools; class Utils { /** - * Generate a token used for RSS + * Generate a token used for RSS. * * @return string */ diff --git a/src/Wallabag/CoreBundle/Twig/Extension/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/Extension/WallabagExtension.php index 92406865..18388948 100644 --- a/src/Wallabag/CoreBundle/Twig/Extension/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/Extension/WallabagExtension.php @@ -13,9 +13,10 @@ class WallabagExtension extends \Twig_Extension } /** - * Returns the domain name for a URL + * Returns the domain name for a URL. * * @param $url + * * @return string */ public static function getDomainName($url) @@ -24,9 +25,10 @@ class WallabagExtension extends \Twig_Extension } /** - * For a given text, we calculate reading time for an article + * For a given text, we calculate reading time for an article. * * @param $text + * * @return float */ public static function getReadingTime($text) -- cgit v1.2.3