-
Notifications
You must be signed in to change notification settings - Fork 2.1k
External storage 'Login credentials' auth mechanism #18531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88cd615
da4127d
3fe802d
7e01f32
7ba715d
895fd49
ebd15fd
15451b2
58afddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?php | ||
| /** | ||
| * @author Robin McCorkell <[email protected]> | ||
| * | ||
| * @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 \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; | ||
|
|
||
| /** | ||
| * Username and password from login credentials, saved in DB | ||
| */ | ||
| class LoginCredentials extends AuthMechanism { | ||
|
|
||
| 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; | ||
|
|
||
| $this | ||
| ->setIdentifier('password::logincredentials') | ||
| ->setScheme(self::SCHEME_PASSWORD) | ||
| ->setText($l->t('Login credentials')) | ||
| ->addParameters([ | ||
| ]) | ||
| ; | ||
|
|
||
| \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); | ||
| } | ||
|
|
||
| /** | ||
| * Hook listener on post login | ||
| * | ||
| * @param array $params | ||
| */ | ||
| public function authenticate(array $params) { | ||
| $userId = $params['uid']; | ||
| $credentials = [ | ||
| 'user' => $this->session->get('loginname'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming that this is correct, will this work with LDAP user ids ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CC @blizzz
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Historical problem in WND + LDAP https://github.com/owncloud/windows_network_drive/issues/218#issuecomment-108363607
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a note in the original ticket for QA to test this case |
||
| 'password' => $params['password'] | ||
| ]; | ||
| $this->credentialsManager->store($userId, self::CREDENTIALS_IDENTIFIER, $credentials); | ||
| } | ||
|
|
||
| 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); | ||
|
|
||
| if (!isset($credentials)) { | ||
| throw new InsufficientDataForMeaningfulAnswerException('No login credentials saved'); | ||
| } | ||
|
|
||
| $storage->setBackendOption('user', $credentials['user']); | ||
| $storage->setBackendOption('password', $credentials['password']); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a beter name