Use EventDispatcher to allow additional setup of auth backends - move federation auth to federation app

This commit is contained in:
Thomas Müller 2015-12-04 12:11:07 +01:00
parent cdc536c423
commit dbddbb634b
4 changed files with 35 additions and 3 deletions

View File

@ -8,6 +8,7 @@ use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCA\DAV\Files\CustomPropertiesBackend; use OCA\DAV\Files\CustomPropertiesBackend;
use OCP\IRequest; use OCP\IRequest;
use OCP\SabrePluginEvent;
use Sabre\DAV\Auth\Plugin; use Sabre\DAV\Auth\Plugin;
class Server { class Server {
@ -37,8 +38,12 @@ class Server {
$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
$authPlugin = new Plugin($authBackend, 'ownCloud'); $authPlugin = new Plugin($authBackend, 'ownCloud');
$authPlugin->addBackend(new FedAuth(\OC::$server->getDatabaseConnection()));
$this->server->addPlugin($authPlugin); $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\DummyGetResponsePlugin());
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());

View File

@ -23,6 +23,7 @@ namespace OCA\Federation\AppInfo;
use OCA\Federation\API\OCSAuthAPI; use OCA\Federation\API\OCSAuthAPI;
use OCA\Federation\Controller\SettingsController; use OCA\Federation\Controller\SettingsController;
use OCA\Federation\DAV\FedAuth;
use OCA\Federation\DbHandler; use OCA\Federation\DbHandler;
use OCA\Federation\Hooks; use OCA\Federation\Hooks;
use OCA\Federation\Middleware\AddServerMiddleware; use OCA\Federation\Middleware\AddServerMiddleware;
@ -30,7 +31,9 @@ use OCA\Federation\TrustedServers;
use OCP\API; use OCP\API;
use OCP\App; use OCP\App;
use OCP\AppFramework\IAppContainer; use OCP\AppFramework\IAppContainer;
use OCP\SabrePluginEvent;
use OCP\Util; use OCP\Util;
use Sabre\DAV\Auth\Plugin;
class Application extends \OCP\AppFramework\App { class Application extends \OCP\AppFramework\App {
@ -144,6 +147,17 @@ class Application extends \OCP\AppFramework\App {
$hooksManager, $hooksManager,
'addServerHook' '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));
}
}
});
} }
} }

View File

@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * 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 OCA\Federation\DbHandler;
use OCP\IDBConnection; use OCP\IDBConnection;

View File

@ -23,6 +23,7 @@ namespace OCP;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use Sabre\DAV\Server;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
/** /**
@ -36,12 +37,16 @@ class SabrePluginEvent extends Event {
/** @var string */ /** @var string */
protected $message; protected $message;
/** @var Server */
protected $server;
/** /**
* @since 8.2.0 * @since 8.2.0
*/ */
public function __construct() { public function __construct($server = null) {
$this->message = ''; $this->message = '';
$this->statusCode = Http::STATUS_OK; $this->statusCode = Http::STATUS_OK;
$this->server = $server;
} }
/** /**
@ -79,4 +84,12 @@ class SabrePluginEvent extends Event {
public function getMessage() { public function getMessage() {
return $this->message; return $this->message;
} }
/**
* @return null|Server
* @since 9.0.0
*/
public function getServer() {
return $this->server;
}
} }