Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5cfe206
start implementing federated sharing 2.0
schiessle Apr 18, 2018
21e64ec
implement receiving of federated shares
schiessle Apr 30, 2018
4c8f3d6
add cloud federation api app
schiessle Apr 30, 2018
6208f25
check if cloud federation api is ready
schiessle May 2, 2018
a3948e8
use new API to send a federated share if possible
schiessle May 4, 2018
db428ea
send accept share notification (WIP)
schiessle May 9, 2018
af178ef
check API Version
schiessle May 14, 2018
daba042
update capabilities
schiessle May 28, 2018
bbce8c3
adjust to latest api version
schiessle May 28, 2018
8889e14
implement accept share notification
schiessle May 29, 2018
c572e84
detect correctly if a share was send successful
schiessle May 29, 2018
b7b8430
fix capabilities
schiessle May 29, 2018
41a1528
implement decline share
schiessle May 30, 2018
fab4e56
send reshare over OCM API
schiessle Jun 4, 2018
a176a1f
implement unshare notification
schiessle Jun 4, 2018
d77eedd
- Don't remove share before all notifications are created, otherwise …
schiessle Jun 5, 2018
2bb1956
implement RESHARE_UNDO notification
schiessle Jun 5, 2018
ed41572
send RESHARE_CHANGE_PERMISSION message
schiessle Jun 5, 2018
61485e3
fix check for reshare permissions
schiessle Jun 5, 2018
957b27f
replace \OCP\Federation\Exception\ShareNotFoundException with the gen…
schiessle Jun 7, 2018
84fc188
some minor fixes and clode cleanup
schiessle Jun 7, 2018
34c4527
add ocm-provider to the list of expected files
schiessle Jun 11, 2018
5d0d33a
remove unused method
schiessle Jun 11, 2018
9d145bb
update tests
schiessle Jun 11, 2018
2e19213
fix notification tests
schiessle Jun 12, 2018
9365fd2
fix external manager tests
schiessle Jun 12, 2018
21b8a87
implement config check
schiessle Jun 12, 2018
2781412
make sure that remote url gets stored with a trailing '/'
schiessle Jun 12, 2018
22d9246
send the display name back after a federated share was received
schiessle Jun 13, 2018
5c8b262
let the actual federated share provider check if incoming/outgoing sh…
schiessle Jun 13, 2018
e251b34
cleanup variable naming, it is actually a resource type
schiessle Jun 13, 2018
8d4da30
add support for different share types
schiessle Jun 13, 2018
cfb3e80
remove the makefile
schiessle Jun 14, 2018
086e7a0
remove debug output
schiessle Jun 18, 2018
cdf8abb
look for correct OCM permissions
schiessle Jun 25, 2018
511a34b
always enable cloud federation api
schiessle Jun 29, 2018
411bae5
fix return type from send share
schiessle Jun 29, 2018
ce567b6
remove unused code
schiessle Jul 2, 2018
7ff74ae
cache results from ocm end-point discovery
schiessle Jul 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send accept share notification (WIP)
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Jul 2, 2018
commit db428ea5471a5be5517911b3bf2f3a6d3f86e297
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Federation\Exceptions\ActionNotSupportedException;
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
use OCP\Federation\Exceptions\ShareNotFoundException;
use OCP\Federation\ICloudFederationFactory;
Expand Down Expand Up @@ -190,13 +191,12 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
/**
* receive notification about existing share
*
* @param $resourceType ('file', 'calendar',...)
* @param string $name resource name (e.g "file", "calendar",...)
* @param string $id unique id of the corresponding item on the receiving site
* @param array $notification contain the actual notification, content is defined by cloud federation provider
* @param string $notificationType (notification type, e.g. SHARE_ACCEPTED)
* @param string $resourceType (calendar, file, contact,...)
* @param array $message contain the actual notification, content is defined by cloud federation provider
* @return JSONResponse
*/
public function receiveNotification($resourceType, $name, $id, $notification) {
public function receiveNotification($notificationType, $resourceType, $message) {
if (!$this->config->incomingRequestsEnabled()) {
return new JSONResponse(
['message' => 'This server doesn\'t support outgoing federated shares'],
Expand All @@ -205,9 +205,9 @@ public function receiveNotification($resourceType, $name, $id, $notification) {
}

// check if all required parameters are set
if ($name === null ||
$id === null ||
!is_array($notification)
if ($notificationType === null ||
$resourceType === null ||
!is_array($message)
) {
return new JSONResponse(
['message' => 'Missing arguments'],
Expand All @@ -217,7 +217,7 @@ public function receiveNotification($resourceType, $name, $id, $notification) {

try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
$provider->notificationReceived($id, $notification);
$provider->notificationReceived($notificationType, $message);
} catch (ProviderDoesNotExistsException $e) {
return new JSONResponse(
['message' => $e->getMessage()],
Expand All @@ -228,6 +228,11 @@ public function receiveNotification($resourceType, $name, $id, $notification) {
['message' => $e->getMessage()],
Http::STATUS_BAD_REQUEST
);
} catch (ActionNotSupportedException $e) {
return new JSONResponse(
['message' => $e->getMessage()],
Http::STATUS_NOT_IMPLEMENTED
);
} catch (\Exception $e) {
return new JSONResponse(
['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Activity\IManager as IActivityManager;
use OCP\App\IAppManager;
use OCP\Federation\Exceptions\ActionNotSupportedException;
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
use OCP\Federation\Exceptions\ShareNotFoundException;
use OCP\Federation\ICloudFederationProvider;
use OCP\Federation\ICloudFederationShare;
use OCP\Federation\ICloudIdManager;
Expand Down Expand Up @@ -178,6 +180,7 @@ public function shareReceived(ICloudFederationShare $share) {
\OC::$server->getNotificationManager(),
\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
$shareWith
);

Expand Down Expand Up @@ -230,15 +233,22 @@ public function shareReceived(ICloudFederationShare $share) {
/**
* notification received from another server
*
* @param string $id unique ID of a already existing share
* @param array $notification provider specific notification
* @param string $notificationType (e.g. SHARE_ACCEPTED)
* @param array $message
*
* @throws \OCP\Federation\Exceptions\ShareNotFoundException
* @throws ShareNotFoundException
* @throws ActionNotSupportedException
*
* @since 14.0.0
*/
public function notificationReceived($id, $notification) {
// TODO: Implement notificationReceived() method.
public function notificationReceived($notificationType, array $message) {
switch ($notificationType) {
case 'SHARE_ACCEPTED' :
return;
}


throw new ActionNotSupportedException($notificationType);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function __construct(array $urlParams = array()) {
$server->getHTTPClientService(),
$server->getNotificationManager(),
$server->query(\OCP\OCS\IDiscoveryService::class),
$server->getCloudFederationProviderManager(),
$server->getCloudFederationFactory(),
$uid
);
});
Expand Down
45 changes: 45 additions & 0 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

use OC\Files\Filesystem;
use OCA\Files_Sharing\Helper;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
Expand Down Expand Up @@ -79,13 +81,21 @@ class Manager {
*/
private $discoveryService;

/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

/** @var ICloudFederationFactory */
private $cloudFederationFactory;

/**
* @param IDBConnection $connection
* @param \OC\Files\Mount\Manager $mountManager
* @param IStorageFactory $storageLoader
* @param IClientService $clientService
* @param IManager $notificationManager
* @param IDiscoveryService $discoveryService
* @param ICloudFederationProviderManager $cloudFederationProviderManager
* @param ICloudFederationFactory $cloudFederationFactory
* @param string $uid
*/
public function __construct(IDBConnection $connection,
Expand All @@ -94,6 +104,8 @@ public function __construct(IDBConnection $connection,
IClientService $clientService,
IManager $notificationManager,
IDiscoveryService $discoveryService,
ICloudFederationProviderManager $cloudFederationProviderManager,
ICloudFederationFactory $cloudFederationFactory,
$uid) {
$this->connection = $connection;
$this->mountManager = $mountManager;
Expand All @@ -102,6 +114,8 @@ public function __construct(IDBConnection $connection,
$this->uid = $uid;
$this->notificationManager = $notificationManager;
$this->discoveryService = $discoveryService;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
$this->cloudFederationFactory = $cloudFederationFactory;
}

/**
Expand Down Expand Up @@ -274,6 +288,12 @@ public function processNotification($remoteShare) {
*/
private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {

$result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback);

if($result === true) {
return true;
}

$federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING');
$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';

Expand All @@ -299,6 +319,31 @@ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {
return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
}

/**
* try send accept message to ocm end-point
*
* @param string $remoteDomain
* @param string $token
* @param $remoteId
* @param string $feedback
* @return mixed
*/
protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) {
switch ($feedback) {
case 'accept':
$notification = $this->cloudFederationFactory->getCloudFederationNotification();
$notification->setMessage('SHARE_ACCEPTED', 'file',
[
'id' => $remoteId,
'access_token' => $token
]
);
return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
}

}


/**
* remove '/user/files' from the path and trailing slashes
*
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static function deleteUser($params) {
\OC::$server->getHTTPClientService(),
\OC::$server->getNotificationManager(),
\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
$params['uid']);

$manager->removeUserShares($params['uid']);
Expand Down
19 changes: 12 additions & 7 deletions lib/private/Federation/CloudFederationNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,28 @@ class CloudFederationNotification implements ICloudFederationNotification {
/**
* add a message to the notification
*
* @param string $identifier
* @param string $message
* @param string $notificationType (e.g. SHARE_ACCEPTED)
* @param string $resourceType (e.g. file, calendar, contact,...)
* @param array $message
*
* @since 14.0.0
*/
public function setMessage($identifier, $message) {
$this->message[$identifier] = $message;
public function setMessage($notificationType, $resourceType, array $message) {
$this->message = [
'notificationType' => $notificationType,
'resourceType' => $resourceType,
'message' => $message,
];
}

/**
* get JSON encoded Message, ready to send out
* get message, ready to send out
*
* @return string
* @return array
*
* @since 14.0.0
*/
public function getMessage() {
return json_encode($this->message);
return $this->message;
}
}
50 changes: 43 additions & 7 deletions lib/private/Federation/CloudFederationProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@

namespace OC\Federation;

use OC\AppFramework\Http;
use OCP\App\IAppManager;
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;
use OCP\Federation\ICloudIdManager;
use OCP\Http\Client\IClientService;
use OCP\ILogger;

/**
* Class Manager
Expand All @@ -53,20 +54,26 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager
/** @var ICloudIdManager */
private $cloudIdManager;

/** @var ILogger */
private $logger;

/**
* CloudFederationProviderManager constructor.
*
* @param IAppManager $appManager
* @param IClientService $httpClientService
* @param ICloudIdManager $cloudIdManager
* @param ILogger $logger
*/
public function __construct(IAppManager $appManager,
IClientService $httpClientService,
ICloudIdManager $cloudIdManager) {
ICloudIdManager $cloudIdManager,
ILogger $logger) {
$this->cloudFederationProvider= [];
$this->appManager = $appManager;
$this->httpClientService = $httpClientService;
$this->cloudIdManager = $cloudIdManager;
$this->logger = $logger;
}


Expand Down Expand Up @@ -135,8 +142,11 @@ public function sendShare(ICloudFederationShare $share) {
'timeout' => 10,
'connect_timeout' => 10,
]);
$result['result'] = $response->getBody();
$result['success'] = true;

if ($response->getStatusCode() === Http::STATUS_OK) {
return true;
}

} 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.
Expand All @@ -146,12 +156,38 @@ public function sendShare(ICloudFederationShare $share) {
}
}

return true;
return false;

}

public function sendNotification(ICloudFederationNotification $notification) {
// TODO: Implement sendNotification() method.
/**
* @param string $url
* @param ICloudFederationNotification $notification
* @return bool
*/
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_OK) {
return true;
}
} catch (\Exception $e) {
// log the error and return false
$this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ public function __construct($webRoot, \OC\Config $config) {
});

$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager());
return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
});

$this->registerService(ICloudFederationFactory::class, function (Server $c) {
Expand Down
Loading