Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/files_external/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function loadAuthMechanisms() {
// AuthMechanism::SCHEME_PASSWORD mechanisms
$container->query('OCA\Files_External\Lib\Auth\Password\Password'),
$container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
$container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a beter name


// AuthMechanism::SCHEME_OAUTH1 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<admin>admin-external-storage</admin>
</documentation>
<rememberlogin>false</rememberlogin>
<version>0.5.1</version>
<version>0.5.2</version>
<types>
<filesystem/>
</types>
Expand Down
16 changes: 11 additions & 5 deletions apps/files_external/controller/storagescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ protected function validate(StorageConfig $storage) {
return null;
}

protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage);
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage);
}

/**
* Check whether the given storage is available / valid.
*
Expand All @@ -222,13 +231,10 @@ protected function validate(StorageConfig $storage) {
*/
protected function updateStorageStatus(StorageConfig &$storage) {
try {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage);
$this->manipulateStorageConfig($storage);

/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage);

// update status (can be time-consuming)
$storage->setStatus(
\OC_Mount_Config::getBackendStatus(
Expand Down
21 changes: 20 additions & 1 deletion apps/files_external/controller/userglobalstoragescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\Files_External\Controller;

use OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCP\IRequest;
use \OCP\IL10N;
use \OCP\AppFramework\Http\DataResponse;
Expand All @@ -30,31 +31,40 @@
use \OCA\Files_external\NotFoundException;
use \OCA\Files_external\Lib\StorageConfig;
use \OCA\Files_External\Lib\Backend\Backend;
use OCP\IUserSession;

/**
* User global storages controller
*/
class UserGlobalStoragesController extends StoragesController {
/**
* @var IUserSession
*/
private $userSession;

/**
* Creates a new user global storages controller.
*
* @param string $AppName application name
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserGlobalStoragesService $userGlobalStoragesService storage service
* @param IUserSession $userSession
*/
public function __construct(
$AppName,
IRequest $request,
IL10N $l10n,
UserGlobalStoragesService $userGlobalStoragesService
UserGlobalStoragesService $userGlobalStoragesService,
IUserSession $userSession
) {
parent::__construct(
$AppName,
$request,
$l10n,
$userGlobalStoragesService
);
$this->userSession = $userSession;
}

/**
Expand All @@ -78,6 +88,15 @@ public function index() {
);
}

protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
}

/**
* Get an external storage entry.
*
Expand Down
20 changes: 19 additions & 1 deletion apps/files_external/controller/userstoragescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCA\Files_External\Controller;


use OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCP\IConfig;
use \OCP\IUserSession;
use \OCP\IRequest;
Expand All @@ -40,26 +41,43 @@
* User storages controller
*/
class UserStoragesController extends StoragesController {
/**
* @var IUserSession
*/
private $userSession;

/**
* Creates a new user storages controller.
*
* @param string $AppName application name
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserStoragesService $userStoragesService storage service
* @param IUserSession $userSession
*/
public function __construct(
$AppName,
IRequest $request,
IL10N $l10n,
UserStoragesService $userStoragesService
UserStoragesService $userStoragesService,
IUserSession $userSession
) {
parent::__construct(
$AppName,
$request,
$l10n,
$userStoragesService
);
$this->userSession = $userSession;
}

protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
}

/**
Expand Down
92 changes: 92 additions & 0 deletions apps/files_external/lib/auth/password/logincredentials.php
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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that this is correct, will this work with LDAP user ids ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @blizzz

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The 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']);
}

}
3 changes: 2 additions & 1 deletion apps/files_external/lib/auth/password/sessioncredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function authenticate(array $params) {
$this->session->set('password::sessioncredentials/credentials', $this->crypto->encrypt(json_encode($params)));
}

public function manipulateStorageConfig(StorageConfig &$storage) {
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
$encrypted = $this->session->get('password::sessioncredentials/credentials');
if (!isset($encrypted)) {
throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
Expand Down
3 changes: 2 additions & 1 deletion apps/files_external/lib/auth/publickey/rsa.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use \OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCA\Files_External\Lib\StorageConfig;
use \OCP\IConfig;
use OCP\IUser;
use \phpseclib\Crypt\RSA as RSACrypt;

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ public function __construct(IL10N $l, IConfig $config) {
;
}

public function manipulateStorageConfig(StorageConfig &$storage) {
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
$auth = new RSACrypt();
$auth->setPassword($this->config->getSystemValue('secret', ''));
if (!$auth->loadKey($storage->getBackendOption('private_key'))) {
Expand Down
4 changes: 3 additions & 1 deletion apps/files_external/lib/backend/smb.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;

use \OCA\Files_External\Lib\Auth\Password\Password;
use OCP\IUser;

class SMB extends Backend {

Expand All @@ -56,8 +57,9 @@ public function __construct(IL10N $l, Password $legacyAuth) {

/**
* @param StorageConfig $storage
* @param IUser $user
*/
public function manipulateStorageConfig(StorageConfig &$storage) {
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
$user = $storage->getBackendOption('user');
if ($domain = $storage->getBackendOption('domain')) {
$storage->setBackendOption('user', $domain.'\\'.$user);
Expand Down
3 changes: 2 additions & 1 deletion apps/files_external/lib/backend/smb_oc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use \OCA\Files_External\Lib\StorageConfig;
use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use \OCA\Files_External\Lib\Backend\SMB;
use OCP\IUser;

/**
* Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism
Expand Down Expand Up @@ -59,7 +60,7 @@ public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBa
;
}

public function manipulateStorageConfig(StorageConfig &$storage) {
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
$username_as_share = ($storage->getBackendOption('username_as_share') === true);

if ($username_as_share) {
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/config/configadapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
}

$storage->getAuthMechanism()->manipulateStorageConfig($storage);
$storage->getBackend()->manipulateStorageConfig($storage);
$storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
$storage->getBackend()->manipulateStorageConfig($storage, $user);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion apps/files_external/lib/storagemodifiertrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\Files_External\Lib;

use \OCP\IUser;
use \OCP\Files\Storage;
use \OCA\Files_External\Lib\StorageConfig;
use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
Expand All @@ -45,10 +46,11 @@ trait StorageModifierTrait {
* Modify a StorageConfig parameters
*
* @param StorageConfig $storage
* @param IUser $user User the storage is being used as
* @throws InsufficientDataForMeaningfulAnswerException
* @throws StorageNotAvailableException
*/
public function manipulateStorageConfig(StorageConfig &$storage) {
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function setUp() {
'files_external',
$this->getMock('\OCP\IRequest'),
$this->getMock('\OCP\IL10N'),
$this->service
$this->service,
$this->getMock('\OCP\IUserSession')
);
}

Expand Down
Loading