summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2018-04-18 16:05:11 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2018-07-02 11:29:27 +0200
commit5cfe20675dfa1f895af47b4a8c93cf479d53b200 (patch)
tree66e0631e2f8791168797a4a7957a420e4ac429cf /lib/private
parent22bb834c48ad31add1d4bebc17de98d6e7d5d226 (diff)
downloadnextcloud-server-5cfe20675dfa1f895af47b4a8c93cf479d53b200.tar.gz
nextcloud-server-5cfe20675dfa1f895af47b4a8c93cf479d53b200.zip
start implementing federated sharing 2.0
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Federation/CloudFederationFactory.php63
-rw-r--r--lib/private/Federation/CloudFederationNotification.php52
-rw-r--r--lib/private/Federation/CloudFederationProviderManager.php108
-rw-r--r--lib/private/Federation/CloudFederationShare.php336
-rw-r--r--lib/private/Server.php38
-rw-r--r--lib/private/Share20/ProviderFactory.php4
6 files changed, 599 insertions, 2 deletions
diff --git a/lib/private/Federation/CloudFederationFactory.php b/lib/private/Federation/CloudFederationFactory.php
new file mode 100644
index 00000000000..4f42eb50bca
--- /dev/null
+++ b/lib/private/Federation/CloudFederationFactory.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @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 OC\Federation;
+
+use OCP\Federation\ICloudFederationFactory;
+use OCP\Federation\ICloudFederationNotification;
+use OCP\Federation\ICloudFederationShare;
+
+class CloudFederationFactory implements ICloudFederationFactory {
+
+ /**
+ * get a CloudFederationShare Object to prepare a share you want to send
+ *
+ * @param string $shareWith
+ * @param string $name resource name (e.g. document.odt)
+ * @param string $description share description (optional)
+ * @param string $providerId resource UID on the provider side
+ * @param string $owner provider specific UID of the user who owns the resource
+ * @param string $ownerDisplayName display name of the user who shared the item
+ * @param string $sharedBy provider specific UID of the user who shared the resource
+ * @param $sharedByDisplayName display name of the user who shared the resource
+ * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
+ * @param string $shareType ('group' or 'user' share)
+ * @param $resourceType ('file', 'calendar',...)
+ * @return ICloudFederationShare
+ *
+ * @since 14.0.0
+ */
+ public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
+ return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType);
+ }
+
+ /**
+ * get a Cloud FederationNotification object to prepare a notification you
+ * want to send
+ *
+ * @return ICloudFederationNotification
+ *
+ * @since 14.0.0
+ */
+ public function getCloudFederationNotification() {
+ return new CloudFederationNotification();
+ }
+}
diff --git a/lib/private/Federation/CloudFederationNotification.php b/lib/private/Federation/CloudFederationNotification.php
new file mode 100644
index 00000000000..ed87b9b0e5d
--- /dev/null
+++ b/lib/private/Federation/CloudFederationNotification.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @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 OC\Federation;
+
+use OCP\Federation\ICloudFederationNotification;
+
+class CloudFederationNotification implements ICloudFederationNotification {
+
+ private $message = [];
+
+ /**
+ * add a message to the notification
+ *
+ * @param string $identifier
+ * @param string $message
+ *
+ * @since 14.0.0
+ */
+ public function setMessage($identifier, $message) {
+ $this->message[$identifier] = $message;
+ }
+
+ /**
+ * get JSON encoded Message, ready to send out
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getMessage() {
+ return json_encode($this->message);
+ }
+}
diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php
new file mode 100644
index 00000000000..925d42a688a
--- /dev/null
+++ b/lib/private/Federation/CloudFederationProviderManager.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @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 OC\Federation;
+
+use OCP\Federation\Exceptions\ProviderAlreadyExistsException;
+use OCP\Federation\Exceptions\ProviderDoesNotExistsException;
+use OCP\Federation\ICloudFederationNotification;
+use OCP\Federation\ICloudFederationProvider;
+use OCP\Federation\ICloudFederationProviderManager;
+use OCP\Federation\ICloudFederationShare;
+
+/**
+ * Class Manager
+ *
+ * Manage Cloud Federation Providers
+ *
+ * @package OC\Federation
+ */
+class CloudFederationProviderManager implements ICloudFederationProviderManager {
+
+ /** @var array list of available cloud federation providers */
+ private $cloudFederationProvider;
+
+ public function __construct() {
+ $this->cloudFederationProvider= [];
+ }
+
+
+ /**
+ * Registers an callback function which must return an cloud federation provider
+ *
+ * @param string $shareType which share type does the provider handles
+ * @param string $displayName user facing name of the federated share provider
+ * @param callable $callback
+ */
+ public function addCloudFederationProvider($shareType, $displayName, callable $callback) {
+ \OC::$server->getRemoteApiFactory();
+
+ $this->cloudFederationProvider[$shareType] = [
+ 'shareType' => $shareType,
+ 'displayName' => $displayName,
+ 'callback' => $callback,
+ ];
+
+ }
+
+ /**
+ * remove cloud federation provider
+ *
+ * @param string $providerId
+ */
+ public function removeCloudFederationProvider($providerId) {
+ unset($this->cloudFederationProvider[$providerId]);
+ }
+
+ /**
+ * get a list of all cloudFederationProviders
+ *
+ * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
+ */
+ public function getAllCloudFederationProviders() {
+ return $this->cloudFederationProvider;
+ }
+
+ /**
+ * get a specific cloud federation provider
+ *
+ * @param string $shareType
+ * @return ICloudFederationProvider
+ * @throws ProviderDoesNotExistsException
+ */
+ public function getCloudFederationProvider($shareType) {
+ if (isset($this->cloudFederationProvider[$shareType])) {
+ return call_user_func($this->cloudFederationProvider[$shareType]['callback']);
+ } else {
+ throw new ProviderDoesNotExistsException($shareType);
+ }
+ }
+
+ public function sendShare(ICloudFederationShare $share) {
+ // TODO: Implement sendShare() method.
+ }
+
+ public function sendNotification(ICloudFederationNotification $notification) {
+ // TODO: Implement sendNotification() method.
+ }
+
+}
diff --git a/lib/private/Federation/CloudFederationShare.php b/lib/private/Federation/CloudFederationShare.php
new file mode 100644
index 00000000000..4622dc096d7
--- /dev/null
+++ b/lib/private/Federation/CloudFederationShare.php
@@ -0,0 +1,336 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @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 OC\Federation;
+
+use OCP\Federation\ICloudFederationShare;
+
+class CloudFederationShare implements ICloudFederationShare {
+
+ private $share = [
+ 'shareWith' => '',
+ 'shareType' => '',
+ 'name' => '',
+ 'resourceType' => '',
+ 'description' => '',
+ 'providerId' => '',
+ 'owner' => '',
+ 'ownerDisplayName' => '',
+ 'sharedBy' => '',
+ 'sharedByDisplayName' => '',
+ 'protocol' => []
+ ];
+
+ /**
+ * get a CloudFederationShare Object to prepare a share you want to send
+ *
+ * @param string $shareWith
+ * @param string $name resource name (e.g. document.odt)
+ * @param string $description share description (optional)
+ * @param string $providerId resource UID on the provider side
+ * @param string $owner provider specific UID of the user who owns the resource
+ * @param string $ownerDisplayName display name of the user who shared the item
+ * @param string $sharedBy provider specific UID of the user who shared the resource
+ * @param string $sharedByDisplayName display name of the user who shared the resource
+ * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
+ * @param string $shareType ('group' or 'user' share)
+ * @param $resourceType ('file', 'calendar',...)
+ *
+ */
+ public function __construct($shareWith = '',
+ $name = '',
+ $description = '',
+ $providerId = '',
+ $owner = '',
+ $ownerDisplayName = '',
+ $sharedBy = '',
+ $sharedByDisplayName = '',
+ $protocol = [],
+ $shareType = '',
+ $resourceType = ''
+ ) {
+ $this->setShareWith($shareWith);
+ $this->setResourceName($name);
+ $this->setDescription($description);
+ $this->setProviderId($providerId);
+ $this->setOwner($owner);
+ $this->setOwnerDisplayName($ownerDisplayName);
+ $this->setSharedBy($sharedBy);
+ $this->setSharedByDisplayName($sharedByDisplayName);
+ $this->setProtocol($protocol);
+ $this->setShareType($shareType);
+ $this->setResourceType($resourceType);
+
+ }
+
+ /**
+ * set uid of the recipient
+ *
+ * @param string $user
+ *
+ * @since 14.0.0
+ */
+ public function setShareWith($user) {
+ $this->share['shareWith'] = $user;
+ }
+
+ /**
+ * set resource name (e.g. document.odt)
+ *
+ * @param string $name
+ *
+ * @since 14.0.0
+ */
+ public function setResourceName($name) {
+ $this->share['name'] = $name;
+ }
+
+ /**
+ * set resource type (e.g. file, calendar, contact,...)
+ *
+ * @param string $resourceType
+ *
+ * @since 14.0.0
+ */
+ public function setResourceType($resourceType) {
+ $this->share['resourceType'] = $resourceType;
+ }
+
+ /**
+ * set resource description (optional)
+ *
+ * @param string $description
+ *
+ * @since 14.0.0
+ */
+ public function setDescription($description) {
+ $this->share['description'] = $description;
+ }
+
+ /**
+ * set provider ID (e.g. file ID)
+ *
+ * @param string $providerId
+ *
+ * @since 14.0.0
+ */
+ public function setProviderId($providerId) {
+ $this->share['providerId'] = $providerId;
+ }
+
+ /**
+ * set owner UID
+ *
+ * @param string $owner
+ *
+ * @since 14.0.0
+ */
+ public function setOwner($owner) {
+ $this->share['owner'] = $owner;
+ }
+
+ /**
+ * set owner display name
+ *
+ * @param string $ownerDisplayName
+ *
+ * @since 14.0.0
+ */
+ public function setOwnerDisplayName($ownerDisplayName) {
+ $this->share['ownerDisplayName'] = $ownerDisplayName;
+ }
+
+ /**
+ * set UID of the user who sends the share
+ *
+ * @param string $sharedBy
+ *
+ * @since 14.0.0
+ */
+ public function setSharedBy($sharedBy) {
+ $this->share['sharedBy'] = $sharedBy;
+ }
+
+ /**
+ * set display name of the user who sends the share
+ *
+ * @param $sharedByDisplayName
+ *
+ * @since 14.0.0
+ */
+ public function setSharedByDisplayName($sharedByDisplayName) {
+ $this->share['sharedByDisplayName'] = $sharedByDisplayName;
+ }
+
+ /**
+ * set protocol specification
+ *
+ * @param array $protocol
+ *
+ * @since 14.0.0
+ */
+ public function setProtocol(array $protocol) {
+ $this->share['protocol'] = $protocol;
+ }
+
+ /**
+ * share type (group or user)
+ *
+ * @param string $shareType
+ *
+ * @since 14.0.0
+ */
+ public function setShareType($shareType) {
+ $this->share['shareType'] = $shareType;
+ }
+
+ /**
+ * get JSON encoded share, ready to send out
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getShare() {
+ return json_encode($this->share);
+ }
+
+ /**
+ * get uid of the recipient
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getShareWith() {
+ return $this->share['shareWith'];
+ }
+
+ /**
+ * get resource name (e.g. file, calendar, contact,...)
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getResourceName() {
+ return $this->share['name'];
+ }
+
+ /**
+ * get resource type (e.g. file, calendar, contact,...)
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getResourceType() {
+ return $this->share['resourceType'];
+ }
+
+ /**
+ * get resource description (optional)
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getDescription() {
+ return $this->share['description'];
+ }
+
+ /**
+ * get provider ID (e.g. file ID)
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getProviderId() {
+ return $this->share['providerId'];
+ }
+
+ /**
+ * get owner UID
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getOwner() {
+ return $this->share['owner'];
+ }
+
+ /**
+ * get owner display name
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getOwnerDisplayName() {
+ return $this->share['ownerDisplayName'];
+ }
+
+ /**
+ * get UID of the user who sends the share
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getSharedBy() {
+ return $this->share['sharedBy'];
+ }
+
+ /**
+ * get display name of the user who sends the share
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getSharedByDisplayName() {
+ return $this->share['sharedByDisplayName'];
+ }
+
+ /**
+ * get share type (group or user)
+ *
+ * @return string
+ *
+ * @since 14.0.0
+ */
+ public function getShareType() {
+ return $this->share['shareType'];
+ }
+
+ /**
+ * get protocol specification
+ *
+ * @return array
+ *
+ * @since 14.0.0
+ */
+ public function getProtocol() {
+ return $this->share['protocol'];
+ }
+}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 3c15873206d..170bc6b2584 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -68,6 +68,8 @@ use OC\Contacts\ContactsMenu\ActionFactory;
use OC\Contacts\ContactsMenu\ContactsStore;
use OC\Diagnostics\EventLogger;
use OC\Diagnostics\QueryLogger;
+use OC\Federation\CloudFederationFactory;
+use OC\Federation\CloudFederationProviderManager;
use OC\Federation\CloudIdManager;
use OC\Files\Config\UserMountCache;
use OC\Files\Config\UserMountCacheListener;
@@ -124,9 +126,12 @@ use OCP\Collaboration\AutoComplete\IManager;
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Defaults;
use OCA\Theming\Util;
+use OCP\Federation\ICloudFederationFactory;
+use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager;
use OCP\Authentication\LoginCredentials\IStore;
use OCP\Files\NotFoundException;
+use OCP\GlobalScale\IConfig;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -1107,6 +1112,18 @@ class Server extends ServerContainer implements IServerContainer {
return new CloudIdManager();
});
+ $this->registerService(IConfig::class, function (Server $c) {
+ return new GlobalScale\Config($c->getConfig());
+ });
+
+ $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
+ return new CloudFederationProviderManager();
+ });
+
+ $this->registerService(ICloudFederationFactory::class, function (Server $c) {
+ return new CloudFederationFactory();
+ });
+
$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
@@ -1974,6 +1991,20 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
+ * @return \OCP\GlobalScale\IConfig
+ */
+ public function getGlobalScaleConfig() {
+ return $this->query(IConfig::class);
+ }
+
+ /**
+ * @return \OCP\Federation\ICloudFederationProviderManager
+ */
+ public function getCloudFederationProviderManager() {
+ return $this->query(ICloudFederationProviderManager::class);
+ }
+
+ /**
* @return \OCP\Remote\Api\IApiFactory
*/
public function getRemoteApiFactory() {
@@ -1981,6 +2012,13 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
+ * @return \OCP\Federation\ICloudFederationFactory
+ */
+ public function getCloudFederationFactory() {
+ return $this->query(ICloudFederationFactory::class);
+ }
+
+ /**
* @return \OCP\Remote\IInstanceFactory
*/
public function getRemoteInstanceFactory() {
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index 3716189445f..456b6dbc596 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -29,10 +29,10 @@
namespace OC\Share20;
use OC\CapabilitiesManager;
-use OC\GlobalScale\Config;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
+use OCA\FederatedFileSharing\OCM\CloudFederationProvider;
use OCA\FederatedFileSharing\TokenHandler;
use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
@@ -133,7 +133,7 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getConfig(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getCloudIdManager(),
- $this->serverContainer->query(Config::class)
+ $this->serverContainer->getGlobalScaleConfig()
);
}