From c2c6caee93c491de9fa9a2e7c2eea036f4974e61 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 17 Feb 2016 13:55:27 +0100 Subject: [PATCH] remove global credentials --- apps/files_external/appinfo/application.php | 1 - apps/files_external/appinfo/routes.php | 7 +- .../controller/ajaxcontroller.php | 11 +- apps/files_external/js/settings.js | 27 ---- .../lib/auth/password/globalauth.php | 88 ------------- apps/files_external/personal.php | 4 - apps/files_external/settings.php | 3 - apps/files_external/templates/settings.php | 17 +-- .../tests/auth/password/globalauth.php | 117 ------------------ 9 files changed, 3 insertions(+), 272 deletions(-) delete mode 100644 apps/files_external/lib/auth/password/globalauth.php delete mode 100644 apps/files_external/tests/auth/password/globalauth.php diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index df7ba35748927..c755b6a29b09e 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -108,7 +108,6 @@ protected function loadAuthMechanisms() { // AuthMechanism::SCHEME_PASSWORD mechanisms $container->query('OCA\Files_External\Lib\Auth\Password\Password'), $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'), - $container->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'), // AuthMechanism::SCHEME_OAUTH1 mechanisms $container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'), diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php index d5b927c022755..c3149a300cff8 100644 --- a/apps/files_external/appinfo/routes.php +++ b/apps/files_external/appinfo/routes.php @@ -44,12 +44,7 @@ 'url' => '/ajax/public_key.php', 'verb' => 'POST', 'requirements' => array() - ), - [ - 'name' => 'Ajax#saveGlobalCredentials', - 'url' => '/globalcredentials', - 'verb' => 'POST' - ] + ) ) ) ); diff --git a/apps/files_external/controller/ajaxcontroller.php b/apps/files_external/controller/ajaxcontroller.php index 86c1b657c91f2..67c32422b1ccc 100644 --- a/apps/files_external/controller/ajaxcontroller.php +++ b/apps/files_external/controller/ajaxcontroller.php @@ -23,7 +23,6 @@ namespace OCA\Files_External\Controller; -use OCA\Files_External\Lib\Auth\Password\GlobalAuth; use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\AppFramework\Http\JSONResponse; @@ -32,13 +31,10 @@ class AjaxController extends Controller { /** @var RSA */ private $rsaMechanism; - /** @var GlobalAuth */ - private $globalAuth; - public function __construct($appName, IRequest $request, RSA $rsaMechanism, GlobalAuth $globalAuth) { + public function __construct($appName, IRequest $request, RSA $rsaMechanism) { parent::__construct($appName, $request); $this->rsaMechanism = $rsaMechanism; - $this->globalAuth = $globalAuth; } private function generateSshKeys() { @@ -64,9 +60,4 @@ public function getSshKeys() { 'status' => 'success' )); } - - public function saveGlobalCredentials($uid, $user, $password) { - $this->globalAuth->saveAuth($uid, $user, $password); - return true; - } } diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 0837555f534b2..26df203091e33 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -1338,33 +1338,6 @@ $(document).ready(function() { } }); - $('#global_credentials').on('submit', function() { - var $form = $(this); - var uid = $form.find('[name=uid]').val(); - var user = $form.find('[name=username]').val(); - var password = $form.find('[name=password]').val(); - var $submit = $form.find('[type=submit]'); - $submit.val(t('files_external', 'Saving...')); - $.ajax({ - type: 'POST', - contentType: 'application/json', - data: JSON.stringify({ - uid: uid, - user: user, - password: password - }), - url: OC.generateUrl('apps/files_external/globalcredentials'), - dataType: 'json', - success: function() { - $submit.val(t('files_external', 'Saved')); - setTimeout(function(){ - $submit.val(t('files_external', 'Save')); - }, 2500); - } - }); - return false; - }); - // global instance OCA.External.Settings.mountConfig = mountConfigListView; diff --git a/apps/files_external/lib/auth/password/globalauth.php b/apps/files_external/lib/auth/password/globalauth.php deleted file mode 100644 index c6faee0610913..0000000000000 --- a/apps/files_external/lib/auth/password/globalauth.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Auth\Password; - -use OCA\Files_External\Service\BackendService; -use OCP\IL10N; -use OCP\IUser; -use OCA\Files_External\Lib\Auth\AuthMechanism; -use OCA\Files_External\Lib\StorageConfig; -use OCP\Security\ICredentialsManager; -use OCP\Files\Storage; -use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; - -/** - * Global Username and Password - */ -class GlobalAuth extends AuthMechanism { - - const CREDENTIALS_IDENTIFIER = 'password::global'; - - /** @var ICredentialsManager */ - protected $credentialsManager; - - public function __construct(IL10N $l, ICredentialsManager $credentialsManager) { - $this->credentialsManager = $credentialsManager; - - $this - ->setIdentifier('password::global') - ->setVisibility(BackendService::VISIBILITY_DEFAULT) - ->setScheme(self::SCHEME_PASSWORD) - ->setText($l->t('Global Credentails')); - } - - public function getAuth($uid) { - $auth = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); - if (!is_array($auth)) { - return [ - 'user' => '', - 'password' => '' - ]; - } else { - return $auth; - } - } - - public function saveAuth($uid, $user, $password) { - $this->credentialsManager->store($uid, self::CREDENTIALS_IDENTIFIER, [ - 'user' => $user, - 'password' => $password - ]); - } - - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { - if ($storage->getType() === StorageConfig::MOUNT_TYPE_ADMIN) { - $uid = ''; - } elseif (is_null($user)) { - throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); - } else { - $uid = $user->getUID(); - } - $credentials = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); - - if (is_array($credentials)) { - $storage->setBackendOption('user', $credentials['user']); - $storage->setBackendOption('password', $credentials['password']); - } - } - -} diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php index f180b7e8f5c98..4d8f480ecc03d 100644 --- a/apps/files_external/personal.php +++ b/apps/files_external/personal.php @@ -30,7 +30,6 @@ $appContainer = \OC_Mount_Config::$app->getContainer(); $backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); $userStoragesService = $appContainer->query('OCA\Files_external\Service\UserStoragesService'); -$globalAuth = $appContainer->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'); $tmpl = new OCP\Template('files_external', 'settings'); $tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); @@ -39,7 +38,4 @@ $tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends())); $tmpl->assign('backends', $backendService->getAvailableBackends()); $tmpl->assign('authMechanisms', $backendService->getAuthMechanisms()); -$uid = \OC::$server->getUserSession()->getUser()->getUID(); -$tmpl->assign('globalCredentials', $globalAuth->getAuth($uid)); -$tmpl->assign('globalCredentialsUid', $uid); return $tmpl->fetchPage(); diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php index a5265c500d9fc..5bc330ff1897c 100644 --- a/apps/files_external/settings.php +++ b/apps/files_external/settings.php @@ -32,7 +32,6 @@ $appContainer = \OC_Mount_Config::$app->getContainer(); $backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); $globalStoragesService = $appContainer->query('OCA\Files_external\Service\GlobalStoragesService'); -$globalAuth = $appContainer->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'); \OC_Util::addVendorScript('select2/select2'); \OC_Util::addVendorStyle('select2/select2'); @@ -46,6 +45,4 @@ $tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends())); $tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed()); $tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed()); -$tmpl->assign('globalCredentials', $globalAuth->getAuth('')); -$tmpl->assign('globalCredentialsUid', ''); return $tmpl->fetchPage(); diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 8b453fe77c37c..f7caf3d2caa49 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -68,23 +68,8 @@ function writeParameterInput($parameter, $options, $classes = []) { } } ?> -
-

t('External Storage')); ?>

-

t('Global Credentials')); ?>

- - - - -
+

t('External Storage')); ?>

'')) print_unescaped(''.$_['dependencies'].''); ?> '> diff --git a/apps/files_external/tests/auth/password/globalauth.php b/apps/files_external/tests/auth/password/globalauth.php deleted file mode 100644 index 912bfd1574d3e..0000000000000 --- a/apps/files_external/tests/auth/password/globalauth.php +++ /dev/null @@ -1,117 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Tests\Auth\Password; - -use OCA\Files_External\Lib\Auth\Password\GlobalAuth; -use OCA\Files_external\Lib\StorageConfig; -use Test\TestCase; - -class GlobalAuthTest extends TestCase { - /** - * @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject - */ - private $l10n; - - /** - * @var \OCP\Security\ICredentialsManager|\PHPUnit_Framework_MockObject_MockObject - */ - private $credentialsManager; - - /** - * @var GlobalAuth - */ - private $instance; - - protected function setUp() { - parent::setUp(); - $this->l10n = $this->getMock('\OCP\IL10N'); - $this->credentialsManager = $this->getMock('\OCP\Security\ICredentialsManager'); - $this->instance = new GlobalAuth($this->l10n, $this->credentialsManager); - } - - private function getStorageConfig($type, $config = []) { - /** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit_Framework_MockObject_MockObject $storageConfig */ - $storageConfig = $this->getMock('\OCA\Files_External\Lib\StorageConfig'); - $storageConfig->expects($this->any()) - ->method('getType') - ->will($this->returnValue($type)); - $storageConfig->expects($this->any()) - ->method('getBackendOptions') - ->will($this->returnCallback(function () use (&$config) { - return $config; - })); - $storageConfig->expects($this->any()) - ->method('getBackendOption') - ->will($this->returnCallback(function ($key) use (&$config) { - return $config[$key]; - })); - $storageConfig->expects($this->any()) - ->method('setBackendOption') - ->will($this->returnCallback(function ($key, $value) use (&$config) { - $config[$key] = $value; - })); - - return $storageConfig; - } - - public function testNoCredentials() { - $this->credentialsManager->expects($this->once()) - ->method('retrieve') - ->will($this->returnValue(null)); - - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); - - $this->instance->manipulateStorageConfig($storage); - $this->assertEquals([], $storage->getBackendOptions()); - } - - public function testSavedCredentials() { - $this->credentialsManager->expects($this->once()) - ->method('retrieve') - ->will($this->returnValue([ - 'user' => 'a', - 'password' => 'b' - ])); - - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN); - - $this->instance->manipulateStorageConfig($storage); - $this->assertEquals([ - 'user' => 'a', - 'password' => 'b' - ], $storage->getBackendOptions()); - } - - /** - * @expectedException \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException - */ - public function testNoCredentialsPersonal() { - $this->credentialsManager->expects($this->never()) - ->method('retrieve'); - - $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAl); - - $this->instance->manipulateStorageConfig($storage); - $this->assertEquals([], $storage->getBackendOptions()); - } - -}