Skip to content

Commit

Permalink
Merge pull request #23261 from nextcloud/enh/external-storage-session…
Browse files Browse the repository at this point in the history
…-type

Expose session based authentication through mount point type
  • Loading branch information
MorrisJobke authored Jan 7, 2021
2 parents 171373a + 35e5cc8 commit 275f15c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/files_external/lib/Config/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
return new PersonalMount(
$this->userStoragesService,
$storageConfig,
$storageConfig->getId(),
$storage,
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
Expand All @@ -171,6 +172,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
);
} else {
return new ExternalMountPoint(
$storageConfig,
$storage,
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
null,
Expand Down
13 changes: 12 additions & 1 deletion apps/files_external/lib/Config/ExternalMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@
namespace OCA\Files_External\Config;

use OC\Files\Mount\MountPoint;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\Auth\Password\SessionCredentials;

class ExternalMountPoint extends MountPoint {

/** @var StorageConfig */
protected $storageConfig;

public function __construct(StorageConfig $storageConfig, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
$this->storageConfig = $storageConfig;
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
}

public function getMountType() {
return 'external';
return ($this->storageConfig->getAuthMechanism() instanceof SessionCredentials) ? 'external-session' : 'external';
}
}
6 changes: 4 additions & 2 deletions apps/files_external/lib/Lib/PersonalMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Files\Mount\MoveableMount;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\Files_External\Service\UserStoragesService;
use OCP\Files\Storage\IStorage;

/**
* Person mount points can be moved by the user
Expand All @@ -42,14 +43,15 @@ class PersonalMount extends ExternalMountPoint implements MoveableMount {
/**
* @param UserStoragesService $storagesService
* @param int $storageId
* @param \OCP\Files\Storage $storage
* @param IStorage $storage
* @param string $mountpoint
* @param array $arguments (optional) configuration for the storage backend
* @param \OCP\Files\Storage\IStorageFactory $loader
* @param array $mountOptions mount specific options
*/
public function __construct(
UserStoragesService $storagesService,
StorageConfig $storageConfig,
$storageId,
$storage,
$mountpoint,
Expand All @@ -58,7 +60,7 @@ public function __construct(
$mountOptions = null,
$mountId = null
) {
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
parent::__construct($storageConfig, $storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
$this->storagesService = $storagesService;
$this->numericStorageId = $storageId;
}
Expand Down
4 changes: 3 additions & 1 deletion apps/files_external/tests/PersonalMountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

use OC\Files\Mount\Manager;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
use Test\TestCase;

class PersonalMountTest extends TestCase {
public function testFindByStorageId() {
$storageConfig = $this->createMock(StorageConfig::class);
/** @var \OCA\Files_External\Service\UserStoragesService $storageService */
$storageService = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService')
->disableOriginalConstructor()
Expand All @@ -43,7 +45,7 @@ public function testFindByStorageId() {
->method('getId')
->willReturn('dummy');

$mount = new PersonalMount($storageService, 10, $storage, '/foo');
$mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo');

$mountManager = new Manager();
$mountManager->addMount($mount);
Expand Down

0 comments on commit 275f15c

Please sign in to comment.