aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Federation
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Federation')
-rw-r--r--lib/private/Federation/CloudFederationFactory.php1
-rw-r--r--lib/private/Federation/CloudFederationNotification.php1
-rw-r--r--lib/private/Federation/CloudFederationProviderManager.php4
-rw-r--r--lib/private/Federation/CloudFederationShare.php1
-rw-r--r--lib/private/Federation/CloudIdManager.php47
5 files changed, 38 insertions, 16 deletions
diff --git a/lib/private/Federation/CloudFederationFactory.php b/lib/private/Federation/CloudFederationFactory.php
index f5f25d14ea1..d06de0f2f58 100644
--- a/lib/private/Federation/CloudFederationFactory.php
+++ b/lib/private/Federation/CloudFederationFactory.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/lib/private/Federation/CloudFederationNotification.php b/lib/private/Federation/CloudFederationNotification.php
index 855580843ba..6ae805df1d9 100644
--- a/lib/private/Federation/CloudFederationNotification.php
+++ b/lib/private/Federation/CloudFederationNotification.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php
index e9354294351..81b5d717a56 100644
--- a/lib/private/Federation/CloudFederationProviderManager.php
+++ b/lib/private/Federation/CloudFederationProviderManager.php
@@ -227,8 +227,8 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager
private function prepareOcmPayload(string $uri, string $payload): array {
$payload = array_merge($this->getDefaultRequestOptions(), ['body' => $payload]);
- if ($this->appConfig->getValueBool('core', OCMSignatoryManager::APPCONFIG_SIGN_ENFORCED, lazy: true) &&
- $this->signatoryManager->getRemoteSignatory($this->signatureManager->extractIdentityFromUri($uri)) === null) {
+ if ($this->appConfig->getValueBool('core', OCMSignatoryManager::APPCONFIG_SIGN_ENFORCED, lazy: true)
+ && $this->signatoryManager->getRemoteSignatory($this->signatureManager->extractIdentityFromUri($uri)) === null) {
return $payload;
}
diff --git a/lib/private/Federation/CloudFederationShare.php b/lib/private/Federation/CloudFederationShare.php
index 3ec53d89ed3..2eb06b3acea 100644
--- a/lib/private/Federation/CloudFederationShare.php
+++ b/lib/private/Federation/CloudFederationShare.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php
index 7e7adda3d39..c599d9046a6 100644
--- a/lib/private/Federation/CloudIdManager.php
+++ b/lib/private/Federation/CloudIdManager.php
@@ -14,6 +14,7 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
+use OCP\Federation\ICloudIdResolver;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
@@ -21,27 +22,19 @@ use OCP\IUserManager;
use OCP\User\Events\UserChangedEvent;
class CloudIdManager implements ICloudIdManager {
- /** @var IManager */
- private $contactsManager;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var IUserManager */
- private $userManager;
private ICache $memCache;
private ICache $displayNameCache;
- /** @var array[] */
private array $cache = [];
+ /** @var ICloudIdResolver[] */
+ private array $cloudIdResolvers = [];
public function __construct(
- IManager $contactsManager,
- IURLGenerator $urlGenerator,
- IUserManager $userManager,
ICacheFactory $cacheFactory,
IEventDispatcher $eventDispatcher,
+ private IManager $contactsManager,
+ private IURLGenerator $urlGenerator,
+ private IUserManager $userManager,
) {
- $this->contactsManager = $contactsManager;
- $this->urlGenerator = $urlGenerator;
- $this->userManager = $userManager;
$this->memCache = $cacheFactory->createDistributed('cloud_id_');
$this->displayNameCache = $cacheFactory->createDistributed('cloudid_name_');
$eventDispatcher->addListener(UserChangedEvent::class, [$this, 'handleUserEvent']);
@@ -81,6 +74,12 @@ class CloudIdManager implements ICloudIdManager {
public function resolveCloudId(string $cloudId): ICloudId {
// TODO magic here to get the url and user instead of just splitting on @
+ foreach ($this->cloudIdResolvers as $resolver) {
+ if ($resolver->isValidCloudId($cloudId)) {
+ return $resolver->resolveCloudId($cloudId);
+ }
+ }
+
if (!$this->isValidCloudId($cloudId)) {
throw new \InvalidArgumentException('Invalid cloud id');
}
@@ -251,6 +250,26 @@ class CloudIdManager implements ICloudIdManager {
* @return bool
*/
public function isValidCloudId(string $cloudId): bool {
- return str_contains($cloudId, '@');
+ foreach ($this->cloudIdResolvers as $resolver) {
+ if ($resolver->isValidCloudId($cloudId)) {
+ return true;
+ }
+ }
+
+ return strpos($cloudId, '@') !== false;
+ }
+
+ public function createCloudId(string $id, string $user, string $remote, ?string $displayName = null): ICloudId {
+ return new CloudId($id, $user, $remote, $displayName);
+ }
+
+ public function registerCloudIdResolver(ICloudIdResolver $resolver): void {
+ array_unshift($this->cloudIdResolvers, $resolver);
+ }
+
+ public function unregisterCloudIdResolver(ICloudIdResolver $resolver): void {
+ if (($key = array_search($resolver, $this->cloudIdResolvers)) !== false) {
+ array_splice($this->cloudIdResolvers, $key, 1);
+ }
}
}