From c13e0861203ad61422eaf62df46db86dcadd60fd Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Mon, 26 Sep 2016 17:32:44 +0200 Subject: [PATCH] Add option to disable API via configuration setting --- config/configuration.sample.yml | 1 + lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php | 8 ++++++++ lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php | 8 ++++++++ lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 05b94d7c68..44dead3020 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -6,6 +6,7 @@ main: maintenance: false languages: [] key: '' + api_disable: false api_require_ssl: true api_disabled: true database: diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php index 21a344ed75..5977043b44 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Api\OAuth2Controller; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Silex\Application; use Silex\ControllerCollection; use Silex\ControllerProviderInterface; @@ -34,6 +35,13 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index d179c68d96..3136a1488f 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Api\V1Controller; use Alchemy\Phrasea\Controller\LazyLocator; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Silex\Application; use Silex\ControllerCollection; @@ -46,6 +47,13 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 7068e6c7ac..124f5c03b6 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -15,6 +15,7 @@ use Alchemy\Phrasea\Controller\Api\LazaretController; use Alchemy\Phrasea\Controller\Api\SearchController; use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Alchemy\Phrasea\Order\Controller\ApiOrderController; use Silex\Application; @@ -70,6 +71,13 @@ class V2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + $controllers = $this->createCollection($app); $controllers->before(new OAuthListener());