diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php index 2fa939764d7..196be05e528 100644 --- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php +++ b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php @@ -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) { |