Signed-off-by: Morris Jobke <hey@morrisjobke.de>tags/v20.0.0beta1
@@ -170,6 +170,7 @@ return array( | |||
'OCA\\DAV\\Direct\\DirectHome' => $baseDir . '/../lib/Direct/DirectHome.php', | |||
'OCA\\DAV\\Direct\\Server' => $baseDir . '/../lib/Direct/Server.php', | |||
'OCA\\DAV\\Direct\\ServerFactory' => $baseDir . '/../lib/Direct/ServerFactory.php', | |||
'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => $baseDir . '/../lib/Events/SabrePluginAuthInitEvent.php', | |||
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => $baseDir . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php', | |||
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => $baseDir . '/../lib/Files/BrowserErrorPagePlugin.php', | |||
'OCA\\DAV\\Files\\FileSearchBackend' => $baseDir . '/../lib/Files/FileSearchBackend.php', |
@@ -185,6 +185,7 @@ class ComposerStaticInitDAV | |||
'OCA\\DAV\\Direct\\DirectHome' => __DIR__ . '/..' . '/../lib/Direct/DirectHome.php', | |||
'OCA\\DAV\\Direct\\Server' => __DIR__ . '/..' . '/../lib/Direct/Server.php', | |||
'OCA\\DAV\\Direct\\ServerFactory' => __DIR__ . '/..' . '/../lib/Direct/ServerFactory.php', | |||
'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => __DIR__ . '/..' . '/../lib/Events/SabrePluginAuthInitEvent.php', | |||
'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => __DIR__ . '/..' . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php', | |||
'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => __DIR__ . '/..' . '/../lib/Files/BrowserErrorPagePlugin.php', | |||
'OCA\\DAV\\Files\\FileSearchBackend' => __DIR__ . '/..' . '/../lib/Files/FileSearchBackend.php', |
@@ -30,8 +30,9 @@ use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin; | |||
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; | |||
use OCA\DAV\Connector\Sabre\CachingTree; | |||
use OCA\DAV\Connector\Sabre\DavAclPlugin; | |||
use OCA\DAV\Events\SabrePluginAuthInitEvent; | |||
use OCA\DAV\RootCollection; | |||
use OCP\SabrePluginEvent; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use Sabre\DAV\Auth\Plugin; | |||
use Sabre\VObject\ITip\Message; | |||
@@ -46,7 +47,8 @@ class InvitationResponseServer { | |||
public function __construct() { | |||
$baseUri = \OC::$WEBROOT . '/remote.php/dav/'; | |||
$logger = \OC::$server->getLogger(); | |||
$dispatcher = \OC::$server->getEventDispatcher(); | |||
/** @var IEventDispatcher $dispatcher */ | |||
$dispatcher = \OC::$server->query(IEventDispatcher::class); | |||
$root = new RootCollection(); | |||
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); | |||
@@ -67,8 +69,8 @@ class InvitationResponseServer { | |||
}); | |||
// allow setup of additional auth backends | |||
$event = new SabrePluginEvent($this->server); | |||
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); | |||
$event = new SabrePluginAuthInitEvent($this->server); | |||
$dispatcher->dispatchTyped($event); | |||
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); | |||
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
@@ -0,0 +1,56 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCA\DAV\Events; | |||
use OCP\EventDispatcher\Event; | |||
use Sabre\DAV\Server; | |||
/** | |||
* This event is triggered during the setup of the SabreDAV server to allow the | |||
* registration of additional authentication backends. | |||
* | |||
* @since 20.0.0 | |||
*/ | |||
class SabrePluginAuthInitEvent extends Event { | |||
/** @var Server */ | |||
private $server; | |||
/** | |||
* @since 20.0.0 | |||
*/ | |||
public function __construct(Server $server) { | |||
$this->server = $server; | |||
} | |||
/** | |||
* @since 20.0.0 | |||
*/ | |||
public function getServer(): Server { | |||
return $this->server; | |||
} | |||
} |
@@ -11,6 +11,7 @@ return array( | |||
'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => $baseDir . '/../lib/BackgroundJob/RetryJob.php', | |||
'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir . '/../lib/Controller/MountPublicLinkController.php', | |||
'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php', | |||
'OCA\\FederatedFileSharing\\Events\\FederatedShareAddedEvent' => $baseDir . '/../lib/Events/FederatedShareAddedEvent.php', | |||
'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir . '/../lib/FederatedShareProvider.php', | |||
'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php', | |||
'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => $baseDir . '/../lib/Migration/Version1010Date20200630191755.php', |
@@ -26,6 +26,7 @@ class ComposerStaticInitFederatedFileSharing | |||
'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RetryJob.php', | |||
'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php', | |||
'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php', | |||
'OCA\\FederatedFileSharing\\Events\\FederatedShareAddedEvent' => __DIR__ . '/..' . '/../lib/Events/FederatedShareAddedEvent.php', | |||
'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php', | |||
'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', | |||
'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191755.php', |
@@ -0,0 +1,54 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCA\FederatedFileSharing\Events; | |||
use OCP\EventDispatcher\Event; | |||
/** | |||
* This event is triggered when a federated share is successfully added | |||
* | |||
* @since 20.0.0 | |||
*/ | |||
class FederatedShareAddedEvent extends Event { | |||
/** @var string */ | |||
private $remote; | |||
/** | |||
* @since 20.0.0 | |||
*/ | |||
public function __construct(string $remote) { | |||
$this->remote = $remote; | |||
} | |||
/** | |||
* @since 20.0.0 | |||
*/ | |||
public function getRemote(): string { | |||
return $this->remote; | |||
} | |||
} |
@@ -25,8 +25,10 @@ | |||
namespace OCA\FederatedFileSharing; | |||
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; | |||
use OCP\AppFramework\Http; | |||
use OCP\BackgroundJob\IJobList; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\Federation\ICloudFederationFactory; | |||
use OCP\Federation\ICloudFederationProviderManager; | |||
use OCP\Http\Client\IClientService; | |||
@@ -53,21 +55,17 @@ class Notifications { | |||
/** @var ICloudFederationFactory */ | |||
private $cloudFederationFactory; | |||
/** | |||
* @param AddressHandler $addressHandler | |||
* @param IClientService $httpClientService | |||
* @param IDiscoveryService $discoveryService | |||
* @param IJobList $jobList | |||
* @param ICloudFederationProviderManager $federationProviderManager | |||
* @param ICloudFederationFactory $cloudFederationFactory | |||
*/ | |||
/** @var IEventDispatcher */ | |||
private $eventDispatcher; | |||
public function __construct( | |||
AddressHandler $addressHandler, | |||
IClientService $httpClientService, | |||
IDiscoveryService $discoveryService, | |||
IJobList $jobList, | |||
ICloudFederationProviderManager $federationProviderManager, | |||
ICloudFederationFactory $cloudFederationFactory | |||
ICloudFederationFactory $cloudFederationFactory, | |||
IEventDispatcher $eventDispatcher | |||
) { | |||
$this->addressHandler = $addressHandler; | |||
$this->httpClientService = $httpClientService; | |||
@@ -75,6 +73,7 @@ class Notifications { | |||
$this->jobList = $jobList; | |||
$this->federationProviderManager = $federationProviderManager; | |||
$this->cloudFederationFactory = $cloudFederationFactory; | |||
$this->eventDispatcher = $eventDispatcher; | |||
} | |||
/** | |||
@@ -119,7 +118,8 @@ class Notifications { | |||
$ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); | |||
if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { | |||
\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); | |||
$event = new FederatedShareAddedEvent($remote); | |||
$this->eventDispatcher->dispatchTyped($event); | |||
return true; | |||
} | |||
} |
@@ -34,6 +34,7 @@ use OCA\Files_Sharing\Activity\Providers\RemoteShares; | |||
use OCP\Activity\IManager as IActivityManager; | |||
use OCP\App\IAppManager; | |||
use OCP\Constants; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\Federation\Exceptions\ActionNotSupportedException; | |||
use OCP\Federation\Exceptions\AuthenticationFailedException; | |||
use OCP\Federation\Exceptions\BadRequestException; | |||
@@ -240,7 +241,8 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { | |||
\OC::$server->getCloudFederationFactory(), | |||
\OC::$server->getGroupManager(), | |||
\OC::$server->getUserManager(), | |||
$shareWith | |||
$shareWith, | |||
\OC::$server->query(IEventDispatcher::class) | |||
); | |||
try { |
@@ -27,6 +27,7 @@ namespace OCA\FederatedFileSharing\Tests; | |||
use OCA\FederatedFileSharing\AddressHandler; | |||
use OCA\FederatedFileSharing\Notifications; | |||
use OCP\BackgroundJob\IJobList; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\Federation\ICloudFederationFactory; | |||
use OCP\Federation\ICloudFederationProviderManager; | |||
use OCP\Http\Client\IClientService; | |||
@@ -52,6 +53,9 @@ class NotificationsTest extends \Test\TestCase { | |||
/** @var ICloudFederationFactory|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $cloudFederationFactory; | |||
/** @var IEventDispatcher|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $eventDispatcher; | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
@@ -62,6 +66,7 @@ class NotificationsTest extends \Test\TestCase { | |||
->disableOriginalConstructor()->getMock(); | |||
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); | |||
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); | |||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class); | |||
} | |||
/** | |||
@@ -78,7 +83,8 @@ class NotificationsTest extends \Test\TestCase { | |||
$this->discoveryService, | |||
$this->jobList, | |||
$this->cloudFederationProviderManager, | |||
$this->cloudFederationFactory | |||
$this->cloudFederationFactory, | |||
$this->eventDispatcher | |||
); | |||
} else { | |||
$instance = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') | |||
@@ -89,7 +95,8 @@ class NotificationsTest extends \Test\TestCase { | |||
$this->discoveryService, | |||
$this->jobList, | |||
$this->cloudFederationProviderManager, | |||
$this->cloudFederationFactory | |||
$this->cloudFederationFactory, | |||
$this->eventDispatcher | |||
] | |||
)->setMethods($mockedMethods)->getMock(); | |||
} |
@@ -1,28 +0,0 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Björn Schießle <bjoern@schiessle.org> | |||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | |||
* | |||
* @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\Federation\AppInfo; | |||
/** @var Application $app */ | |||
$app = \OC::$server->query(Application::class); | |||
$app->registerHooks(); |
@@ -15,6 +15,8 @@ return array( | |||
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php', | |||
'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php', | |||
'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php', | |||
'OCA\\Federation\\Listener\\FederatedShareAddedListener' => $baseDir . '/../lib/Listeners/FederatedShareAddedListener.php', | |||
'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => $baseDir . '/../lib/Listeners/SabrePluginAuthInitListener.php', | |||
'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php', | |||
'OCA\\Federation\\Migration\\Version1010Date20200630191302' => $baseDir . '/../lib/Migration/Version1010Date20200630191302.php', | |||
'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
@@ -30,6 +30,8 @@ class ComposerStaticInitFederation | |||
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php', | |||
'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php', | |||
'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', | |||
'OCA\\Federation\\Listener\\FederatedShareAddedListener' => __DIR__ . '/..' . '/../lib/Listeners/FederatedShareAddedListener.php', | |||
'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => __DIR__ . '/..' . '/../lib/Listeners/SabrePluginAuthInitListener.php', | |||
'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php', | |||
'OCA\\Federation\\Migration\\Version1010Date20200630191302' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191302.php', | |||
'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
@@ -27,58 +27,32 @@ | |||
namespace OCA\Federation\AppInfo; | |||
use OCA\Federation\DAV\FedAuth; | |||
use OCA\Federation\Hooks; | |||
use OCA\DAV\Events\SabrePluginAuthInitEvent; | |||
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; | |||
use OCA\Federation\Listener\FederatedShareAddedListener; | |||
use OCA\Federation\Listener\SabrePluginAuthInitListener; | |||
use OCA\Federation\Middleware\AddServerMiddleware; | |||
use OCP\AppFramework\App; | |||
use OCP\SabrePluginEvent; | |||
use OCP\Share; | |||
use OCP\Util; | |||
use Sabre\DAV\Auth\Plugin; | |||
use Sabre\DAV\Server; | |||
use OCP\AppFramework\Bootstrap\IBootContext; | |||
use OCP\AppFramework\Bootstrap\IBootstrap; | |||
use OCP\AppFramework\Bootstrap\IRegistrationContext; | |||
class Application extends App { | |||
class Application extends App implements IBootstrap { | |||
/** | |||
* @param array $urlParams | |||
*/ | |||
public function __construct($urlParams = []) { | |||
parent::__construct('federation', $urlParams); | |||
$this->registerMiddleware(); | |||
} | |||
private function registerMiddleware() { | |||
$container = $this->getContainer(); | |||
$container->registerAlias('AddServerMiddleware', AddServerMiddleware::class); | |||
$container->registerMiddleWare('AddServerMiddleware'); | |||
} | |||
public function register(IRegistrationContext $context): void { | |||
$context->registerMiddleware(AddServerMiddleware::class); | |||
/** | |||
* listen to federated_share_added hooks to auto-add new servers to the | |||
* list of trusted servers. | |||
*/ | |||
public function registerHooks() { | |||
$container = $this->getContainer(); | |||
$hooksManager = $container->query(Hooks::class); | |||
Util::connectHook( | |||
Share::class, | |||
'federated_share_added', | |||
$hooksManager, | |||
'addServerHook' | |||
); | |||
$context->registerEventListener(FederatedShareAddedEvent::class, FederatedShareAddedListener::class); | |||
$context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class); | |||
} | |||
$dispatcher = $container->getServer()->getEventDispatcher(); | |||
$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) { | |||
if ($event instanceof SabrePluginEvent) { | |||
$server = $event->getServer(); | |||
if ($server instanceof Server) { | |||
$authPlugin = $server->getPlugin('auth'); | |||
if ($authPlugin instanceof Plugin) { | |||
$authPlugin->addBackend($container->query(FedAuth::class)); | |||
} | |||
} | |||
} | |||
}); | |||
public function boot(IBootContext $context): void { | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCA\Federation\Listener; | |||
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; | |||
use OCA\Federation\TrustedServers; | |||
use OCP\EventDispatcher\Event; | |||
use OCP\EventDispatcher\IEventListener; | |||
/** | |||
* Automatically add new servers to the list of trusted servers. | |||
* | |||
* @since 20.0.0 | |||
*/ | |||
class FederatedShareAddedListener implements IEventListener { | |||
/** @var TrustedServers */ | |||
private $trustedServers; | |||
public function __construct(TrustedServers $trustedServers) { | |||
$this->trustedServers = $trustedServers; | |||
} | |||
public function handle(Event $event): void { | |||
if (!($event instanceof FederatedShareAddedEvent)) { | |||
return; | |||
} | |||
$server = $event->getRemote(); | |||
if ( | |||
$this->trustedServers->getAutoAddServers() === true && | |||
$this->trustedServers->isTrustedServer($server) === false | |||
) { | |||
$this->trustedServers->addServer($server); | |||
} | |||
} | |||
} |
@@ -0,0 +1,57 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCA\Federation\Listener; | |||
use OCA\DAV\Events\SabrePluginAuthInitEvent; | |||
use OCA\Federation\DAV\FedAuth; | |||
use OCP\EventDispatcher\Event; | |||
use OCP\EventDispatcher\IEventListener; | |||
use Sabre\DAV\Auth\Plugin; | |||
/** | |||
* @since 20.0.0 | |||
*/ | |||
class SabrePluginAuthInitListener implements IEventListener { | |||
/** @var FedAuth */ | |||
private $fedAuth; | |||
public function __construct(FedAuth $fedAuth) { | |||
$this->fedAuth = $fedAuth; | |||
} | |||
public function handle(Event $event): void { | |||
if (!($event instanceof SabrePluginAuthInitEvent)) { | |||
return; | |||
} | |||
$server = $event->getServer(); | |||
$authPlugin = $server->getPlugin('auth'); | |||
if ($authPlugin instanceof Plugin) { | |||
$authPlugin->addBackend($this->fedAuth); | |||
} | |||
} | |||
} |
@@ -94,7 +94,8 @@ class Application extends App { | |||
$server->getCloudFederationFactory(), | |||
$server->getGroupManager(), | |||
$server->getUserManager(), | |||
$uid | |||
$uid, | |||
$server->query(IEventDispatcher::class) | |||
); | |||
}); | |||
@@ -33,7 +33,9 @@ | |||
namespace OCA\Files_Sharing\External; | |||
use OC\Files\Filesystem; | |||
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; | |||
use OCA\Files_Sharing\Helper; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\Federation\ICloudFederationFactory; | |||
use OCP\Federation\ICloudFederationProviderManager; | |||
use OCP\Files; | |||
@@ -50,39 +52,25 @@ use OCP\Share\IShare; | |||
class Manager { | |||
public const STORAGE = '\OCA\Files_Sharing\External\Storage'; | |||
/** | |||
* @var string | |||
*/ | |||
/** @var string */ | |||
private $uid; | |||
/** | |||
* @var IDBConnection | |||
*/ | |||
/** @var IDBConnection */ | |||
private $connection; | |||
/** | |||
* @var \OC\Files\Mount\Manager | |||
*/ | |||
/** @var \OC\Files\Mount\Manager */ | |||
private $mountManager; | |||
/** | |||
* @var IStorageFactory | |||
*/ | |||
/** @var IStorageFactory */ | |||
private $storageLoader; | |||
/** | |||
* @var IClientService | |||
*/ | |||
/** @var IClientService */ | |||
private $clientService; | |||
/** | |||
* @var IManager | |||
*/ | |||
/** @var IManager */ | |||
private $notificationManager; | |||
/** | |||
* @var IDiscoveryService | |||
*/ | |||
/** @var IDiscoveryService */ | |||
private $discoveryService; | |||
/** @var ICloudFederationProviderManager */ | |||
@@ -97,19 +85,9 @@ class Manager { | |||
/** @var IUserManager */ | |||
private $userManager; | |||
/** | |||
* @param IDBConnection $connection | |||
* @param \OC\Files\Mount\Manager $mountManager | |||
* @param IStorageFactory $storageLoader | |||
* @param IClientService $clientService | |||
* @param IManager $notificationManager | |||
* @param IDiscoveryService $discoveryService | |||
* @param ICloudFederationProviderManager $cloudFederationProviderManager | |||
* @param ICloudFederationFactory $cloudFederationFactory | |||
* @param IGroupManager $groupManager | |||
* @param IUserManager $userManager | |||
* @param string $uid | |||
*/ | |||
/** @var IEventDispatcher */ | |||
private $eventDispatcher; | |||
public function __construct(IDBConnection $connection, | |||
\OC\Files\Mount\Manager $mountManager, | |||
IStorageFactory $storageLoader, | |||
@@ -120,7 +98,8 @@ class Manager { | |||
ICloudFederationFactory $cloudFederationFactory, | |||
IGroupManager $groupManager, | |||
IUserManager $userManager, | |||
$uid) { | |||
string $uid, | |||
IEventDispatcher $eventDispatcher) { | |||
$this->connection = $connection; | |||
$this->mountManager = $mountManager; | |||
$this->storageLoader = $storageLoader; | |||
@@ -132,6 +111,7 @@ class Manager { | |||
$this->cloudFederationFactory = $cloudFederationFactory; | |||
$this->groupManager = $groupManager; | |||
$this->userManager = $userManager; | |||
$this->eventDispatcher = $eventDispatcher; | |||
} | |||
/** | |||
@@ -300,7 +280,8 @@ class Manager { | |||
} | |||
if ($userShareAccepted === true) { | |||
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); | |||
\OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); | |||
$event = new FederatedShareAddedEvent($share['remote']); | |||
$this->eventDispatcher->dispatchTyped($event); | |||
$result = true; | |||
} | |||
} |
@@ -28,6 +28,7 @@ | |||
namespace OCA\Files_Sharing; | |||
use OC\Files\Filesystem; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
class Hooks { | |||
public static function deleteUser($params) { | |||
@@ -42,7 +43,9 @@ class Hooks { | |||
\OC::$server->getCloudFederationFactory(), | |||
\OC::$server->getGroupManager(), | |||
\OC::$server->getUserManager(), | |||
$params['uid']); | |||
$params['uid'], | |||
\OC::$server->query(IEventDispatcher::class) | |||
); | |||
$manager->removeUserShares($params['uid']); | |||
} |
@@ -33,6 +33,7 @@ use OC\Files\Storage\StorageFactory; | |||
use OCA\Files_Sharing\External\Manager; | |||
use OCA\Files_Sharing\External\MountProvider; | |||
use OCA\Files_Sharing\Tests\TestCase; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\Federation\ICloudFederationFactory; | |||
use OCP\Federation\ICloudFederationProviderManager; | |||
use OCP\Http\Client\IClientService; | |||
@@ -80,6 +81,8 @@ class ManagerTest extends TestCase { | |||
*/ | |||
private $user; | |||
private $testMountProvider; | |||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ | |||
private $eventDispatcher; | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
@@ -94,6 +97,7 @@ class ManagerTest extends TestCase { | |||
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); | |||
$this->groupManager = $this->createMock(IGroupManager::class); | |||
$this->userManager = $this->createMock(IUserManager::class); | |||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class); | |||
$this->manager = $this->getMockBuilder(Manager::class) | |||
->setConstructorArgs( | |||
@@ -108,7 +112,8 @@ class ManagerTest extends TestCase { | |||
$this->cloudFederationFactory, | |||
$this->groupManager, | |||
$this->userManager, | |||
$this->uid | |||
$this->uid, | |||
$this->eventDispatcher, | |||
] | |||
)->setMethods(['tryOCMEndPoint'])->getMock(); | |||
@@ -39,6 +39,7 @@ use OCA\FederatedFileSharing\TokenHandler; | |||
use OCA\ShareByMail\Settings\SettingsManager; | |||
use OCA\ShareByMail\ShareByMailProvider; | |||
use OCP\Defaults; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\IServerContainer; | |||
use OCP\Share\IProviderFactory; | |||
use OCP\Share\IShare; | |||
@@ -127,7 +128,8 @@ class ProviderFactory implements IProviderFactory { | |||
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), | |||
$this->serverContainer->getJobList(), | |||
\OC::$server->getCloudFederationProviderManager(), | |||
\OC::$server->getCloudFederationFactory() | |||
\OC::$server->getCloudFederationFactory(), | |||
$this->serverContainer->query(IEventDispatcher::class) | |||
); | |||
$tokenHandler = new TokenHandler( | |||
$this->serverContainer->getSecureRandom() |