]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow trusted servers to authenticate
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 3 Dec 2015 15:22:18 +0000 (16:22 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 12 Jan 2016 13:24:01 +0000 (14:24 +0100)
apps/dav/lib/connector/fedauth.php [new file with mode: 0644]
apps/dav/lib/server.php
apps/federation/appinfo/database.xml
apps/federation/lib/dbhandler.php

diff --git a/apps/dav/lib/connector/fedauth.php b/apps/dav/lib/connector/fedauth.php
new file mode 100644 (file)
index 0000000..42a29ce
--- /dev/null
@@ -0,0 +1,55 @@
+<?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);
+       }
+}
index a6ad878d29f029d5ece71e04b2e11e53d4b646cf..8b7171c145c58df40d07898ba064eeccdcbd876e 100644 (file)
@@ -3,6 +3,7 @@
 namespace OCA\DAV;
 
 use OCA\DAV\CalDAV\Schedule\IMipPlugin;
+use OCA\DAV\Connector\FedAuth;
 use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
 use OCA\DAV\Files\CustomPropertiesBackend;
@@ -35,7 +36,9 @@ class Server {
                $this->server->setBaseUri($this->baseUri);
 
                $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
-               $this->server->addPlugin(new Plugin($authBackend, 'ownCloud'));
+               $authPlugin = new Plugin($authBackend, 'ownCloud');
+               $authPlugin->addBackend(new FedAuth(\OC::$server->getDatabaseConnection()));
+               $this->server->addPlugin($authPlugin);
                $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());
index e0bb241918e26c7f16c0335645256d395d75e5cb..e6728df1408bd5e0303c46864c73ba7b26d8b949 100644 (file)
@@ -34,7 +34,7 @@
                                <name>token</name>
                                <type>text</type>
                                <length>128</length>
-                               <comments>toke used to exchange the shared secret</comments>
+                               <comments>token used to exchange the shared secret</comments>
                        </field>
                        <field>
                                <name>shared_secret</name>
                                <default>2</default>
                                <comments>current status of the connection</comments>
                        </field>
+                       <field>
+                               <name>sync_token</name>
+                               <type>integer</type>
+                               <notnull>true</notnull>
+                               <default>0</default>
+                               <comments>cardDav sync token</comments>
+                       </field>
                        <index>
                                <name>url_hash</name>
                                <unique>true</unique>
index 7606593f780b884554fc278f59bb212256eab50b..f86a8e15d808d46634d606073163bfeafe020bc8 100644 (file)
@@ -111,7 +111,7 @@ class DbHandler {
         */
        public function getAllServer() {
                $query = $this->connection->getQueryBuilder();
-               $query->select(['url', 'id', 'status'])->from($this->dbTable);
+               $query->select(['url', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable);
                $result = $query->execute()->fetchAll();
                return $result;
        }
@@ -267,4 +267,21 @@ class DbHandler {
                return $normalized;
        }
 
+       /**
+        * @param $username
+        * @param $password
+        * @return bool
+        */
+       public function auth($username, $password) {
+               if ($username !== 'system') {
+                       return false;
+               }
+               $query = $this->connection->getQueryBuilder();
+               $query->select('url')->from($this->dbTable)
+                               ->where($query->expr()->eq('shared_secret', $query->createNamedParameter($password)));
+
+               $result = $query->execute()->fetch();
+               return !empty($result);
+       }
+
 }