diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-02-03 18:29:24 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-02-04 14:57:17 +0100 |
commit | 9dfe9f77f294a00b65e7f93afc336df17dc221c9 (patch) | |
tree | f0ec873d4f9e2c42e3029073d8bc6484f6f97ba5 /apps/files_external | |
parent | 899444103a30a157a2112ca7389e9b047256b72d (diff) | |
download | nextcloud-server-9dfe9f77f294a00b65e7f93afc336df17dc221c9.tar.gz nextcloud-server-9dfe9f77f294a00b65e7f93afc336df17dc221c9.zip |
Add global auth backend for files external
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/appinfo/application.php | 1 | ||||
-rw-r--r-- | apps/files_external/appinfo/routes.php | 7 | ||||
-rw-r--r-- | apps/files_external/controller/ajaxcontroller.php | 10 | ||||
-rw-r--r-- | apps/files_external/js/settings.js | 27 | ||||
-rw-r--r-- | apps/files_external/lib/auth/password/globalauth.php | 85 | ||||
-rw-r--r-- | apps/files_external/lib/failedcache.php | 4 | ||||
-rw-r--r-- | apps/files_external/personal.php | 4 | ||||
-rw-r--r-- | apps/files_external/settings.php | 4 | ||||
-rw-r--r-- | apps/files_external/templates/settings.php | 17 |
9 files changed, 156 insertions, 3 deletions
diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php index 1bf258c48b4..d6552fa680c 100644 --- a/apps/files_external/appinfo/application.php +++ b/apps/files_external/appinfo/application.php @@ -110,6 +110,7 @@ class Application extends App { $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'), $container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'), $container->query('OCA\Files_External\Lib\Auth\Password\UserProvided'), + $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 c3149a300cf..d5b927c0227 100644 --- a/apps/files_external/appinfo/routes.php +++ b/apps/files_external/appinfo/routes.php @@ -44,7 +44,12 @@ namespace OCA\Files_External\AppInfo; '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 cfccacb03ea..86c1b657c91 100644 --- a/apps/files_external/controller/ajaxcontroller.php +++ b/apps/files_external/controller/ajaxcontroller.php @@ -23,6 +23,7 @@ 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; @@ -31,10 +32,13 @@ use OCA\Files_External\Lib\Auth\PublicKey\RSA; class AjaxController extends Controller { /** @var RSA */ private $rsaMechanism; + /** @var GlobalAuth */ + private $globalAuth; - public function __construct($appName, IRequest $request, RSA $rsaMechanism) { + public function __construct($appName, IRequest $request, RSA $rsaMechanism, GlobalAuth $globalAuth) { parent::__construct($appName, $request); $this->rsaMechanism = $rsaMechanism; + $this->globalAuth = $globalAuth; } private function generateSshKeys() { @@ -61,4 +65,8 @@ class AjaxController extends Controller { )); } + 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 26df203091e..0837555f534 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -1338,6 +1338,33 @@ $(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 new file mode 100644 index 00000000000..dcfea65b555 --- /dev/null +++ b/apps/files_external/lib/auth/password/globalauth.php @@ -0,0 +1,85 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\Files_External\Lib\Auth\Password; + +use OCA\Files_External\Lib\Auth\IUserProvided; +use OCA\Files_External\Lib\DefinitionParameter; +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 []; + } 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 = ''; + } 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/lib/failedcache.php b/apps/files_external/lib/failedcache.php index 9e24c12f4b5..f9866f43058 100644 --- a/apps/files_external/lib/failedcache.php +++ b/apps/files_external/lib/failedcache.php @@ -60,6 +60,10 @@ class FailedCache implements ICache { return; } + public function insert($file, array $data) { + return; + } + public function update($id, array $data) { return; } diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php index 4d8f480ecc0..f180b7e8f5c 100644 --- a/apps/files_external/personal.php +++ b/apps/files_external/personal.php @@ -30,6 +30,7 @@ use \OCA\Files_External\Service\BackendService; $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()); @@ -38,4 +39,7 @@ $tmpl->assign('storages', $userStoragesService->getStorages()); $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 0d83d26ff97..a5265c500d9 100644 --- a/apps/files_external/settings.php +++ b/apps/files_external/settings.php @@ -32,6 +32,7 @@ use \OCA\Files_External\Service\BackendService; $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'); @@ -44,4 +45,7 @@ $tmpl->assign('backends', $backendService->getAvailableBackends()); $tmpl->assign('authMechanisms', $backendService->getAuthMechanisms()); $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 f7caf3d2caa..8b453fe77c3 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -68,8 +68,23 @@ } } ?> -<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> +<form autocomplete="false" class="section" action="#" + id="global_credentials"> <h2><?php p($l->t('External Storage')); ?></h2> + <p><?php p($l->t('Global Credentials')); ?></p> + <input type="text" name="username" + autocomplete="false" + value="<?php p($_['globalCredentials']['user']); ?>" + placeholder="<?php p($l->t('Username')) ?>"/> + <input type="password" name="password" + autocomplete="false" + value="<?php p($_['globalCredentials']['password']); ?>" + placeholder="<?php p($l->t('Password')) ?>"/> + <input type="hidden" name="uid" + value="<?php p($_['globalCredentialsUid']); ?>"/> + <input type="submit" value="<?php p($l->t('Save')) ?>"/> +</form> +<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> <?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?> <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> <thead> |