+++ /dev/null
-<?php
-/**
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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\DAV\Connector;
-
-use OCA\Federation\DbHandler;
-use OCP\IDBConnection;
-use Sabre\DAV\Auth\Backend\AbstractBasic;
-
-class FedAuth extends AbstractBasic {
-
- /**
- * FedAuth constructor.
- *
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- $this->db = $db;
- $this->principalPrefix = 'principals/system/';
- }
-
- /**
- * Validates a username and password
- *
- * This method should return true or false depending on if login
- * succeeded.
- *
- * @param string $username
- * @param string $password
- * @return bool
- */
- protected function validateUserPass($username, $password) {
- $h = new DbHandler($this->db,
- \OC::$server->getL10N('federation')
- );
- return $h->auth($username, $password);
- }
-}
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCA\DAV\Files\CustomPropertiesBackend;
use OCP\IRequest;
+use OCP\SabrePluginEvent;
use Sabre\DAV\Auth\Plugin;
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());
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;
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 {
$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));
+ }
+ }
+ });
}
}
--- /dev/null
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @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\Federation\DAV;
+
+use OCA\Federation\DbHandler;
+use OCP\IDBConnection;
+use Sabre\DAV\Auth\Backend\AbstractBasic;
+
+class FedAuth extends AbstractBasic {
+
+ /**
+ * FedAuth constructor.
+ *
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ $this->db = $db;
+ $this->principalPrefix = 'principals/system/';
+ }
+
+ /**
+ * Validates a username and password
+ *
+ * This method should return true or false depending on if login
+ * succeeded.
+ *
+ * @param string $username
+ * @param string $password
+ * @return bool
+ */
+ protected function validateUserPass($username, $password) {
+ $h = new DbHandler($this->db,
+ \OC::$server->getL10N('federation')
+ );
+ return $h->auth($username, $password);
+ }
+}
use OCP\AppFramework\Http;
+use Sabre\DAV\Server;
use Symfony\Component\EventDispatcher\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;
}
/**
public function getMessage() {
return $this->message;
}
+
+ /**
+ * @return null|Server
+ * @since 9.0.0
+ */
+ public function getServer() {
+ return $this->server;
+ }
}