Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use OCP\Security\Signature\IIncomingSignedRequest;
use OCP\Security\Signature\ISignatureManager;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Util;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -414,21 +413,12 @@ public function receiveNotification($notificationType, $resourceType, $providerI
}

/**
* map login name to internal LDAP UID if a LDAP backend is in use
*
* @param string $uid
* @return string mixed
* Map login name to internal LDAP UID if an LDAP backend is in use
*/
private function mapUid($uid) {
// FIXME this should be a method in the user management instead
private function mapUid(string $uid): string {
$this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
['uid' => &$uid]
);
$uid = $this->userManager->getUserNameFromLoginName($uid);
$this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]);

return $uid;
}

Expand Down
72 changes: 21 additions & 51 deletions apps/federatedfilesharing/lib/AddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OCP\HintException;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;
use OCP\IUserManager;

/**
* Class AddressHandler - parse, modify and construct federated sharing addresses
Expand All @@ -22,26 +22,23 @@ class AddressHandler {

/**
* AddressHandler constructor.
*
* @param IURLGenerator $urlGenerator
* @param IL10N $l
* @param ICloudIdManager $cloudIdManager
*/
public function __construct(
private IURLGenerator $urlGenerator,
private IL10N $l,
private ICloudIdManager $cloudIdManager,
private readonly IURLGenerator $urlGenerator,
private readonly IL10N $l,
private readonly ICloudIdManager $cloudIdManager,
private readonly IUserManager $userManager,
) {
}

/**
* split user and remote from federated cloud id
* Split user and remote from federated cloud id.
*
* @param string $address federated share address
* @return array<string> [user, remoteURL]
* @throws HintException
*/
public function splitUserRemote($address) {
public function splitUserRemote(string $address): array {
try {
$cloudId = $this->cloudIdManager->resolveCloudId($address);
return [$cloudId->getUser(), $cloudId->getRemote()];
Expand All @@ -52,55 +49,36 @@ public function splitUserRemote($address) {
}

/**
* generate remote URL part of federated ID
* Generate remote URL part of federated ID
*
* @return string url of the current server
*/
public function generateRemoteURL() {
public function generateRemoteURL(): string {
return $this->urlGenerator->getAbsoluteURL('/');
}

/**
* check if two federated cloud IDs refer to the same user
* Check if two federated cloud IDs refer to the same user
*
* @param string $user1
* @param string $server1
* @param string $user2
* @param string $server2
* @return bool true if both users and servers are the same
*/
public function compareAddresses($user1, $server1, $user2, $server2) {
public function compareAddresses(string $user1, string $server1, string $user2, string $server2): bool {
$normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1));
$normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2));

if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) {
// FIXME this should be a method in the user management instead
Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
['uid' => &$user1]
);
Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
['uid' => &$user2]
);

if ($user1 === $user2) {
return true;
}
if (rtrim($normalizedServer1, '/') !== rtrim($normalizedServer2, '/')) {
return false;
}

return false;
$user1 = $this->userManager->getUserNameFromLoginName($user1);
$user2 = $this->userManager->getUserNameFromLoginName($user2);
return $user1 === $user2;
}

/**
* remove protocol from URL
*
* @param string $url
* @return string
* Remove protocol from URL
*/
public function removeProtocolFromUrl($url) {
public function removeProtocolFromUrl(string $url): string {
if (str_starts_with($url, 'https://')) {
return substr($url, strlen('https://'));
} elseif (str_starts_with($url, 'http://')) {
Expand All @@ -111,17 +89,9 @@ public function removeProtocolFromUrl($url) {
}

/**
* check if the url contain the protocol (http or https)
*
* @param string $url
* @return bool
* Check if the url contain the protocol (http or https).
*/
public function urlContainProtocol($url) {
if (str_starts_with($url, 'https://')
|| str_starts_with($url, 'http://')) {
return true;
}

return false;
public function urlContainProtocol(string $url): bool {
return str_starts_with($url, 'https://') || str_starts_with($url, 'http://');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ public function shareReceived(ICloudFederationShare $share): string {

if ($shareType === IShare::TYPE_USER) {
$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
['uid' => &$shareWith]
);
$shareWith = $this->userManager->getUserNameFromLoginName($shareWith);
$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);

$user = $this->userManager->get($shareWith);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'OCA\\Files_External\\Controller\\StoragesController' => $baseDir . '/../lib/Controller/StoragesController.php',
'OCA\\Files_External\\Controller\\UserGlobalStoragesController' => $baseDir . '/../lib/Controller/UserGlobalStoragesController.php',
'OCA\\Files_External\\Controller\\UserStoragesController' => $baseDir . '/../lib/Controller/UserStoragesController.php',
'OCA\\Files_External\\Event\\LoadAdditionalBackendEvent' => $baseDir . '/../lib/Event/LoadAdditionalBackendEvent.php',
'OCA\\Files_External\\Event\\StorageCreatedEvent' => $baseDir . '/../lib/Event/StorageCreatedEvent.php',
'OCA\\Files_External\\Event\\StorageDeletedEvent' => $baseDir . '/../lib/Event/StorageDeletedEvent.php',
'OCA\\Files_External\\Event\\StorageUpdatedEvent' => $baseDir . '/../lib/Event/StorageUpdatedEvent.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ComposerStaticInitFiles_External
'OCA\\Files_External\\Controller\\StoragesController' => __DIR__ . '/..' . '/../lib/Controller/StoragesController.php',
'OCA\\Files_External\\Controller\\UserGlobalStoragesController' => __DIR__ . '/..' . '/../lib/Controller/UserGlobalStoragesController.php',
'OCA\\Files_External\\Controller\\UserStoragesController' => __DIR__ . '/..' . '/../lib/Controller/UserStoragesController.php',
'OCA\\Files_External\\Event\\LoadAdditionalBackendEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalBackendEvent.php',
'OCA\\Files_External\\Event\\StorageCreatedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageCreatedEvent.php',
'OCA\\Files_External\\Event\\StorageDeletedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageDeletedEvent.php',
'OCA\\Files_External\\Event\\StorageUpdatedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageUpdatedEvent.php',
Expand Down
17 changes: 17 additions & 0 deletions apps/files_external/lib/Event/LoadAdditionalBackendEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
* SPDX-FileContributor: Carl Schwan
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files_External\Event;

use OCP\EventDispatcher\Event;

class LoadAdditionalBackendEvent extends Event {

}
59 changes: 17 additions & 42 deletions apps/files_external/lib/Service/BackendService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use OCA\Files_External\AppInfo\Application;
use OCA\Files_External\Config\IConfigHandler;
use OCA\Files_External\ConfigLexicon;
use OCA\Files_External\Event\LoadAdditionalBackendEvent;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\Server;
Expand Down Expand Up @@ -71,21 +71,20 @@ public function registerBackendProvider(IBackendProvider $provider) {
$this->backendProviders[] = $provider;
}

private function callForRegistrations() {
private function callForRegistrations(): void {
static $eventSent = false;
if (!$eventSent) {
Server::get(IEventDispatcher::class)->dispatch(
'OCA\\Files_External::loadAdditionalBackends',
new GenericEvent()
);
Server::get(IEventDispatcher::class)->dispatchTyped(new LoadAdditionalBackendEvent());
$eventSent = true;
}
}

private function loadBackendProviders() {
private function loadBackendProviders(): void {
$this->callForRegistrations();
foreach ($this->backendProviders as $provider) {
$this->registerBackends($provider->getBackends());
foreach ($provider->getBackends() as $backend) {
$this->registerBackend($backend);
}
}
$this->backendProviders = [];
}
Expand All @@ -94,27 +93,25 @@ private function loadBackendProviders() {
* Register an auth mechanism provider
*
* @since 9.1.0
* @param IAuthMechanismProvider $provider
*/
public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) {
public function registerAuthMechanismProvider(IAuthMechanismProvider $provider): void {
$this->authMechanismProviders[] = $provider;
}

private function loadAuthMechanismProviders() {
private function loadAuthMechanismProviders(): void {
$this->callForRegistrations();
foreach ($this->authMechanismProviders as $provider) {
$this->registerAuthMechanisms($provider->getAuthMechanisms());
foreach ($provider->getAuthMechanisms() as $mechanism) {
$this->registerAuthMechanism($mechanism);
}
}
$this->authMechanismProviders = [];
}

/**
* Register a backend
*
* @deprecated 9.1.0 use registerBackendProvider()
* @param Backend $backend
*/
public function registerBackend(Backend $backend) {
private function registerBackend(Backend $backend): void {
if (!$this->isAllowedUserBackend($backend)) {
$backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
}
Expand All @@ -123,22 +120,10 @@ public function registerBackend(Backend $backend) {
}
}

/**
* @deprecated 9.1.0 use registerBackendProvider()
* @param Backend[] $backends
*/
public function registerBackends(array $backends) {
foreach ($backends as $backend) {
$this->registerBackend($backend);
}
}
/**
* Register an authentication mechanism
*
* @deprecated 9.1.0 use registerAuthMechanismProvider()
* @param AuthMechanism $authMech
*/
public function registerAuthMechanism(AuthMechanism $authMech) {
private function registerAuthMechanism(AuthMechanism $authMech): void {
if (!$this->isAllowedAuthMechanism($authMech)) {
$authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
}
Expand All @@ -147,22 +132,12 @@ public function registerAuthMechanism(AuthMechanism $authMech) {
}
}

/**
* @deprecated 9.1.0 use registerAuthMechanismProvider()
* @param AuthMechanism[] $mechanisms
*/
public function registerAuthMechanisms(array $mechanisms) {
foreach ($mechanisms as $mechanism) {
$this->registerAuthMechanism($mechanism);
}
}

/**
* Get all backends
*
* @return Backend[]
* @return array<string, Backend>
*/
public function getBackends() {
public function getBackends(): array {
$this->loadBackendProviders();
// only return real identifiers, no aliases
$backends = [];
Expand All @@ -177,7 +152,7 @@ public function getBackends() {
*
* @return Backend[]
*/
public function getAvailableBackends() {
public function getAvailableBackends(): array {
return array_filter($this->getBackends(), fn (Backend $backend) => $backend->checkRequiredDependencies() === []);
}

Expand Down
1 change: 1 addition & 0 deletions apps/user_ldap/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'OCA\\User_LDAP\\LDAPProvider' => $baseDir . '/../lib/LDAPProvider.php',
'OCA\\User_LDAP\\LDAPProviderFactory' => $baseDir . '/../lib/LDAPProviderFactory.php',
'OCA\\User_LDAP\\LDAPUtility' => $baseDir . '/../lib/LDAPUtility.php',
'OCA\\User_LDAP\\Listener\\LoadAdditionalBackendListener' => $baseDir . '/../lib/Listener/LoadAdditionalBackendListener.php',
'OCA\\User_LDAP\\LoginListener' => $baseDir . '/../lib/LoginListener.php',
'OCA\\User_LDAP\\Mapping\\AbstractMapping' => $baseDir . '/../lib/Mapping/AbstractMapping.php',
'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir . '/../lib/Mapping/GroupMapping.php',
Expand Down
1 change: 1 addition & 0 deletions apps/user_ldap/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ComposerStaticInitUser_LDAP
'OCA\\User_LDAP\\LDAPProvider' => __DIR__ . '/..' . '/../lib/LDAPProvider.php',
'OCA\\User_LDAP\\LDAPProviderFactory' => __DIR__ . '/..' . '/../lib/LDAPProviderFactory.php',
'OCA\\User_LDAP\\LDAPUtility' => __DIR__ . '/..' . '/../lib/LDAPUtility.php',
'OCA\\User_LDAP\\Listener\\LoadAdditionalBackendListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalBackendListener.php',
'OCA\\User_LDAP\\LoginListener' => __DIR__ . '/..' . '/../lib/LoginListener.php',
'OCA\\User_LDAP\\Mapping\\AbstractMapping' => __DIR__ . '/..' . '/../lib/Mapping/AbstractMapping.php',
'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__ . '/..' . '/../lib/Mapping/GroupMapping.php',
Expand Down
Loading
Loading