summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-06-21 13:55:07 +0200
committerLukas Reschke <lukas@owncloud.com>2016-06-21 14:16:45 +0200
commit6affbdc6e7f57d52d63080d5fa0d7e332770831b (patch)
tree771dba148ded3d080d4611fcff066d78777f2e90 /apps/files_external/lib
parent097cba8b38331b578895cacb8cce9d2458a765cd (diff)
downloadnextcloud-server-6affbdc6e7f57d52d63080d5fa0d7e332770831b.tar.gz
nextcloud-server-6affbdc6e7f57d52d63080d5fa0d7e332770831b.zip
Add "Global Auth" option to external storage
This adds the "Global Auth" option to the external storage implementation, it is basically done by reverting c2c6caee93c491de9fa9a2e7c2eea036f4974e61 from https://github.com/owncloud/core/pull/22468. This was taken from owncloud/core which is AGPL licensed. Commited with "icewind@owncloud.com" to keep the license header signature in sync. ![2016-06-21_14-01-06](https://cloud.githubusercontent.com/assets/878997/16228662/9c243136-37b8-11e6-9700-c1076ddb3d17.png)
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/AppInfo/Application.php1
-rw-r--r--apps/files_external/lib/Controller/AjaxController.php20
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php88
3 files changed, 108 insertions, 1 deletions
diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php
index f78411038fa..ee773d03d8c 100644
--- a/apps/files_external/lib/AppInfo/Application.php
+++ b/apps/files_external/lib/AppInfo/Application.php
@@ -112,6 +112,7 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
// 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/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php
index c3df3fa8522..8dcfb2a47eb 100644
--- a/apps/files_external/lib/Controller/AjaxController.php
+++ b/apps/files_external/lib/Controller/AjaxController.php
@@ -24,6 +24,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;
@@ -32,10 +33,16 @@ 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 +68,15 @@ class AjaxController extends Controller {
'status' => 'success'
));
}
+
+ /**
+ * @param string $uid
+ * @param string $user
+ * @param string $password
+ * @return bool
+ */
+ public function saveGlobalCredentials($uid, $user, $password) {
+ $this->globalAuth->saveAuth($uid, $user, $password);
+ return true;
+ }
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
new file mode 100644
index 00000000000..5fa4dc5d1d4
--- /dev/null
+++ b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
@@ -0,0 +1,88 @@
+<?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\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 Credentials'));
+ }
+
+ 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']);
+ }
+ }
+
+}