Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion apps/dav/lib/CardDAV/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ public function __construct(
* @psalm-return list{0: ?string, 1: boolean}
* @throws \Exception
*/
public function syncRemoteAddressBook(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken, string $targetBookHash, string $targetPrincipal, array $targetProperties): array {
public function syncRemoteAddressBook(
string $url,
string $userName,
string $addressBookUrl,
string $sharedSecret,
?string $syncToken,
string $targetBookHash,
string $targetPrincipal,
array $targetProperties,
bool $tokenOnly = false,
): array {
// 1. create addressbook
$book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookHash, $targetProperties);
$addressBookId = $book['id'];
Expand All @@ -55,6 +65,9 @@ public function syncRemoteAddressBook(string $url, string $userName, string $add
try {
$absoluteUri = $this->prepareUri($url, $addressBookUrl);
$response = $this->requestSyncReport($absoluteUri, $userName, $sharedSecret, $syncToken);
if ($tokenOnly) {
return [$response['token'], false];
}
} catch (ClientExceptionInterface $ex) {
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
// remote server revoked access to the address book, remove it
Expand Down
1 change: 1 addition & 0 deletions apps/federation/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php',
'OCA\\Federation\\Command\\SyncFederationAddressBooks' => $baseDir . '/../lib/Command/SyncFederationAddressBooks.php',
'OCA\\Federation\\Command\\SyncFederationCalendars' => $baseDir . '/../lib/Command/SyncFederationCalendars.php',
'OCA\\Federation\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
'OCA\\Federation\\Controller\\OCSAuthAPIController' => $baseDir . '/../lib/Controller/OCSAuthAPIController.php',
'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php',
Expand Down
1 change: 1 addition & 0 deletions apps/federation/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ComposerStaticInitFederation
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php',
'OCA\\Federation\\Command\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/Command/SyncFederationAddressBooks.php',
'OCA\\Federation\\Command\\SyncFederationCalendars' => __DIR__ . '/..' . '/../lib/Command/SyncFederationCalendars.php',
'OCA\\Federation\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
'OCA\\Federation\\Controller\\OCSAuthAPIController' => __DIR__ . '/..' . '/../lib/Controller/OCSAuthAPIController.php',
'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/federation/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Federation\AppInfo;

use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Federation\ConfigLexicon;
use OCA\Federation\Listener\SabrePluginAuthInitListener;
use OCA\Federation\Listener\TrustedServerRemovedListener;
use OCP\AppFramework\App;
Expand All @@ -32,6 +33,8 @@ public function __construct($urlParams = []) {
public function register(IRegistrationContext $context): void {
$context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class);
$context->registerEventListener(TrustedServerRemovedEvent::class, TrustedServerRemovedListener::class);

$context->registerConfigLexicon(ConfigLexicon::class);
}

#[\Override]
Expand Down
43 changes: 43 additions & 0 deletions apps/federation/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Federation;

use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for federation.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const string IGNORE_REMOTE_SYSTEM_ADDRESS_BOOK = 'ignore_remote_system_address_book';

#[\Override]
public function getStrictness(): Strictness {
return Strictness::NOTICE;
}

#[\Override]
public function getAppConfigs(): array {
return [
new Entry(self::IGNORE_REMOTE_SYSTEM_ADDRESS_BOOK, ValueType::BOOL, true, 'Ignore system address book from trusted servers', true, note: 'This does not stop your own instance from replying to request from trusted servers'),
];
}

#[\Override]
public function getUserConfigs(): array {
return [];
}
}
5 changes: 4 additions & 1 deletion apps/federation/lib/SyncFederationAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCA\DAV\CardDAV\SyncService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Services\IAppConfig;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;

Expand All @@ -18,6 +19,7 @@ public function __construct(
protected DbHandler $dbHandler,
private SyncService $syncService,
private IDiscoveryService $ocsDiscoveryService,
private IAppConfig $appConfig,
private LoggerInterface $logger,
) {
}
Expand Down Expand Up @@ -64,7 +66,8 @@ public function syncThemAll(\Closure $callback, bool $full = false) {
$syncToken,
$targetBookId,
$targetPrincipal,
$targetBookProperties
$targetBookProperties,
$this->appConfig->getAppValueBool(ConfigLexicon::IGNORE_REMOTE_SYSTEM_ADDRESS_BOOK),
);
} while ($truncated);

Expand Down
7 changes: 4 additions & 3 deletions apps/federation/tests/SyncFederationAddressbooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Federation\DbHandler;
use OCA\Federation\SyncFederationAddressBooks;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Services\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -49,7 +50,7 @@ public function testSync(): void {
->willReturn(['1', false]);

/** @var SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->createMock(IAppConfig::class), $this->logger);
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
Expand All @@ -73,7 +74,7 @@ public function testException(): void {
->willThrowException(new \Exception('something did not work out'));

/** @var SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->createMock(IAppConfig::class), $this->logger);
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
Expand All @@ -100,7 +101,7 @@ public function testSuccessfulSyncWithoutChangesAfterFailure(): void {
->willReturn(['0', false]);

/** @var SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->createMock(IAppConfig::class), $this->logger);
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
Expand Down
Loading