diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-07-03 23:13:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-03 23:13:47 +0200 |
commit | 7025f160176ea1440290b4deea8d59eeab1ec83c (patch) | |
tree | 3db69d031b1a9695de89b65bc64299c43bfdfe86 /lib | |
parent | 8b683feca2e003bd50913bb4951012d7c7cc8d4f (diff) | |
parent | 7ff74ae8eda8feb232a9b2c2094ec98641543721 (diff) | |
download | nextcloud-server-7025f160176ea1440290b4deea8d59eeab1ec83c.tar.gz nextcloud-server-7025f160176ea1440290b4deea8d59eeab1ec83c.zip |
Merge pull request #9345 from nextcloud/federation20
Federation 2.0
Diffstat (limited to 'lib')
21 files changed, 1702 insertions, 5 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index f818bc2840f..d2648c2db63 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -132,6 +132,17 @@ return array( 'OCP\\Encryption\\IFile' => $baseDir . '/lib/public/Encryption/IFile.php', 'OCP\\Encryption\\IManager' => $baseDir . '/lib/public/Encryption/IManager.php', 'OCP\\Encryption\\Keys\\IStorage' => $baseDir . '/lib/public/Encryption/Keys/IStorage.php', + 'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => $baseDir . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', + 'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', + 'OCP\\Federation\\Exceptions\\BadRequestException' => $baseDir . '/lib/public/Federation/Exceptions/BadRequestException.php', + 'OCP\\Federation\\Exceptions\\ProviderAlreadyExistsException' => $baseDir . '/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php', + 'OCP\\Federation\\Exceptions\\ProviderCouldNotAddShareException' => $baseDir . '/lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php', + 'OCP\\Federation\\Exceptions\\ProviderDoesNotExistsException' => $baseDir . '/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php', + 'OCP\\Federation\\ICloudFederationFactory' => $baseDir . '/lib/public/Federation/ICloudFederationFactory.php', + 'OCP\\Federation\\ICloudFederationNotification' => $baseDir . '/lib/public/Federation/ICloudFederationNotification.php', + 'OCP\\Federation\\ICloudFederationProvider' => $baseDir . '/lib/public/Federation/ICloudFederationProvider.php', + 'OCP\\Federation\\ICloudFederationProviderManager' => $baseDir . '/lib/public/Federation/ICloudFederationProviderManager.php', + 'OCP\\Federation\\ICloudFederationShare' => $baseDir . '/lib/public/Federation/ICloudFederationShare.php', 'OCP\\Federation\\ICloudId' => $baseDir . '/lib/public/Federation/ICloudId.php', 'OCP\\Federation\\ICloudIdManager' => $baseDir . '/lib/public/Federation/ICloudIdManager.php', 'OCP\\Files' => $baseDir . '/lib/public/Files.php', @@ -660,6 +671,10 @@ return array( 'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php', 'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php', 'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php', + 'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php', + 'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php', + 'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php', + 'OC\\Federation\\CloudFederationShare' => $baseDir . '/lib/private/Federation/CloudFederationShare.php', 'OC\\Federation\\CloudId' => $baseDir . '/lib/private/Federation/CloudId.php', 'OC\\Federation\\CloudIdManager' => $baseDir . '/lib/private/Federation/CloudIdManager.php', 'OC\\Files\\AppData\\AppData' => $baseDir . '/lib/private/Files/AppData/AppData.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 05128f65c4f..4a2580fe757 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -162,6 +162,17 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Encryption\\IFile' => __DIR__ . '/../../..' . '/lib/public/Encryption/IFile.php', 'OCP\\Encryption\\IManager' => __DIR__ . '/../../..' . '/lib/public/Encryption/IManager.php', 'OCP\\Encryption\\Keys\\IStorage' => __DIR__ . '/../../..' . '/lib/public/Encryption/Keys/IStorage.php', + 'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', + 'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', + 'OCP\\Federation\\Exceptions\\BadRequestException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/BadRequestException.php', + 'OCP\\Federation\\Exceptions\\ProviderAlreadyExistsException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php', + 'OCP\\Federation\\Exceptions\\ProviderCouldNotAddShareException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php', + 'OCP\\Federation\\Exceptions\\ProviderDoesNotExistsException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php', + 'OCP\\Federation\\ICloudFederationFactory' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudFederationFactory.php', + 'OCP\\Federation\\ICloudFederationNotification' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudFederationNotification.php', + 'OCP\\Federation\\ICloudFederationProvider' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudFederationProvider.php', + 'OCP\\Federation\\ICloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudFederationProviderManager.php', + 'OCP\\Federation\\ICloudFederationShare' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudFederationShare.php', 'OCP\\Federation\\ICloudId' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudId.php', 'OCP\\Federation\\ICloudIdManager' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudIdManager.php', 'OCP\\Files' => __DIR__ . '/../../..' . '/lib/public/Files.php', @@ -690,6 +701,10 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php', 'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php', 'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php', + 'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php', + 'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php', + 'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php', + 'OC\\Federation\\CloudFederationShare' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationShare.php', 'OC\\Federation\\CloudId' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudId.php', 'OC\\Federation\\CloudIdManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudIdManager.php', 'OC\\Files\\AppData\\AppData' => __DIR__ . '/../../..' . '/lib/private/Files/AppData/AppData.php', diff --git a/lib/private/Federation/CloudFederationFactory.php b/lib/private/Federation/CloudFederationFactory.php new file mode 100644 index 00000000000..11566dd44a9 --- /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 string $sharedByDisplayName display name of the user who shared the resource + * @param string $sharedSecret used to authenticate requests across servers + * @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, $sharedSecret, $shareType, $resourceType) { + return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); + } + + /** + * 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..62af67079e5 --- /dev/null +++ b/lib/private/Federation/CloudFederationNotification.php @@ -0,0 +1,67 @@ +<?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 + * + * @package OC\Federation + * + * @since 14.0.0 + */ +class CloudFederationNotification implements ICloudFederationNotification { + + private $message = []; + + /** + * add a message to the notification + * + * @param string $notificationType (e.g. SHARE_ACCEPTED) + * @param string $resourceType (e.g. file, calendar, contact,...) + * @param string $providerId id of the share + * @param array $notification payload of the notification + * + * @since 14.0.0 + */ + public function setMessage($notificationType, $resourceType, $providerId, array $notification) { + $this->message = [ + 'notificationType' => $notificationType, + 'resourceType' => $resourceType, + 'providerId' => $providerId, + 'notification' => $notification, + ]; + + } + + /** + * get message, ready to send out + * + * @return array + * + * @since 14.0.0 + */ + public function getMessage() { + return $this->message; + } +} diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php new file mode 100644 index 00000000000..254ceb03bf8 --- /dev/null +++ b/lib/private/Federation/CloudFederationProviderManager.php @@ -0,0 +1,242 @@ +<?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 OC\AppFramework\Http; +use OCP\App\IAppManager; +use OCP\Federation\Exceptions\ProviderDoesNotExistsException; +use OCP\Federation\ICloudFederationNotification; +use OCP\Federation\ICloudFederationProvider; +use OCP\Federation\ICloudFederationProviderManager; +use OCP\Federation\ICloudFederationShare; +use OCP\Federation\ICloudIdManager; +use OCP\Http\Client\IClientService; +use OCP\ILogger; + +/** + * Class Manager + * + * Manage Cloud Federation Providers + * + * @package OC\Federation + */ +class CloudFederationProviderManager implements ICloudFederationProviderManager { + + /** @var array list of available cloud federation providers */ + private $cloudFederationProvider; + + /** @var IAppManager */ + private $appManager; + + /** @var IClientService */ + private $httpClientService; + + /** @var ICloudIdManager */ + private $cloudIdManager; + + /** @var ILogger */ + private $logger; + + /** @var array cache OCM end-points */ + private $ocmEndPoints = []; + + private $supportedAPIVersion = '1.0-proposal1'; + + /** + * CloudFederationProviderManager constructor. + * + * @param IAppManager $appManager + * @param IClientService $httpClientService + * @param ICloudIdManager $cloudIdManager + * @param ILogger $logger + */ + public function __construct(IAppManager $appManager, + IClientService $httpClientService, + ICloudIdManager $cloudIdManager, + ILogger $logger) { + $this->cloudFederationProvider= []; + $this->appManager = $appManager; + $this->httpClientService = $httpClientService; + $this->cloudIdManager = $cloudIdManager; + $this->logger = $logger; + } + + + /** + * Registers an callback function which must return an cloud federation provider + * + * @param string $resourceType which resource type does the provider handles + * @param string $displayName user facing name of the federated share provider + * @param callable $callback + */ + public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { + $this->cloudFederationProvider[$resourceType] = [ + 'resourceType' => $resourceType, + '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 [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] + */ + public function getAllCloudFederationProviders() { + return $this->cloudFederationProvider; + } + + /** + * get a specific cloud federation provider + * + * @param string $resourceType + * @return ICloudFederationProvider + * @throws ProviderDoesNotExistsException + */ + public function getCloudFederationProvider($resourceType) { + if (isset($this->cloudFederationProvider[$resourceType])) { + return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); + } else { + throw new ProviderDoesNotExistsException($resourceType); + } + } + + public function sendShare(ICloudFederationShare $share) { + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); + + if (empty($ocmEndPoint)) { + return false; + } + + $client = $this->httpClientService->newClient(); + try { + $response = $client->post($ocmEndPoint . '/shares', [ + 'body' => $share->getShare(), + 'timeout' => 10, + 'connect_timeout' => 10, + ]); + + if ($response->getStatusCode() === Http::STATUS_CREATED) { + $result = json_decode($response->getBody(), true); + return (is_array($result)) ? $result : []; + } + + } catch (\Exception $e) { + // if flat re-sharing is not supported by the remote server + // we re-throw the exception and fall back to the old behaviour. + // (flat re-shares has been introduced in Nextcloud 9.1) + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { + throw $e; + } + } + + return false; + + } + + /** + * @param string $url + * @param ICloudFederationNotification $notification + * @return mixed + */ + public function sendNotification($url, ICloudFederationNotification $notification) { + $ocmEndPoint = $this->getOCMEndPoint($url); + + if (empty($ocmEndPoint)) { + return false; + } + + $client = $this->httpClientService->newClient(); + try { + $response = $client->post($ocmEndPoint . '/notifications', [ + 'body' => $notification->getMessage(), + 'timeout' => 10, + 'connect_timeout' => 10, + ]); + if ($response->getStatusCode() === Http::STATUS_CREATED) { + $result = json_decode($response->getBody(), true); + return (is_array($result)) ? $result : []; + } + } catch (\Exception $e) { + // log the error and return false + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); + } + + return false; + } + + /** + * check if the new cloud federation API is ready to be used + * + * @return bool + */ + public function isReady() { + return $this->appManager->isEnabledForUser('cloud_federation_api'); + } + /** + * check if server supports the new OCM api and ask for the correct end-point + * + * @param string $url full base URL of the cloud server + * @return string + */ + protected function getOCMEndPoint($url) { + + if (isset($this->ocmEndPoints[$url])) { + return $this->ocmEndPoints[$url]; + } + + $client = $this->httpClientService->newClient(); + try { + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); + } catch (\Exception $e) { + $this->ocmEndPoints[$url] = ''; + return ''; + } + + $result = $response->getBody(); + $result = json_decode($result, true); + + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; + + if (isset($result['endPoint']) && $supportedVersion) { + $this->ocmEndPoints[$url] = $result['endPoint']; + return $result['endPoint']; + } + + $this->ocmEndPoints[$url] = ''; + return ''; + } + + +} diff --git a/lib/private/Federation/CloudFederationShare.php b/lib/private/Federation/CloudFederationShare.php new file mode 100644 index 00000000000..0c2795188f0 --- /dev/null +++ b/lib/private/Federation/CloudFederationShare.php @@ -0,0 +1,352 @@ +<?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 string $shareType ('group' or 'user' share) + * @param string $resourceType ('file', 'calendar',...) + * @param string $sharedSecret + */ + public function __construct($shareWith = '', + $name = '', + $description = '', + $providerId = '', + $owner = '', + $ownerDisplayName = '', + $sharedBy = '', + $sharedByDisplayName = '', + $shareType = '', + $resourceType = '', + $sharedSecret = '' + ) { + $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([ + 'name' => 'webdav', + 'options' => [ + 'sharedSecret' => $sharedSecret, + 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions' + ] + ]); + $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 the whole share, ready to send out + * + * @return array + * + * @since 14.0.0 + */ + public function getShare() { + return $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 share Secret + * + * @return string + * + * @since 14.0.0 + */ + public function getShareSecret() { + return $this->share['protocol']['options']['sharedSecret']; + } + + /** + * 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..90e9e81c105 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($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); + }); + + $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..7d866db24fa 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; @@ -116,7 +116,9 @@ class ProviderFactory implements IProviderFactory { $addressHandler, $this->serverContainer->getHTTPClientService(), $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), - $this->serverContainer->getJobList() + $this->serverContainer->getJobList(), + \OC::$server->getCloudFederationProviderManager(), + \OC::$server->getCloudFederationFactory() ); $tokenHandler = new TokenHandler( $this->serverContainer->getSecureRandom() @@ -133,7 +135,7 @@ class ProviderFactory implements IProviderFactory { $this->serverContainer->getConfig(), $this->serverContainer->getUserManager(), $this->serverContainer->getCloudIdManager(), - $this->serverContainer->query(Config::class) + $this->serverContainer->getGlobalScaleConfig() ); } diff --git a/lib/public/Federation/Exceptions/ActionNotSupportedException.php b/lib/public/Federation/Exceptions/ActionNotSupportedException.php new file mode 100644 index 00000000000..2d295bd9d8b --- /dev/null +++ b/lib/public/Federation/Exceptions/ActionNotSupportedException.php @@ -0,0 +1,48 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; + +/** + * Class ActionNotSupportedException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class ActionNotSupportedException extends HintException { + + /** + * ActionNotSupportedException constructor. + * + * @since 14.0.0 + * + */ + public function __construct($action) { + $l = \OC::$server->getL10N('federation'); + $message = 'Action "' . $action . '" not supported or implemented.'; + $hint = $l->t('Action "%s" not supported or implemented.', [$action]); + parent::__construct($message, $hint); + } + +} diff --git a/lib/public/Federation/Exceptions/AuthenticationFailedException.php b/lib/public/Federation/Exceptions/AuthenticationFailedException.php new file mode 100644 index 00000000000..1ea7ec5cd31 --- /dev/null +++ b/lib/public/Federation/Exceptions/AuthenticationFailedException.php @@ -0,0 +1,48 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; + +/** + * Class AuthenticationFailedException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class AuthenticationFailedException extends HintException { + + /** + * BadRequestException constructor. + * + * @since 14.0.0 + * + */ + public function __construct() { + $l = \OC::$server->getL10N('federation'); + $message = 'Authentication failed, wrong token or provider ID given'; + $hint = $l->t('Authentication failed, wrong token or provider ID given'); + parent::__construct($message, $hint); + } + +} diff --git a/lib/public/Federation/Exceptions/BadRequestException.php b/lib/public/Federation/Exceptions/BadRequestException.php new file mode 100644 index 00000000000..9d9e48157a1 --- /dev/null +++ b/lib/public/Federation/Exceptions/BadRequestException.php @@ -0,0 +1,77 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; + +/** + * Class BadRequestException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class BadRequestException extends HintException { + + private $parameterList; + + /** + * BadRequestException constructor. + * + * @since 14.0.0 + * + * @param array $missingParameters + */ + public function __construct(array $missingParameters) { + $l = \OC::$server->getL10N('federation'); + $this->parameterList = $missingParameters; + $parameterList = implode(',', $missingParameters); + $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; + $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); + parent::__construct($message, $hint); + } + + /** + * get array with the return message as defined in the OCM API + * + * @since 14.0.0 + * + * @return array + */ + public function getReturnMessage() { + $result = [ + 'message' => 'RESOURCE_NOT_FOUND', + 'validationErrors' =>[ + ] + ]; + + foreach ($this->parameterList as $missingParameter) { + $result['validationErrors'] = [ + 'name' => $missingParameter, + 'message' => 'NOT_FOUND' + ]; + } + + return $result; + } + +} diff --git a/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php b/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php new file mode 100644 index 00000000000..e5022500d1c --- /dev/null +++ b/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php @@ -0,0 +1,50 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; + +/** + * Class ProviderAlreadyExistsException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class ProviderAlreadyExistsException extends HintException { + + /** + * ProviderAlreadyExistsException constructor. + * + * @since 14.0.0 + * + * @param string $newProviderId cloud federation provider ID of the new provider + * @param string $existingProviderName name of cloud federation provider which already use the same ID + */ + public function __construct($newProviderId, $existingProviderName) { + $l = \OC::$server->getL10N('federation'); + $message = 'Id "' . $newProviderId . '" already used by cloud federation provider "' . $existingProviderName . '"'; + $hint = $l->t('Id "%s" already used by cloud federation provider "%s"', [$newProviderId, $existingProviderName]); + parent::__construct($message, $hint); + } + +} diff --git a/lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php b/lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php new file mode 100644 index 00000000000..80613cc29ac --- /dev/null +++ b/lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php @@ -0,0 +1,51 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; +use OCP\AppFramework\Http; + +/** + * Class ProviderCouldNotAddShareException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class ProviderCouldNotAddShareException extends HintException { + + /** + * ProviderCouldNotAddShareException constructor. + * + * @since 14.0.0 + * + * @param string $message + * @param string $hint + * @param int $code + * @param \Exception|null $previous + */ + public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) { + parent::__construct($message, $hint, $code, $previous); + } + + +} diff --git a/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php b/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php new file mode 100644 index 00000000000..761fcaf809d --- /dev/null +++ b/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php @@ -0,0 +1,49 @@ +<?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 OCP\Federation\Exceptions; + +use OC\HintException; + +/** + * Class ProviderDoesNotExistsException + * + * @package OCP\Federation\Exceptions + * + * @since 14.0.0 + */ +class ProviderDoesNotExistsException extends HintException { + + /** + * ProviderDoesNotExistsException constructor. + * + * @since 14.0.0 + * + * @param string $providerId cloud federation provider ID + */ + public function __construct($providerId) { + $l = \OC::$server->getL10N('federation'); + $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.'; + $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); + parent::__construct($message, $hint); + } + +} diff --git a/lib/public/Federation/ICloudFederationFactory.php b/lib/public/Federation/ICloudFederationFactory.php new file mode 100644 index 00000000000..5cb4dc3106a --- /dev/null +++ b/lib/public/Federation/ICloudFederationFactory.php @@ -0,0 +1,62 @@ +<?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 OCP\Federation; + +/** + * Interface ICloudFederationFactory + * + * @package OCP\Federation + * + * @since 14.0.0 + */ +interface 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 string $sharedByDisplayName display name of the user who shared the resource + * @param string $sharedSecret used to authenticate requests across servers + * @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, $sharedSecret, $shareType, $resourceType); + + /** + * get a Cloud FederationNotification object to prepare a notification you + * want to send + * + * @return ICloudFederationNotification + * + * @since 14.0.0 + */ + public function getCloudFederationNotification(); +} diff --git a/lib/public/Federation/ICloudFederationNotification.php b/lib/public/Federation/ICloudFederationNotification.php new file mode 100644 index 00000000000..c7ceb6d2399 --- /dev/null +++ b/lib/public/Federation/ICloudFederationNotification.php @@ -0,0 +1,53 @@ +<?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 OCP\Federation; + +/** + * Interface ICloudFederationNotification + * + * @package OCP\Federation + * + * @since 14.0.0 + */ +interface ICloudFederationNotification { + + /** + * add a message to the notification + * + * @param string $notificationType (e.g. SHARE_ACCEPTED) + * @param string $resourceType (e.g. file, calendar, contact,...) + * @param $providerId id of the share + * @param array $notification , payload of the notification + * + * @since 14.0.0 + */ + public function setMessage($notificationType, $resourceType, $providerId, array $notification); + + /** + * get message, ready to send out + * + * @return array + * + * @since 14.0.0 + */ + public function getMessage(); +} diff --git a/lib/public/Federation/ICloudFederationProvider.php b/lib/public/Federation/ICloudFederationProvider.php new file mode 100644 index 00000000000..b3574535cb0 --- /dev/null +++ b/lib/public/Federation/ICloudFederationProvider.php @@ -0,0 +1,89 @@ +<?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 OCP\Federation; + +use OCP\Federation\Exceptions\ActionNotSupportedException; +use OCP\Federation\Exceptions\AuthenticationFailedException; +use OCP\Federation\Exceptions\BadRequestException; +use OCP\Federation\Exceptions\ProviderCouldNotAddShareException; +use \OCP\Share\Exceptions\ShareNotFound; + +/** + * Interface ICloudFederationProvider + * + * Enable apps to create their own cloud federation provider + * + * @since 14.0.0 + * + * @package OCP\Federation + */ + +interface ICloudFederationProvider { + + /** + * get the name of the share type, handled by this provider + * + * @return string + * + * @since 14.0.0 + */ + public function getShareType(); + + /** + * share received from another server + * + * @param ICloudFederationShare $share + * @return string provider specific unique ID of the share + * + * @throws ProviderCouldNotAddShareException + * + * @since 14.0.0 + */ + public function shareReceived(ICloudFederationShare $share); + + /** + * notification received from another server + * + * @param string $notificationType (e.g SHARE_ACCEPTED) + * @param string $providerId share ID + * @param array $notification provider specific notification + * @return array $data send back to sender + * + * @throws ShareNotFound + * @throws ActionNotSupportedException + * @throws BadRequestException + * @throws AuthenticationFailedException + * + * @since 14.0.0 + */ + public function notificationReceived($notificationType, $providerId, array $notification); + + /** + * get the supported share types, e.g. "user", "group", etc. + * + * @return array + * + * @since 14.0.0 + */ + public function getSupportedShareTypes(); + +} diff --git a/lib/public/Federation/ICloudFederationProviderManager.php b/lib/public/Federation/ICloudFederationProviderManager.php new file mode 100644 index 00000000000..f1e932388bf --- /dev/null +++ b/lib/public/Federation/ICloudFederationProviderManager.php @@ -0,0 +1,107 @@ +<?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 OCP\Federation; + +/** + * Class ICloudFederationProviderManager + * + * Manage cloud federation providers + * + * @since 14.0.0 + * + * @package OCP\Federation + */ +interface ICloudFederationProviderManager { + + /** + * Registers an callback function which must return an cloud federation provider + * + * @param string $resourceType which resource type does the provider handles + * @param string $displayName user facing name of the federated share provider + * @param callable $callback + * @throws Exceptions\ProviderAlreadyExistsException + * + * @since 14.0.0 + */ + public function addCloudFederationProvider($resourceType, $displayName, callable $callback); + + /** + * remove cloud federation provider + * + * @param string $resourceType + * + * @since 14.0.0 + */ + public function removeCloudFederationProvider($resourceType); + + /** + * get a list of all cloudFederationProviders + * + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] + * + * @since 14.0.0 + */ + public function getAllCloudFederationProviders(); + + /** + * get a specific cloud federation provider + * + * @param string $resourceType + * @return ICloudFederationProvider + * @throws Exceptions\ProviderDoesNotExistsException; + * + * @since 14.0.0 + */ + public function getCloudFederationProvider($resourceType); + + /** + * send federated share + * + * @param ICloudFederationShare $share + * @return mixed + * + * @since 14.0.0 + */ + public function sendShare(ICloudFederationShare $share); + + /** + * send notification about existing share + * + * @param string $url + * @param ICloudFederationNotification $notification + * @return mixed + * + * @since 14.0.0 + */ + public function sendNotification($url, ICloudFederationNotification $notification); + + /** + * check if the new cloud federation API is ready to be used + * + * @return bool + * + * @since 14.0.0 + */ + public function isReady(); + + +} diff --git a/lib/public/Federation/ICloudFederationShare.php b/lib/public/Federation/ICloudFederationShare.php new file mode 100644 index 00000000000..fda934d9e8d --- /dev/null +++ b/lib/public/Federation/ICloudFederationShare.php @@ -0,0 +1,250 @@ +<?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 OCP\Federation; + +/** + * Interface ICloudFederationShare + * + * @package OCP\Federation + * + * @since 14.0.0 + */ +interface ICloudFederationShare { + + /** + * set uid of the recipient + * + * @param string $user + * + * @since 14.0.0 + */ + public function setShareWith($user); + + /** + * set resource name (e.g. file, calendar, contact,...) + * + * @param string $name + * + * @since 14.0.0 + */ + public function setResourceName($name); + + /** + * set resource type (e.g. file, calendar, contact,...) + * + * @param string $resourceType + * + * @since 14.0.0 + */ + public function setResourceType($resourceType); + + /** + * set resource description (optional) + * + * @param string $description + * + * @since 14.0.0 + */ + public function setDescription($description); + + /** + * set provider ID (e.g. file ID) + * + * @param string $providerId + * + * @since 14.0.0 + */ + public function setProviderId($providerId); + + /** + * set owner UID + * + * @param string $owner + * + * @since 14.0.0 + */ + public function setOwner($owner); + + /** + * set owner display name + * + * @param string $ownerDisplayName + * + * @since 14.0.0 + */ + public function setOwnerDisplayName($ownerDisplayName); + + /** + * set UID of the user who sends the share + * + * @param string $sharedBy + * + * @since 14.0.0 + */ + public function setSharedBy($sharedBy); + + /** + * set display name of the user who sends the share + * + * @param $sharedByDisplayName + * + * @since 14.0.0 + */ + public function setSharedByDisplayName($sharedByDisplayName); + + /** + * set protocol specification + * + * @param array $protocol + * + * @since 14.0.0 + */ + public function setProtocol(array $protocol); + + /** + * share type (group or user) + * + * @param string $shareType + * + * @since 14.0.0 + */ + public function setShareType($shareType); + + /** + * get the whole share, ready to send out + * + * @return array + * + * @since 14.0.0 + */ + public function getShare(); + + /** + * get uid of the recipient + * + * @return string + * + * @since 14.0.0 + */ + public function getShareWith(); + + /** + * get resource name (e.g. file, calendar, contact,...) + * + * @return string + * + * @since 14.0.0 + */ + public function getResourceName(); + + /** + * get resource type (e.g. file, calendar, contact,...) + * + * @return string + * + * @since 14.0.0 + */ + public function getResourceType(); + + /** + * get resource description (optional) + * + * @return string + * + * @since 14.0.0 + */ + public function getDescription(); + + /** + * get provider ID (e.g. file ID) + * + * @return string + * + * @since 14.0.0 + */ + public function getProviderId(); + + /** + * get owner UID + * + * @return string + * + * @since 14.0.0 + */ + public function getOwner(); + + /** + * get owner display name + * + * @return string + * + * @since 14.0.0 + */ + public function getOwnerDisplayName(); + + /** + * get UID of the user who sends the share + * + * @return string + * + * @since 14.0.0 + */ + public function getSharedBy(); + + /** + * get display name of the user who sends the share + * + * @return string + * + * @since 14.0.0 + */ + public function getSharedByDisplayName(); + + /** + * get share type (group or user) + * + * @return string + * + * @since 14.0.0 + */ + public function getShareType(); + + /** + * get share Secret + * + * @return string + * + * @since 14.0.0 + */ + public function getShareSecret(); + + + /** + * get protocol specification + * + * @return array + * + * @since 14.0.0 + */ + public function getProtocol(); + +} diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php index 96015d3f8a8..639487660b6 100644 --- a/lib/public/IServerContainer.php +++ b/lib/public/IServerContainer.php @@ -45,6 +45,8 @@ // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; use OCP\Log\ILogFactory; +use OCP\Federation\ICloudFederationFactory; +use OCP\Federation\ICloudFederationProviderManager; use OCP\Security\IContentSecurityPolicyManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -554,6 +556,24 @@ interface IServerContainer extends IContainer { public function getCloudIdManager(); /** + * @return \OCP\GlobalScale\IConfig + * @since 14.0.0 + */ + public function getGlobalScaleConfig(); + + /** + * @return ICloudFederationFactory + * @since 14.0.0 + */ + public function getCloudFederationFactory(); + + /** + * @return ICloudFederationProviderManager + * @since 14.0.0 + */ + public function getCloudFederationProviderManager(); + + /** * @return \OCP\Remote\Api\IApiFactory * @since 13.0.0 */ diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php index 4db43d953cf..4a1ac9b8b8d 100644 --- a/lib/public/Share/IShareProvider.php +++ b/lib/public/Share/IShareProvider.php @@ -25,7 +25,6 @@ namespace OCP\Share; use OCP\Files\Folder; -use OCP\Share\Exceptions\ShareNotFound; use OCP\Files\Node; /** @@ -46,7 +45,7 @@ interface IShareProvider { /** * Create a share - * + * * @param \OCP\Share\IShare $share * @return \OCP\Share\IShare The share object * @since 9.0.0 |