mirror of https://github.com/nextcloud/server.git
Move federated_share_added into a typed event
Signed-off-by: Morris Jobke <hey@morrisjobke.de>pull/21814/head
parent
99d0ba5f7e
commit
0763a17332
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue