2018-04-18 10:05:11 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2018-04-18 10:05:11 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-04-18 10:05:11 -04:00
|
|
|
*/
|
2026-05-28 08:54:31 -04:00
|
|
|
|
2018-04-18 10:05:11 -04:00
|
|
|
namespace OC\Federation;
|
|
|
|
|
|
|
|
|
|
use OCP\Federation\ICloudFederationFactory;
|
|
|
|
|
use OCP\Federation\ICloudFederationNotification;
|
|
|
|
|
use OCP\Federation\ICloudFederationShare;
|
2026-05-27 15:33:36 -04:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
|
|
|
|
use OCP\OCM\Exceptions\OCMProviderException;
|
|
|
|
|
use OCP\OCM\IOCMDiscoveryService;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
2018-04-18 10:05:11 -04:00
|
|
|
|
|
|
|
|
class CloudFederationFactory implements ICloudFederationFactory {
|
2026-05-27 15:33:36 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IOCMDiscoveryService $ocmDiscoveryService,
|
|
|
|
|
private ICloudIdManager $cloudIdManager,
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
) {
|
|
|
|
|
}
|
2018-04-18 10:05:11 -04:00
|
|
|
/**
|
|
|
|
|
* 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
|
2018-05-28 11:13:19 -04:00
|
|
|
* @param string $sharedByDisplayName display name of the user who shared the resource
|
|
|
|
|
* @param string $sharedSecret used to authenticate requests across servers
|
2018-04-18 10:05:11 -04:00
|
|
|
* @param string $shareType ('group' or 'user' share)
|
|
|
|
|
* @param $resourceType ('file', 'calendar',...)
|
|
|
|
|
* @return ICloudFederationShare
|
|
|
|
|
*
|
|
|
|
|
* @since 14.0.0
|
|
|
|
|
*/
|
2026-04-28 13:36:04 -04:00
|
|
|
#[\Override]
|
2018-05-28 11:13:19 -04:00
|
|
|
public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) {
|
2026-05-27 15:33:36 -04:00
|
|
|
$useExchangeToken = false;
|
|
|
|
|
$remoteDomain = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
|
|
|
|
|
$remoteDomain = $cloudId->getRemote();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$remoteProvider = $this->ocmDiscoveryService->discover($remoteDomain);
|
|
|
|
|
$capabilities = $remoteProvider->getCapabilities();
|
|
|
|
|
$useExchangeToken = $capabilities->hasExchangeToken();
|
|
|
|
|
|
|
|
|
|
$this->logger->debug('OCM provider capabilities discovered', [
|
|
|
|
|
'remote' => $remoteDomain,
|
|
|
|
|
'capabilities' => $capabilities->toArray(),
|
|
|
|
|
'useExchangeToken' => $useExchangeToken,
|
|
|
|
|
]);
|
|
|
|
|
} catch (OCMProviderException $e) {
|
|
|
|
|
$this->logger->warning('Failed to discover OCM provider, using legacy share method', [
|
|
|
|
|
'remote' => $remoteDomain,
|
|
|
|
|
'exception' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
|
$this->logger->warning('Invalid cloud ID format, using legacy share method', [
|
|
|
|
|
'shareWith' => $shareWith,
|
|
|
|
|
'exception' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CloudFederationShare(
|
|
|
|
|
$shareWith,
|
|
|
|
|
$name,
|
|
|
|
|
$description,
|
|
|
|
|
$providerId,
|
|
|
|
|
$owner,
|
|
|
|
|
$ownerDisplayName,
|
|
|
|
|
$sharedBy,
|
|
|
|
|
$sharedByDisplayName,
|
|
|
|
|
$shareType,
|
|
|
|
|
$resourceType,
|
|
|
|
|
$sharedSecret,
|
|
|
|
|
$useExchangeToken,
|
|
|
|
|
$remoteDomain
|
|
|
|
|
);
|
2018-04-18 10:05:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get a Cloud FederationNotification object to prepare a notification you
|
|
|
|
|
* want to send
|
|
|
|
|
*
|
|
|
|
|
* @return ICloudFederationNotification
|
|
|
|
|
*
|
|
|
|
|
* @since 14.0.0
|
|
|
|
|
*/
|
2026-04-28 13:36:04 -04:00
|
|
|
#[\Override]
|
2018-04-18 10:05:11 -04:00
|
|
|
public function getCloudFederationNotification() {
|
|
|
|
|
return new CloudFederationNotification();
|
|
|
|
|
}
|
|
|
|
|
}
|