migrate 'password::sessioncredentials' extern storage auth to credential store

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2016-12-19 11:42:57 +01:00 committed by Roeland Jago Douma
parent 3316a9d294
commit e4abb9cb6e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 24 additions and 32 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@ -23,16 +24,17 @@
namespace OCA\Files_External\Lib\Auth\Password;
use \OCP\IUser;
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;
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\ISession;
use OCP\IUser;
use OCP\Security\ICrypto;
/**
* Username and password from login credentials, saved in session
@ -45,39 +47,29 @@ class SessionCredentials extends AuthMechanism {
/** @var ICrypto */
protected $crypto;
public function __construct(IL10N $l, ISession $session, ICrypto $crypto) {
/** @var CredentialsStore */
private $credentialsStore;
public function __construct(IL10N $l, ISession $session, ICrypto $crypto, CredentialsStore $credentialsStore) {
$this->session = $session;
$this->crypto = $crypto;
$this->credentialsStore = $credentialsStore;
$this
->setIdentifier('password::sessioncredentials')
$this->setIdentifier('password::sessioncredentials')
->setScheme(self::SCHEME_PASSWORD)
->setText($l->t('Log-in credentials, save in session'))
->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)));
->addParameters([]);
}
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
$encrypted = $this->session->get('password::sessioncredentials/credentials');
if (!isset($encrypted)) {
try {
$credentials = $this->credentialsStore->getLoginCredentials();
} catch (CredentialsUnavailableException $e) {
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']);
$storage->setBackendOption('user', $credentials->getLoginName());
$storage->setBackendOption('password', $credentials->getPassword());
}
public function wrapStorage(Storage $storage) {