2015-08-13 00:05:17 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2015-08-13 00:05:17 +03:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-08-13 00:05:17 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_External\Lib\Auth\Password;
|
|
|
|
|
2016-12-19 13:42:57 +03:00
|
|
|
use OCA\Files_External\Lib\Auth\AuthMechanism;
|
|
|
|
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\IL10N;
|
|
|
|
use OCP\IUser;
|
2015-08-13 00:05:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Username and password from login credentials, saved in session
|
|
|
|
*/
|
|
|
|
class SessionCredentials extends AuthMechanism {
|
|
|
|
|
2016-12-19 13:42:57 +03:00
|
|
|
/** @var CredentialsStore */
|
|
|
|
private $credentialsStore;
|
|
|
|
|
2017-01-02 12:04:55 +03:00
|
|
|
public function __construct(IL10N $l, CredentialsStore $credentialsStore) {
|
2016-12-19 13:42:57 +03:00
|
|
|
$this->credentialsStore = $credentialsStore;
|
2015-08-13 00:05:17 +03:00
|
|
|
|
2016-12-19 13:42:57 +03:00
|
|
|
$this->setIdentifier('password::sessioncredentials')
|
2015-08-13 00:05:17 +03:00
|
|
|
->setScheme(self::SCHEME_PASSWORD)
|
2016-02-01 14:20:21 +03:00
|
|
|
->setText($l->t('Log-in credentials, save in session'))
|
2016-12-19 13:42:57 +03:00
|
|
|
->addParameters([]);
|
2015-08-13 00:05:17 +03:00
|
|
|
}
|
|
|
|
|
2015-08-24 18:32:44 +03:00
|
|
|
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
|
2016-12-19 13:42:57 +03:00
|
|
|
try {
|
|
|
|
$credentials = $this->credentialsStore->getLoginCredentials();
|
|
|
|
} catch (CredentialsUnavailableException $e) {
|
2015-08-13 00:05:17 +03:00
|
|
|
throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
|
|
|
|
}
|
|
|
|
|
2016-12-19 13:42:57 +03:00
|
|
|
$storage->setBackendOption('user', $credentials->getLoginName());
|
|
|
|
$storage->setBackendOption('password', $credentials->getPassword());
|
2015-08-13 00:05:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function wrapStorage(Storage $storage) {
|
|
|
|
return new SessionStorageWrapper(['storage' => $storage]);
|
|
|
|
}
|
|
|
|
}
|