aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib/Auth/Password
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Lib/Auth/Password')
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php58
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php146
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/Password.php35
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php62
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/UserGlobalAuth.php73
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/UserProvided.php62
6 files changed, 244 insertions, 192 deletions
diff --git a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
index 3c5798ccee7..916b496b506 100644
--- a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
+++ b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
@@ -1,50 +1,31 @@
<?php
+
/**
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Lib\Auth\Password;
+use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
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 {
+ public const CREDENTIALS_IDENTIFIER = 'password::global';
+ private const PWD_PLACEHOLDER = '************************';
- const CREDENTIALS_IDENTIFIER = 'password::global';
-
- /** @var ICredentialsManager */
- protected $credentialsManager;
-
- public function __construct(IL10N $l, ICredentialsManager $credentialsManager) {
- $this->credentialsManager = $credentialsManager;
-
+ public function __construct(
+ IL10N $l,
+ protected ICredentialsManager $credentialsManager,
+ ) {
$this
->setIdentifier('password::global')
->setVisibility(BackendService::VISIBILITY_DEFAULT)
@@ -60,18 +41,28 @@ class GlobalAuth extends AuthMechanism {
'password' => ''
];
} else {
+ $auth['password'] = self::PWD_PLACEHOLDER;
return $auth;
}
}
public function saveAuth($uid, $user, $password) {
+ // Use old password if it has not changed.
+ if ($password === self::PWD_PLACEHOLDER) {
+ $auth = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER);
+ $password = $auth['password'];
+ }
+
$this->credentialsManager->store($uid, self::CREDENTIALS_IDENTIFIER, [
'user' => $user,
'password' => $password
]);
}
- public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ /**
+ * @return void
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
if ($storage->getType() === StorageConfig::MOUNT_TYPE_ADMIN) {
$uid = '';
} elseif (is_null($user)) {
@@ -86,5 +77,4 @@ class GlobalAuth extends AuthMechanism {
$storage->setBackendOption('password', $credentials['password']);
}
}
-
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
index 80703b52a9a..ce38140b6ee 100644
--- a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
+++ b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
@@ -1,93 +1,113 @@
<?php
+
/**
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Lib\Auth\Password;
-use \OCP\IL10N;
-use \OCP\IUser;
-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\ICredentialsManager;
-use \OCP\Files\Storage;
-use \OCA\Files_External\Lib\SessionStorageWrapper;
-use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\DefinitionParameter;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Listener\StorePasswordListener;
+use OCP\Authentication\Exceptions\CredentialsUnavailableException;
+use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IL10N;
+use OCP\ISession;
+use OCP\IUser;
+use OCP\IUserBackend;
+use OCP\LDAP\ILDAPProviderFactory;
+use OCP\Security\ICredentialsManager;
+use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\UserLoggedInEvent;
/**
* Username and password from login credentials, saved in DB
*/
class LoginCredentials extends AuthMechanism {
+ public const CREDENTIALS_IDENTIFIER = 'password::logincredentials/credentials';
- const CREDENTIALS_IDENTIFIER = 'password::logincredentials/credentials';
-
- /** @var ISession */
- protected $session;
-
- /** @var ICredentialsManager */
- protected $credentialsManager;
-
- public function __construct(IL10N $l, ISession $session, ICredentialsManager $credentialsManager) {
- $this->session = $session;
- $this->credentialsManager = $credentialsManager;
-
+ public function __construct(
+ IL10N $l,
+ protected ISession $session,
+ protected ICredentialsManager $credentialsManager,
+ private CredentialsStore $credentialsStore,
+ IEventDispatcher $eventDispatcher,
+ private ILDAPProviderFactory $ldapFactory,
+ ) {
$this
->setIdentifier('password::logincredentials')
->setScheme(self::SCHEME_PASSWORD)
->setText($l->t('Log-in credentials, save in database'))
->addParameters([
- ])
- ;
+ (new DefinitionParameter('password', $l->t('Password')))
+ ->setType(DefinitionParameter::VALUE_PASSWORD)
+ ->setFlag(DefinitionParameter::FLAG_HIDDEN)
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ]);
- \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
+ $eventDispatcher->addServiceListener(UserLoggedInEvent::class, StorePasswordListener::class);
+ $eventDispatcher->addServiceListener(PasswordUpdatedEvent::class, StorePasswordListener::class);
}
- /**
- * Hook listener on post login
- *
- * @param array $params
- */
- public function authenticate(array $params) {
- $userId = $params['uid'];
- $credentials = [
- 'user' => $this->session->get('loginname'),
- 'password' => $params['password']
- ];
- $this->credentialsManager->store($userId, self::CREDENTIALS_IDENTIFIER, $credentials);
+ private function getCredentials(IUser $user): array {
+ $credentials = $this->credentialsManager->retrieve($user->getUID(), self::CREDENTIALS_IDENTIFIER);
+
+ if (is_null($credentials)) {
+ // nothing saved in db, try to get it from the session and save it
+ try {
+ $sessionCredentials = $this->credentialsStore->getLoginCredentials();
+
+ if ($sessionCredentials->getUID() !== $user->getUID()) {
+ // Can't take the credentials from the session as they are not the same user
+ throw new CredentialsUnavailableException();
+ }
+
+ $credentials = [
+ 'user' => $sessionCredentials->getLoginName(),
+ 'password' => $sessionCredentials->getPassword(),
+ ];
+
+ $this->credentialsManager->store($user->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials);
+ } catch (CredentialsUnavailableException $e) {
+ throw new InsufficientDataForMeaningfulAnswerException('No login credentials saved');
+ }
+ }
+
+ return $credentials;
}
- public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ /**
+ * @return void
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
if (!isset($user)) {
throw new InsufficientDataForMeaningfulAnswerException('No login credentials saved');
}
- $uid = $user->getUID();
- $credentials = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER);
+ $credentials = $this->getCredentials($user);
- if (!isset($credentials)) {
- throw new InsufficientDataForMeaningfulAnswerException('No login credentials saved');
+ $loginKey = $storage->getBackendOption('login_ldap_attr');
+ if ($loginKey) {
+ $backend = $user->getBackend();
+ if ($backend instanceof IUserBackend && $backend->getBackendName() === 'LDAP') {
+ $value = $this->getLdapPropertyForUser($user, $loginKey);
+ if ($value === null) {
+ throw new InsufficientDataForMeaningfulAnswerException('Custom ldap attribute not set for user ' . $user->getUID());
+ }
+ $storage->setBackendOption('user', $value);
+ } else {
+ throw new InsufficientDataForMeaningfulAnswerException('Custom ldap attribute configured but user ' . $user->getUID() . ' is not an ldap user');
+ }
+ } else {
+ $storage->setBackendOption('user', $credentials['user']);
}
-
- $storage->setBackendOption('user', $credentials['user']);
$storage->setBackendOption('password', $credentials['password']);
}
+ private function getLdapPropertyForUser(IUser $user, string $property): ?string {
+ return $this->ldapFactory->getLDAPProvider()->getUserAttribute($user->getUID(), $property);
+ }
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/Password.php b/apps/files_external/lib/Lib/Auth/Password/Password.php
index cf8d6b9f458..d4291148e3e 100644
--- a/apps/files_external/lib/Lib/Auth/Password/Password.php
+++ b/apps/files_external/lib/Lib/Auth/Password/Password.php
@@ -1,46 +1,29 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
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\Auth\AuthMechanism;
+use OCA\Files_External\Lib\DefinitionParameter;
+use OCP\IL10N;
/**
* 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'))
+ ->setText($l->t('Login and password'))
->addParameters([
- (new DefinitionParameter('user', $l->t('Username'))),
+ new DefinitionParameter('user', $l->t('Login')),
(new DefinitionParameter('password', $l->t('Password')))
->setType(DefinitionParameter::VALUE_PASSWORD),
]);
}
-
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php
index 9f1ad9e4a32..8f161073771 100644
--- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php
+++ b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php
@@ -1,36 +1,21 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@owncloud.com>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Lib\Auth\Password;
use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\DefinitionParameter;
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCA\Files_External\Lib\SessionStorageWrapper;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
-use OCP\Files\Storage;
+use OCP\Files\Storage\IStorage;
+use OCP\Files\StorageAuthException;
use OCP\IL10N;
use OCP\IUser;
@@ -39,31 +24,44 @@ use OCP\IUser;
*/
class SessionCredentials extends AuthMechanism {
- /** @var CredentialsStore */
- private $credentialsStore;
-
- public function __construct(IL10N $l, CredentialsStore $credentialsStore) {
- $this->credentialsStore = $credentialsStore;
-
+ public function __construct(
+ IL10N $l,
+ private CredentialsStore $credentialsStore,
+ ) {
$this->setIdentifier('password::sessioncredentials')
->setScheme(self::SCHEME_PASSWORD)
->setText($l->t('Log-in credentials, save in session'))
- ->addParameters([]);
+ ->addParameters([
+ (new DefinitionParameter('password', $l->t('Password')))
+ ->setType(DefinitionParameter::VALUE_PASSWORD)
+ ->setFlag(DefinitionParameter::FLAG_HIDDEN)
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ]);
}
- public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ /**
+ * @return void
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
try {
$credentials = $this->credentialsStore->getLoginCredentials();
} catch (CredentialsUnavailableException $e) {
throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
}
+ if ($user === null) {
+ throw new StorageAuthException('Session unavailable');
+ }
+
+ if ($credentials->getUID() !== $user->getUID()) {
+ throw new StorageAuthException('Session credentials for storage owner not available');
+ }
+
$storage->setBackendOption('user', $credentials->getLoginName());
$storage->setBackendOption('password', $credentials->getPassword());
}
- public function wrapStorage(Storage $storage) {
+ public function wrapStorage(IStorage $storage): IStorage {
return new SessionStorageWrapper(['storage' => $storage]);
}
-
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/UserGlobalAuth.php b/apps/files_external/lib/Lib/Auth/Password/UserGlobalAuth.php
new file mode 100644
index 00000000000..cb7165261ac
--- /dev/null
+++ b/apps/files_external/lib/Lib/Auth/Password/UserGlobalAuth.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_External\Lib\Auth\Password;
+
+use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\DefinitionParameter;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Service\BackendService;
+use OCP\IL10N;
+use OCP\IUser;
+use OCP\Security\ICredentialsManager;
+
+/**
+ * User provided Global Username and Password
+ */
+class UserGlobalAuth extends AuthMechanism {
+ private const CREDENTIALS_IDENTIFIER = 'password::global';
+
+ public function __construct(
+ IL10N $l,
+ protected ICredentialsManager $credentialsManager,
+ ) {
+ $this
+ ->setIdentifier('password::global::user')
+ ->setVisibility(BackendService::VISIBILITY_DEFAULT)
+ ->setScheme(self::SCHEME_PASSWORD)
+ ->setText($l->t('Global credentials, manually entered'));
+ }
+
+ public function saveBackendOptions(IUser $user, $id, $backendOptions) {
+ // backendOptions are set when invoked via Files app
+ // but they are not set when invoked via ext storage settings
+ if (!isset($backendOptions['user']) && !isset($backendOptions['password'])) {
+ return;
+ }
+
+ if ($backendOptions['password'] === DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
+ $oldCredentials = $this->credentialsManager->retrieve($user->getUID(), self::CREDENTIALS_IDENTIFIER);
+ $backendOptions['password'] = $oldCredentials['password'];
+ }
+
+ // make sure we're not setting any unexpected keys
+ $credentials = [
+ 'user' => $backendOptions['user'],
+ 'password' => $backendOptions['password'],
+ ];
+ $this->credentialsManager->store($user->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials);
+ }
+
+ /**
+ * @return void
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
+ if ($user === null) {
+ throw new InsufficientDataForMeaningfulAnswerException('No credentials saved');
+ }
+
+ $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/Lib/Auth/Password/UserProvided.php b/apps/files_external/lib/Lib/Auth/Password/UserProvided.php
index 7eb2f63e7d3..b158392f6eb 100644
--- a/apps/files_external/lib/Lib/Auth/Password/UserProvided.php
+++ b/apps/files_external/lib/Lib/Auth/Password/UserProvided.php
@@ -1,58 +1,39 @@
<?php
+
/**
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Lib\Auth\Password;
+use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\IUserProvided;
use OCA\Files_External\Lib\DefinitionParameter;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
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;
/**
* User provided Username and Password
*/
class UserProvided extends AuthMechanism implements IUserProvided {
+ public const CREDENTIALS_IDENTIFIER_PREFIX = 'password::userprovided/';
- const CREDENTIALS_IDENTIFIER_PREFIX = 'password::userprovided/';
-
- /** @var ICredentialsManager */
- protected $credentialsManager;
-
- public function __construct(IL10N $l, ICredentialsManager $credentialsManager) {
- $this->credentialsManager = $credentialsManager;
-
+ public function __construct(
+ IL10N $l,
+ protected ICredentialsManager $credentialsManager,
+ ) {
$this
->setIdentifier('password::userprovided')
->setVisibility(BackendService::VISIBILITY_ADMIN)
->setScheme(self::SCHEME_PASSWORD)
- ->setText($l->t('User entered, store in database'))
+ ->setText($l->t('Manually entered, store in database'))
->addParameters([
- (new DefinitionParameter('user', $l->t('Username')))
+ (new DefinitionParameter('user', $l->t('Login')))
->setFlag(DefinitionParameter::FLAG_USER_PROVIDED),
(new DefinitionParameter('password', $l->t('Password')))
->setType(DefinitionParameter::VALUE_PASSWORD)
@@ -64,14 +45,22 @@ class UserProvided extends AuthMechanism implements IUserProvided {
return self::CREDENTIALS_IDENTIFIER_PREFIX . $storageId;
}
- public function saveBackendOptions(IUser $user, $id, array $options) {
- $this->credentialsManager->store($user->getUID(), $this->getCredentialsIdentifier($id), [
+ public function saveBackendOptions(IUser $user, $mountId, array $options) {
+ if ($options['password'] === DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
+ $oldCredentials = $this->credentialsManager->retrieve($user->getUID(), $this->getCredentialsIdentifier($mountId));
+ $options['password'] = $oldCredentials['password'];
+ }
+
+ $this->credentialsManager->store($user->getUID(), $this->getCredentialsIdentifier($mountId), [
'user' => $options['user'], // explicitly copy the fields we want instead of just passing the entire $options array
'password' => $options['password'] // this way we prevent users from being able to modify any other field
]);
}
- public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ /**
+ * @return void
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
if (!isset($user)) {
throw new InsufficientDataForMeaningfulAnswerException('No credentials saved');
}
@@ -85,5 +74,4 @@ class UserProvided extends AuthMechanism implements IUserProvided {
$storage->setBackendOption('user', $credentials['user']);
$storage->setBackendOption('password', $credentials['password']);
}
-
}