Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/user_saml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-03-05 20:44:39 +0300
committerRobin Appelman <robin@icewind.nl>2018-11-20 17:12:51 +0300
commita7f0e3522586d9c651cc24064bf43a31dfd0d5cc (patch)
tree549dec7cee80d2feb92f732f03aa73e4f5bf7879 /lib
parent0ebcaa733db6abf345b960b76ac6a8a5aea560d4 (diff)
Add sabredav plugin to register environment auth for dav requests
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php24
-rw-r--r--lib/DavPlugin.php54
2 files changed, 77 insertions, 1 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 0a7a2429..126099df 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -21,9 +21,11 @@
namespace OCA\User_SAML\AppInfo;
+use OCA\User_SAML\DavPlugin;
use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
+use OCP\SabrePluginEvent;
class Application extends App {
public function __construct(array $urlParams = array()) {
@@ -33,12 +35,32 @@ class Application extends App {
/**
* Middleware
*/
- $container->registerService('OnlyLoggedInMiddleware', function(IAppContainer $c){
+ $container->registerService('OnlyLoggedInMiddleware', function (IAppContainer $c) {
return new OnlyLoggedInMiddleware(
$c->query('ControllerMethodReflector'),
$c->query('ServerContainer')->getUserSession()
);
});
+
+ $container->registerService(DavPlugin::class, function (IAppContainer $c) {
+ $server = $c->getServer();
+ return new DavPlugin(
+ $server->getSession(),
+ $server->getConfig(),
+ $_SERVER
+ );
+ });
+
$container->registerMiddleWare('OnlyLoggedInMiddleware');
}
+
+ public function registerDavAuth() {
+
+ $container = $this->getContainer();
+
+ $dispatcher = $container->getServer()->getEventDispatcher();
+ $dispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($container) {
+ $event->getServer()->addPlugin($container->query(DavPlugin::class));
+ });
+ }
}
diff --git a/lib/DavPlugin.php b/lib/DavPlugin.php
new file mode 100644
index 00000000..1545d71c
--- /dev/null
+++ b/lib/DavPlugin.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
+ *
+ * @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\User_SAML;
+
+use OCP\IConfig;
+use OCP\ISession;
+use Sabre\DAV\Server;
+use Sabre\DAV\ServerPlugin;
+
+class DavPlugin extends ServerPlugin {
+ private $session;
+ private $config;
+ private $auth;
+
+ public function __construct(ISession $session, IConfig $config, array $auth) {
+ $this->session = $session;
+ $this->config = $config;
+ $this->auth = $auth;
+ }
+
+
+ public function initialize(Server $server) {
+ // before auth
+ $server->on('beforeMethod', [$this, 'beforeMethod'], 9);
+ }
+
+ public function beforeMethod() {
+ if (!$this->session->exists('user_saml.samlUserData')) {
+ $uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping');
+ if (isset($this->auth[$uidMapping])) {
+ $this->session->set('user_saml.samlUserData', $this->auth);
+ }
+ }
+ }
+}