From ea9ce1c04ac94c45b6fe959ef987598846a0a5fd Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 5 Jul 2018 18:53:12 +0200 Subject: [PATCH 1/2] PHRAS-2086_AdobeCC-AppToken_4.1 add an "adobe_cc-plugin" api application require system:upgrade to go to 4.1.0-alpha.10 must be enabled via "adobe_cc-enabled" in conf --- .../Command/Developer/RegenerateSqliteDb.php | 15 ++++ .../Core/Event/Listener/OAuthListener.php | 6 ++ .../Subscriber/PhraseaInstallSubscriber.php | 19 ++++ lib/Alchemy/Phrasea/Core/Version.php | 2 +- .../Manipulator/ApiApplicationManipulator.php | 7 ++ .../API/OAuth2/Application/AdobeCCPlugin.php | 17 ++++ lib/classes/patch/410alpha10a.php | 88 +++++++++++++++++++ 7 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 lib/classes/API/OAuth2/Application/AdobeCCPlugin.php create mode 100644 lib/classes/patch/410alpha10a.php diff --git a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php index a6d9606dee..9d1f07394f 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php +++ b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php @@ -251,6 +251,21 @@ class RegenerateSqliteDb extends Command $application->setClientSecret(\API_OAuth2_Application_OfficePlugin::CLIENT_SECRET); $this->container['manipulator.api-application']->update($application); + + $application = $this->container['manipulator.api-application']->create( + \API_OAuth2_Application_AdobeCCPlugin::CLIENT_NAME, + ApiApplication::DESKTOP_TYPE, + '', + 'http://www.phraseanet.com', + null, + ApiApplication::NATIVE_APP_REDIRECT_URI + ); + + $application->setGrantPassword(true); + $application->setClientId(\API_OAuth2_Application_AdobeCCPlugin::CLIENT_ID); + $application->setClientSecret(\API_OAuth2_Application_AdobeCCPlugin::CLIENT_SECRET); + + $this->container['manipulator.api-application']->update($application); } private function insertAuthFailures(EntityManager $em, \Pimple $DI) diff --git a/lib/Alchemy/Phrasea/Core/Event/Listener/OAuthListener.php b/lib/Alchemy/Phrasea/Core/Event/Listener/OAuthListener.php index ee8535f834..1ccbd0580a 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Listener/OAuthListener.php +++ b/lib/Alchemy/Phrasea/Core/Event/Listener/OAuthListener.php @@ -89,6 +89,12 @@ class OAuthListener return Result::createError($request, 403, 'The use of Office Plugin is not allowed.')->createResponse(); } + if ($oAuth2App->getClientId() == \API_OAuth2_Application_AdobeCCPlugin::CLIENT_ID + && !$conf->get(['registry', 'api-clients', 'adobe_cc-enabled']) + ) { + return Result::createError($request, 403, 'The use of AdobeCC Plugin is not allowed.')->createResponse(); + } + $authentication = $this->getAuthenticator($app); if ($authentication->isAuthenticated()) { diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php index 91d7efaaac..74912721b5 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php @@ -38,6 +38,7 @@ class PhraseaInstallSubscriber implements EventSubscriberInterface { $this->createNavigatorApplication(); $this->createOfficePluginApplication(); + $this->createAdobeCCPluginApplication(); $this->generateProxies(); } @@ -77,6 +78,24 @@ class PhraseaInstallSubscriber implements EventSubscriberInterface $this->app['manipulator.api-application']->update($application); } + private function createAdobeCCPluginApplication() + { + $application = $this->app['manipulator.api-application']->create( + \API_OAuth2_Application_AdobeCCPlugin::CLIENT_NAME, + ApiApplication::DESKTOP_TYPE, + '', + 'http://www.phraseanet.com', + null, + ApiApplication::NATIVE_APP_REDIRECT_URI + ); + + $application->setGrantPassword(true); + $application->setClientId(\API_OAuth2_Application_adobeCCPlugin::CLIENT_ID); + $application->setClientSecret(\API_OAuth2_Application_adobeCCPlugin::CLIENT_SECRET); + + $this->app['manipulator.api-application']->update($application); + } + private function generateProxies() { $process = new Process('php ' . $this->app['root.path']. '/bin/developer orm:generate:proxies'); diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index 1fbafcb5b7..f42332439b 100644 --- a/lib/Alchemy/Phrasea/Core/Version.php +++ b/lib/Alchemy/Phrasea/Core/Version.php @@ -16,7 +16,7 @@ class Version /** * @var string */ - private $number = '4.1.0-alpha.9'; + private $number = '4.1.0-alpha.10'; /** * @var string diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php index 7d45988f20..058db9cc5d 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php @@ -51,6 +51,13 @@ class ApiApplicationManipulator implements ManipulatorInterface return $application; } + public function findByClientID($client_id) + { + return $this->repository->findOneBy([ + 'clientId' => $client_id + ]); + } + public function delete(ApiApplication $application) { $this->om->remove($application); diff --git a/lib/classes/API/OAuth2/Application/AdobeCCPlugin.php b/lib/classes/API/OAuth2/Application/AdobeCCPlugin.php new file mode 100644 index 0000000000..e131df96a2 --- /dev/null +++ b/lib/classes/API/OAuth2/Application/AdobeCCPlugin.php @@ -0,0 +1,17 @@ +release; + } + + /** + * {@inheritdoc} + */ + public function getDoctrineMigrations() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function require_all_upgrades() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function concern() + { + return $this->concern; + } + + /** + * {@inheritdoc} + */ + public function apply(base $databox, Application $app) + { + // create an api application for adobeCC + + /** @var ApiApplicationManipulator $manipulator */ + $manipulator = $app['manipulator.api-application']; + + if($manipulator->findByClientID(\API_OAuth2_Application_adobeCCPlugin::CLIENT_ID) === null) { + + $application = $manipulator->create( + \API_OAuth2_Application_adobeCCPlugin::CLIENT_NAME, + ApiApplication::DESKTOP_TYPE, + '', + 'http://www.phraseanet.com', + null, + ApiApplication::NATIVE_APP_REDIRECT_URI + ); + + $application->setGrantPassword(true); + $application->setClientId(\API_OAuth2_Application_adobeCCPlugin::CLIENT_ID); + $application->setClientSecret(\API_OAuth2_Application_adobeCCPlugin::CLIENT_SECRET); + + $manipulator->update($application); + } + + return true; + } +} From 15f0a7017abcdd37d4d5807035a4db7506b6e21d Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Fri, 6 Jul 2018 15:55:04 +0200 Subject: [PATCH 2/2] PHRAS-2086_AdobeCC-AppToken_4.1 simplified --- .../Model/Manipulator/ApiApplicationManipulator.php | 7 ------- lib/classes/patch/410alpha10a.php | 9 ++++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php index 058db9cc5d..7d45988f20 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/ApiApplicationManipulator.php @@ -51,13 +51,6 @@ class ApiApplicationManipulator implements ManipulatorInterface return $application; } - public function findByClientID($client_id) - { - return $this->repository->findOneBy([ - 'clientId' => $client_id - ]); - } - public function delete(ApiApplication $application) { $this->om->remove($application); diff --git a/lib/classes/patch/410alpha10a.php b/lib/classes/patch/410alpha10a.php index 345fcfdf3a..962d6964c5 100644 --- a/lib/classes/patch/410alpha10a.php +++ b/lib/classes/patch/410alpha10a.php @@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator; use Alchemy\Phrasea\Model\Entities\ApiApplication; +use Alchemy\Phrasea\Model\Repositories\ApiApplicationRepository; class patch_410alpha10a implements patchInterface @@ -62,10 +63,12 @@ class patch_410alpha10a implements patchInterface { // create an api application for adobeCC - /** @var ApiApplicationManipulator $manipulator */ - $manipulator = $app['manipulator.api-application']; + /** @var ApiApplicationRepository $repo */ + $repo = $app['repo.api-applications']; + if(!$repo->findByClientId(\API_OAuth2_Application_adobeCCPlugin::CLIENT_ID)) { - if($manipulator->findByClientID(\API_OAuth2_Application_adobeCCPlugin::CLIENT_ID) === null) { + /** @var ApiApplicationManipulator $manipulator */ + $manipulator = $app['manipulator.api-application']; $application = $manipulator->create( \API_OAuth2_Application_adobeCCPlugin::CLIENT_NAME,