From 3bb793b6a711c6dcba266982b8aea4c6d3fe4bc5 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:05:17 +0100 Subject: [PATCH 1/9] Implement password authentication mechanisms Introduces the basic password authentication mechanism, along with a mechanism based on ownCloud credentials stored in the user session. Change to lib/private is an extension of PermissionsMask, as isSharable() override was missing. Session credentials auth mechanism now disables sharing on applied storages, as credentials will not be available. --- apps/files_external/appinfo/application.php | 4 + .../lib/auth/password/password.php | 45 ++++++++++ .../lib/auth/password/sessioncredentials.php | 84 +++++++++++++++++++ .../lib/sessionstoragewrapper.php | 43 ++++++++++ .../files/storage/wrapper/permissionsmask.php | 4 + 5 files changed, 180 insertions(+) create mode 100644 apps/files_external/lib/auth/password/password.php create mode 100644 apps/files_external/lib/auth/password/sessioncredentials.php create mode 100644 apps/files_external/lib/sessionstoragewrapper.php diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index 38b9e9b7c36..d9c877a54d1 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -75,6 +75,10 @@ class Application extends App { // AuthMechanism::SCHEME_BUILTIN mechanism $container->query('OCA\Files_External\Lib\Auth\Builtin'), + + // AuthMechanism::SCHEME_PASSWORD mechanisms + $container->query('OCA\Files_External\Lib\Auth\Password\Password'), + $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'), ]); } diff --git a/apps/files_external/lib/auth/password/password.php b/apps/files_external/lib/auth/password/password.php new file mode 100644 index 00000000000..96ad4b496d4 --- /dev/null +++ b/apps/files_external/lib/auth/password/password.php @@ -0,0 +1,45 @@ + + * + * @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 \OCP\IL10N; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; + +/** + * Basic password authentication mechanism + */ +class Password extends AuthMechanism { + + public function __construct(IL10N $l) { + $this + ->setIdentifier('password::password') + ->setScheme(self::SCHEME_PASSWORD) + ->setText($l->t('Username and password')) + ->addParameters([ + (new DefinitionParameter('user', $l->t('Username'))), + (new DefinitionParameter('password', $l->t('Password'))) + ->setType(DefinitionParameter::VALUE_PASSWORD), + ]); + } + +} diff --git a/apps/files_external/lib/auth/password/sessioncredentials.php b/apps/files_external/lib/auth/password/sessioncredentials.php new file mode 100644 index 00000000000..37cfd97a176 --- /dev/null +++ b/apps/files_external/lib/auth/password/sessioncredentials.php @@ -0,0 +1,84 @@ + + * + * @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 \OCP\IL10N; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Lib\StorageConfig; +use \OCP\ISession; +use \OCP\Security\ICrypto; +use \OCP\Files\Storage; +use \OCA\Files_External\Lib\SessionStorageWrapper; +use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; + +/** + * Username and password from login credentials, saved in session + */ +class SessionCredentials extends AuthMechanism { + + /** @var ISession */ + protected $session; + + /** @var ICrypto */ + protected $crypto; + + public function __construct(IL10N $l, ISession $session, ICrypto $crypto) { + $this->session = $session; + $this->crypto = $crypto; + + $this + ->setIdentifier('password::sessioncredentials') + ->setScheme(self::SCHEME_PASSWORD) + ->setText($l->t('Session credentials')) + ->addParameters([ + ]) + ; + + \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); + } + + /** + * Hook listener on post login + * + * @param array $params + */ + public function authenticate(array $params) { + $this->session->set('password::sessioncredentials/credentials', $this->crypto->encrypt(json_encode($params))); + } + + public function manipulateStorageConfig(StorageConfig &$storage) { + $encrypted = $this->session->get('password::sessioncredentials/credentials'); + if (!isset($encrypted)) { + throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved'); + } + + $credentials = json_decode($this->crypto->decrypt($encrypted), true); + $storage->setBackendOption('user', $this->session->get('loginname')); + $storage->setBackendOption('password', $credentials['password']); + } + + public function wrapStorage(Storage $storage) { + return new SessionStorageWrapper(['storage' => $storage]); + } + +} diff --git a/apps/files_external/lib/sessionstoragewrapper.php b/apps/files_external/lib/sessionstoragewrapper.php new file mode 100644 index 00000000000..91be7eb1903 --- /dev/null +++ b/apps/files_external/lib/sessionstoragewrapper.php @@ -0,0 +1,43 @@ + + * + * @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; + +use \OCP\Files\Storage; +use \OC\Files\Storage\Wrapper\PermissionsMask; +use \OCP\Constants; + +/** + * Wrap Storage in PermissionsMask for session ephemeral use + */ +class SessionStorageWrapper extends PermissionsMask { + + /** + * @param array $arguments ['storage' => $storage] + */ + public function __construct(array $arguments) { + // disable sharing permission + $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE; + parent::__construct($arguments); + } + +} + diff --git a/lib/private/files/storage/wrapper/permissionsmask.php b/lib/private/files/storage/wrapper/permissionsmask.php index 993936321d0..50c3f2a6268 100644 --- a/lib/private/files/storage/wrapper/permissionsmask.php +++ b/lib/private/files/storage/wrapper/permissionsmask.php @@ -65,6 +65,10 @@ class PermissionsMask extends Wrapper { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); } + public function isSharable($path) { + return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($parm); + } + public function getPermissions($path) { return $this->storage->getPermissions($path) & $this->mask; } From 118cb7df1a906ce003fd80c1d64b357f45afcf02 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 19 Aug 2015 14:40:20 +0100 Subject: [PATCH 2/9] Allow builtin auth mechanism to be overridden The builtin mechanism is used exclusively for legacy external storages, which when upgraded to the new registration need to fallback to the defined legacy authentication mechanism instead. --- apps/files_external/service/storagesservice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php index e89af6bc756..f655d990454 100644 --- a/apps/files_external/service/storagesservice.php +++ b/apps/files_external/service/storagesservice.php @@ -87,7 +87,7 @@ abstract class StoragesService { } $storageConfig->setBackend($backend); - if (isset($storageOptions['authMechanism'])) { + if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); } else { $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); From 3b27603762e38f87d50b923e05cfb86c83b1ca1b Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Mon, 10 Aug 2015 23:20:27 +0100 Subject: [PATCH 3/9] Revert "Fix mounting wrapped storages resulting in many-layered wrapping" This reverts commit 75a5e6e12b18a9f5b7b113cd7e2c9c56c204084d. --- lib/private/files/mount/mountpoint.php | 7 +------ tests/lib/files/mount/mountpoint.php | 21 --------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php index 5e4949aa9dd..2871bbd9083 100644 --- a/lib/private/files/mount/mountpoint.php +++ b/lib/private/files/mount/mountpoint.php @@ -29,7 +29,6 @@ namespace OC\Files\Mount; use \OC\Files\Filesystem; use OC\Files\Storage\StorageFactory; use OC\Files\Storage\Storage; -use OC\Files\Storage\Wrapper\Wrapper; use OCP\Files\Mount\IMountPoint; class MountPoint implements IMountPoint { @@ -93,11 +92,7 @@ class MountPoint implements IMountPoint { $this->mountPoint = $mountpoint; if ($storage instanceof Storage) { $this->class = get_class($storage); - $this->storage = $storage; - // only wrap if not already wrapped - if (!($this->storage instanceof Wrapper)) { - $this->storage = $this->loader->wrap($this, $this->storage); - } + $this->storage = $this->loader->wrap($this, $storage); } else { // Update old classes to new namespace if (strpos($storage, 'OC_Filestorage_') !== false) { diff --git a/tests/lib/files/mount/mountpoint.php b/tests/lib/files/mount/mountpoint.php index d758c1b8d4d..29610e6058d 100644 --- a/tests/lib/files/mount/mountpoint.php +++ b/tests/lib/files/mount/mountpoint.php @@ -70,25 +70,4 @@ class MountPoint extends \Test\TestCase { // storage wrapper never called $this->assertFalse($called); } - - public function testWrappedStorage() { - $storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Wrapper') - ->disableOriginalConstructor() - ->getMock(); - - $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory'); - $loader->expects($this->never()) - ->method('getInstance'); - $loader->expects($this->never()) - ->method('wrap'); - - $mountPoint = new \OC\Files\Mount\MountPoint( - $storage, - '/mountpoint', - null, - $loader - ); - - $this->assertEquals($storage, $mountPoint->getStorage()); - } } From 0ffb51c6cc78b9c81b8b96f68d316673e43dfeaa Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 21:55:43 +0100 Subject: [PATCH 4/9] Migrate Local external storage to new API --- apps/files_external/appinfo/app.php | 12 ----- apps/files_external/appinfo/application.php | 6 ++- apps/files_external/lib/backend/local.php | 49 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 apps/files_external/lib/backend/local.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 4bdfd316799..6b9be44f368 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -70,18 +70,6 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == ' OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook'); OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login'); -OC_Mount_Config::registerBackend('\OC\Files\Storage\Local', [ - 'backend' => (string)$l->t('Local'), - 'priority' => 150, - 'configuration' => [ - 'datadir' => (string)$l->t('Location') - ], -]); -// Local must only be visible to the admin -$appContainer->query('OCA\Files_External\Service\BackendService') - ->getBackend('\OC\Files\Storage\Local') - ->setAllowedVisibility(\OCA\Files_External\Service\BackendService::VISIBILITY_ADMIN); - OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', [ 'backend' => (string)$l->t('Amazon S3'), 'priority' => 100, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index d9c877a54d1..f971b2ec635 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -28,8 +28,6 @@ use \OCA\Files_External\Controller\AjaxController; use \OCP\AppFramework\App; use \OCP\IContainer; use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\BackendConfig; -use \OCA\Files_External\Lib\BackendParameter; /** * @package OCA\Files_External\Appinfo @@ -60,6 +58,10 @@ class Application extends App { protected function loadBackends() { $container = $this->getContainer(); $service = $container->query('OCA\\Files_External\\Service\\BackendService'); + + $service->registerBackends([ + $container->query('OCA\Files_External\Lib\Backend\Local'), + ]); } /** diff --git a/apps/files_external/lib/backend/local.php b/apps/files_external/lib/backend/local.php new file mode 100644 index 00000000000..a80b437fab7 --- /dev/null +++ b/apps/files_external/lib/backend/local.php @@ -0,0 +1,49 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\Auth\NullMechanism; + +class Local extends Backend { + + public function __construct(IL10N $l, NullMechanism $legacyAuth) { + $this + ->setIdentifier('local') + ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat + ->setStorageClass('\OC\Files\Storage\Local') + ->setText($l->t('Local')) + ->addParameters([ + (new DefinitionParameter('datadir', $l->t('Location'))), + ]) + ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) + ->setPriority(BackendService::PRIORITY_DEFAULT + 50) + ->addAuthScheme(AuthMechanism::SCHEME_NULL) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} From 0f1809eced9296ab6b9cb9ea9084563781e74941 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:07:20 +0100 Subject: [PATCH 5/9] Migrate FTP external storage to new API --- apps/files_external/appinfo/app.php | 13 ----- apps/files_external/appinfo/application.php | 1 + apps/files_external/lib/backend/ftp.php | 53 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 apps/files_external/lib/backend/ftp.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 6b9be44f368..576a8be45c2 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -111,19 +111,6 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', [ 'has_dependencies' => true, ]); -OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', [ - 'backend' => 'FTP', - 'priority' => 100, - 'configuration' => [ - 'host' => (string)$l->t('Host'), - 'user' => (string)$l->t('Username'), - 'password' => '*'.$l->t('Password'), - 'root' => '&'.$l->t('Remote subfolder'), - 'secure' => '!'.$l->t('Secure ftps://') - ], - 'has_dependencies' => true, -]); - OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', [ 'backend' => 'Google Drive', 'priority' => 100, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index f971b2ec635..0e0c2f3e265 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -61,6 +61,7 @@ class Application extends App { $service->registerBackends([ $container->query('OCA\Files_External\Lib\Backend\Local'), + $container->query('OCA\Files_External\Lib\Backend\FTP'), ]); } diff --git a/apps/files_external/lib/backend/ftp.php b/apps/files_external/lib/backend/ftp.php new file mode 100644 index 00000000000..df6ca37679e --- /dev/null +++ b/apps/files_external/lib/backend/ftp.php @@ -0,0 +1,53 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class FTP extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('ftp') + ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat + ->setStorageClass('\OC\Files\Storage\FTP') + ->setText($l->t('FTP')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure ftps://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->setDependencyCheck('\OC\Files\Storage\FTP::checkDependencies') + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} From ab8c738b8d6de6ff984ec9d2397b92020a5c27c4 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:13:27 +0100 Subject: [PATCH 6/9] Migrate SMB external storage to new API --- apps/files_external/appinfo/app.php | 13 ------ apps/files_external/appinfo/application.php | 6 +++ apps/files_external/lib/backend/smb.php | 52 +++++++++++++++++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 apps/files_external/lib/backend/smb.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 576a8be45c2..8df0f3054c3 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -144,19 +144,6 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', [ if (!OC_Util::runningOnWindows()) { - OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB', [ - 'backend' => 'SMB / CIFS', - 'priority' => 100, - 'configuration' => [ - 'host' => (string)$l->t('Host'), - 'user' => (string)$l->t('Username'), - 'password' => '*'.$l->t('Password'), - 'share' => (string)$l->t('Share'), - 'root' => '&'.$l->t('Remote subfolder'), - ], - 'has_dependencies' => true, - ]); - OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', [ 'backend' => (string)$l->t('SMB / CIFS using OC login'), 'priority' => 90, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index 0e0c2f3e265..d930e8fc137 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -63,6 +63,12 @@ class Application extends App { $container->query('OCA\Files_External\Lib\Backend\Local'), $container->query('OCA\Files_External\Lib\Backend\FTP'), ]); + + if (!\OC_Util::runningOnWindows()) { + $service->registerBackends([ + $container->query('OCA\Files_External\Lib\Backend\SMB'), + ]); + } } /** diff --git a/apps/files_external/lib/backend/smb.php b/apps/files_external/lib/backend/smb.php new file mode 100644 index 00000000000..3d950a80c31 --- /dev/null +++ b/apps/files_external/lib/backend/smb.php @@ -0,0 +1,52 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class SMB extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('smb') + ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat + ->setStorageClass('\OC\Files\Storage\SMB') + ->setText($l->t('SMB / CIFS')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('share', $l->t('Share'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->setDependencyCheck('\OC\Files\Storage\SMB::checkDependencies') + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} From 68418bdd34c92c17c1e7241fe6f1c5cfe5392178 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:16:46 +0100 Subject: [PATCH 7/9] Migrate DAV external storage to new API --- apps/files_external/appinfo/app.php | 13 ----- apps/files_external/appinfo/application.php | 1 + apps/files_external/lib/backend/dav.php | 53 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 apps/files_external/lib/backend/dav.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 8df0f3054c3..62fcdba583f 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -157,19 +157,6 @@ if (!OC_Util::runningOnWindows()) { ]); } -OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', [ - 'backend' => 'WebDAV', - 'priority' => 100, - 'configuration' => [ - 'host' => (string)$l->t('URL'), - 'user' => (string)$l->t('Username'), - 'password' => '*'.$l->t('Password'), - 'root' => '&'.$l->t('Remote subfolder'), - 'secure' => '!'.$l->t('Secure https://'), - ], - 'has_dependencies' => true, -]); - OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', [ 'backend' => 'ownCloud', 'priority' => 100, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index d930e8fc137..2a9618655bb 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -62,6 +62,7 @@ class Application extends App { $service->registerBackends([ $container->query('OCA\Files_External\Lib\Backend\Local'), $container->query('OCA\Files_External\Lib\Backend\FTP'), + $container->query('OCA\Files_External\Lib\Backend\DAV'), ]); if (!\OC_Util::runningOnWindows()) { diff --git a/apps/files_external/lib/backend/dav.php b/apps/files_external/lib/backend/dav.php new file mode 100644 index 00000000000..5ae6d122588 --- /dev/null +++ b/apps/files_external/lib/backend/dav.php @@ -0,0 +1,53 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class DAV extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('dav') + ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat + ->setStorageClass('\OC\Files\Storage\DAV') + ->setText($l->t('WebDAV')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('URL'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure https://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->setDependencyCheck('\OC\Files\Storage\DAV::checkDependencies') + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} From a99e52489892299e2b3148fbde46ce3790c34124 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:17:50 +0100 Subject: [PATCH 8/9] Migrate OwnCloud external storage to new API --- apps/files_external/appinfo/app.php | 13 ----- apps/files_external/appinfo/application.php | 1 + apps/files_external/lib/backend/owncloud.php | 52 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 apps/files_external/lib/backend/owncloud.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 62fcdba583f..aa10b9b300f 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -157,19 +157,6 @@ if (!OC_Util::runningOnWindows()) { ]); } -OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', [ - 'backend' => 'ownCloud', - 'priority' => 100, - 'configuration' => [ - 'host' => (string)$l->t('URL'), - 'user' => (string)$l->t('Username'), - 'password' => '*'.$l->t('Password'), - 'root' => '&'.$l->t('Remote subfolder'), - 'secure' => '!'.$l->t('Secure https://'), - ], -]); - - OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', [ 'backend' => 'SFTP', 'priority' => 100, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index 2a9618655bb..93ecbd50b29 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -63,6 +63,7 @@ class Application extends App { $container->query('OCA\Files_External\Lib\Backend\Local'), $container->query('OCA\Files_External\Lib\Backend\FTP'), $container->query('OCA\Files_External\Lib\Backend\DAV'), + $container->query('OCA\Files_External\Lib\Backend\OwnCloud'), ]); if (!\OC_Util::runningOnWindows()) { diff --git a/apps/files_external/lib/backend/owncloud.php b/apps/files_external/lib/backend/owncloud.php new file mode 100644 index 00000000000..d06625de241 --- /dev/null +++ b/apps/files_external/lib/backend/owncloud.php @@ -0,0 +1,52 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class OwnCloud extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('owncloud') + ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat + ->setStorageClass('\OC\Files\Storage\OwnCloud') + ->setText($l->t('ownCloud')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('URL'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure https://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} From 16389270ffc36becba628002a80789acfb2eb83d Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 12 Aug 2015 22:19:32 +0100 Subject: [PATCH 9/9] Migrate SFTP external storage to new API --- apps/files_external/appinfo/app.php | 11 ----- apps/files_external/appinfo/application.php | 1 + apps/files_external/lib/backend/sftp.php | 50 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 apps/files_external/lib/backend/sftp.php diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index aa10b9b300f..3d8e610db4d 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -157,17 +157,6 @@ if (!OC_Util::runningOnWindows()) { ]); } -OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', [ - 'backend' => 'SFTP', - 'priority' => 100, - 'configuration' => [ - 'host' => (string)$l->t('Host'), - 'user' => (string)$l->t('Username'), - 'password' => '*'.$l->t('Password'), - 'root' => '&'.$l->t('Remote subfolder'), - ], -]); - OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP_Key', [ 'backend' => (string)$l->t('SFTP with secret key login'), 'priority' => 100, diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index 93ecbd50b29..4520a8737be 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -64,6 +64,7 @@ class Application extends App { $container->query('OCA\Files_External\Lib\Backend\FTP'), $container->query('OCA\Files_External\Lib\Backend\DAV'), $container->query('OCA\Files_External\Lib\Backend\OwnCloud'), + $container->query('OCA\Files_External\Lib\Backend\SFTP'), ]); if (!\OC_Util::runningOnWindows()) { diff --git a/apps/files_external/lib/backend/sftp.php b/apps/files_external/lib/backend/sftp.php new file mode 100644 index 00000000000..dd0f5d8e2e0 --- /dev/null +++ b/apps/files_external/lib/backend/sftp.php @@ -0,0 +1,50 @@ + + * + * @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\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class SFTP extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('sftp') + ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat + ->setStorageClass('\OC\Files\Storage\SFTP') + ->setText($l->t('SFTP')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('root', $l->t('Root'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +}