diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 8b7171c145c58df40d07898ba064eeccdcbd876e..93e903e6bf1a1946f1f472258d4b50c6a2408854 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -8,6 +8,7 @@ use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; use OCA\DAV\Files\CustomPropertiesBackend; use OCP\IRequest; +use OCP\SabrePluginEvent; use Sabre\DAV\Auth\Plugin; class Server { @@ -37,8 +38,12 @@ class Server { $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); $authPlugin = new Plugin($authBackend, 'ownCloud'); - $authPlugin->addBackend(new FedAuth(\OC::$server->getDatabaseConnection())); $this->server->addPlugin($authPlugin); + + // allow setup of additional auth backends + $event = new SabrePluginEvent($this->server); + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); diff --git a/apps/federation/appinfo/application.php b/apps/federation/appinfo/application.php index 45d88548b70d2919a702698b6bac3edc694d8ffe..f0fefb948af9ba0e70fed43edabf5ef9881a1926 100644 --- a/apps/federation/appinfo/application.php +++ b/apps/federation/appinfo/application.php @@ -23,6 +23,7 @@ namespace OCA\Federation\AppInfo; use OCA\Federation\API\OCSAuthAPI; use OCA\Federation\Controller\SettingsController; +use OCA\Federation\DAV\FedAuth; use OCA\Federation\DbHandler; use OCA\Federation\Hooks; use OCA\Federation\Middleware\AddServerMiddleware; @@ -30,7 +31,9 @@ use OCA\Federation\TrustedServers; use OCP\API; use OCP\App; use OCP\AppFramework\IAppContainer; +use OCP\SabrePluginEvent; use OCP\Util; +use Sabre\DAV\Auth\Plugin; class Application extends \OCP\AppFramework\App { @@ -144,6 +147,17 @@ class Application extends \OCP\AppFramework\App { $hooksManager, 'addServerHook' ); + + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); + $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) { + if ($event instanceof SabrePluginEvent) { + $authPlugin = $event->getServer()->getPlugin('auth'); + if ($authPlugin instanceof Plugin) { + $db = $container->getServer()->getDatabaseConnection(); + $authPlugin->addBackend(new FedAuth($db)); + } + } + }); } } diff --git a/apps/dav/lib/connector/fedauth.php b/apps/federation/dav/fedauth.php similarity index 98% rename from apps/dav/lib/connector/fedauth.php rename to apps/federation/dav/fedauth.php index 42a29cef3fcba9c0a13fa7da0375bff40d723a80..ade5448d1bcd8604e1d92fc5127bf4a2319dab58 100644 --- a/apps/dav/lib/connector/fedauth.php +++ b/apps/federation/dav/fedauth.php @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -namespace OCA\DAV\Connector; +namespace OCA\Federation\DAV; use OCA\Federation\DbHandler; use OCP\IDBConnection; diff --git a/lib/public/sabrepluginevent.php b/lib/public/sabrepluginevent.php index fed3237166d87c78022780993f685b4ada3a18c3..1a64c8ac3edb109ab17f9f22d150f95f9b85b379 100644 --- a/lib/public/sabrepluginevent.php +++ b/lib/public/sabrepluginevent.php @@ -23,6 +23,7 @@ namespace OCP; use OCP\AppFramework\Http; +use Sabre\DAV\Server; use Symfony\Component\EventDispatcher\Event; /** @@ -36,12 +37,16 @@ class SabrePluginEvent extends Event { /** @var string */ protected $message; + /** @var Server */ + protected $server; + /** * @since 8.2.0 */ - public function __construct() { + public function __construct($server = null) { $this->message = ''; $this->statusCode = Http::STATUS_OK; + $this->server = $server; } /** @@ -79,4 +84,12 @@ class SabrePluginEvent extends Event { public function getMessage() { return $this->message; } + + /** + * @return null|Server + * @since 9.0.0 + */ + public function getServer() { + return $this->server; + } }