diff --git a/apps/federation/appinfo/routes.php b/apps/federation/appinfo/routes.php index 706bbdc000..15ade1536b 100644 --- a/apps/federation/appinfo/routes.php +++ b/apps/federation/appinfo/routes.php @@ -34,11 +34,6 @@ return [ 'url' => '/trusted-servers/{id}', 'verb' => 'DELETE' ], - [ - 'name' => 'Settings#autoAddServers', - 'url' => '/auto-add-servers', - 'verb' => 'POST' - ], ], 'ocs' => [ // old endpoints, only used by Nextcloud and ownCloud diff --git a/apps/federation/composer/composer/ClassLoader.php b/apps/federation/composer/composer/ClassLoader.php index fce8549f07..247294d66e 100644 --- a/apps/federation/composer/composer/ClassLoader.php +++ b/apps/federation/composer/composer/ClassLoader.php @@ -37,11 +37,13 @@ namespace Composer\Autoload; * * @author Fabien Potencier * @author Jordi Boggiano - * @see http://www.php-fig.org/psr/psr-0/ - * @see http://www.php-fig.org/psr/psr-4/ + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ */ class ClassLoader { + private $vendorDir; + // PSR-4 private $prefixLengthsPsr4 = array(); private $prefixDirsPsr4 = array(); @@ -57,10 +59,17 @@ class ClassLoader private $missingClasses = array(); private $apcuPrefix; + private static $registeredLoaders = array(); + + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + } + public function getPrefixes() { if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', $this->prefixesPsr0); + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); } return array(); @@ -300,6 +309,17 @@ class ClassLoader public function register($prepend = false) { spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } } /** @@ -308,6 +328,10 @@ class ClassLoader public function unregister() { spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } } /** @@ -367,6 +391,16 @@ class ClassLoader return $file; } + /** + * Returns the currently registered loaders indexed by their corresponding vendor directories. + * + * @return self[] + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + private function findFileWithExtension($class, $ext) { // PSR-4 lookup diff --git a/apps/federation/composer/composer/autoload_classmap.php b/apps/federation/composer/composer/autoload_classmap.php index 8274bf4524..18cc80e31a 100644 --- a/apps/federation/composer/composer/autoload_classmap.php +++ b/apps/federation/composer/composer/autoload_classmap.php @@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = $vendorDir; return array( + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 'OCA\\Federation\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir . '/../lib/BackgroundJob/GetSharedSecret.php', 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php', @@ -14,7 +15,6 @@ return array( 'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', 'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php', 'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php', - 'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php', 'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php', 'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', 'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php', diff --git a/apps/federation/composer/composer/autoload_real.php b/apps/federation/composer/composer/autoload_real.php index 75b98c785d..fed3f44342 100644 --- a/apps/federation/composer/composer/autoload_real.php +++ b/apps/federation/composer/composer/autoload_real.php @@ -23,12 +23,12 @@ class ComposerAutoloaderInitFederation } spl_autoload_register(array('ComposerAutoloaderInitFederation', 'loadClassLoader'), true, true); - self::$loader = $loader = new \Composer\Autoload\ClassLoader(); + self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); spl_autoload_unregister(array('ComposerAutoloaderInitFederation', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { - require_once __DIR__ . '/autoload_static.php'; + require __DIR__ . '/autoload_static.php'; call_user_func(\Composer\Autoload\ComposerStaticInitFederation::getInitializer($loader)); } else { diff --git a/apps/federation/composer/composer/autoload_static.php b/apps/federation/composer/composer/autoload_static.php index e005986b9f..80fc75771b 100644 --- a/apps/federation/composer/composer/autoload_static.php +++ b/apps/federation/composer/composer/autoload_static.php @@ -21,6 +21,7 @@ class ComposerStaticInitFederation ); public static $classMap = array ( + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 'OCA\\Federation\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/GetSharedSecret.php', 'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php', @@ -29,7 +30,6 @@ class ComposerStaticInitFederation 'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', 'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php', 'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php', - 'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', 'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php', 'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', 'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php', diff --git a/apps/federation/js/settings-admin.js b/apps/federation/js/settings-admin.js index da3f3c2d1a..cd276f3f02 100644 --- a/apps/federation/js/settings-admin.js +++ b/apps/federation/js/settings-admin.js @@ -19,7 +19,7 @@ */ (function( $ ) { - + // ocFederationAddServer $.fn.ocFederationAddServer = function() { @@ -27,14 +27,13 @@ ========================================================================== */ var $wrapper = $(this), - + // Buttons $btnAddServer = $wrapper.find("#ocFederationAddServerButton"), $btnSubmit = $wrapper.find("#ocFederationSubmit"), - + // Inputs $inpServerUrl = $wrapper.find("#serverUrl"), - $inpAutoAddServers = $wrapper.find("#autoAddServers"), // misc $msgBox = $wrapper.find("#ocFederationAddServer .msg"), @@ -55,17 +54,8 @@ $srvList.on('click', 'li > .icon-delete', function() { var $this = $(this).parent(); var id = $this.attr('id'); - - removeServer( id ); - }); - $inpAutoAddServers.on("change", function() { - $.post( - OC.generateUrl('/apps/federation/auto-add-servers'), - { - autoAddServers: $(this).is(":checked") - } - ); + removeServer( id ); }); $btnSubmit.on("click", function() @@ -94,7 +84,7 @@ } }); }; - + /* private Functions ========================================================================== */ @@ -132,11 +122,11 @@ }); } - + })( jQuery ); $(document).ready(function () { $('#ocFederationSettings').ocFederationAddServer(); - + }); diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php index 09a6eed4ab..5c0e804353 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -28,7 +28,6 @@ namespace OCA\Federation\AppInfo; use OCA\Federation\DAV\FedAuth; -use OCA\Federation\Hooks; use OCA\Federation\Middleware\AddServerMiddleware; use OCP\AppFramework\App; use OCP\SabrePluginEvent; @@ -53,20 +52,8 @@ class Application extends App { $container->registerMiddleWare('AddServerMiddleware'); } - /** - * listen to federated_share_added hooks to auto-add new servers to the - * list of trusted servers. - */ public function registerHooks() { $container = $this->getContainer(); - $hooksManager = $container->query(Hooks::class); - - Util::connectHook( - Share::class, - 'federated_share_added', - $hooksManager, - 'addServerHook' - ); $dispatcher = $container->getServer()->getEventDispatcher(); $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) { diff --git a/apps/federation/lib/Controller/SettingsController.php b/apps/federation/lib/Controller/SettingsController.php index 7f68f23836..853dc2584c 100644 --- a/apps/federation/lib/Controller/SettingsController.php +++ b/apps/federation/lib/Controller/SettingsController.php @@ -87,16 +87,6 @@ class SettingsController extends Controller { return new DataResponse(); } - /** - * enable/disable to automatically add servers to the list of trusted servers - * once a federated share was created and accepted successfully - * - * @param bool $autoAddServers - */ - public function autoAddServers($autoAddServers) { - $this->trustedServers->setAutoAddServers($autoAddServers); - } - /** * check if the server should be added to the list of trusted servers or not * diff --git a/apps/federation/lib/Hooks.php b/apps/federation/lib/Hooks.php deleted file mode 100644 index f02409ef24..0000000000 --- a/apps/federation/lib/Hooks.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Federation; - -class Hooks { - - /** @var TrustedServers */ - private $trustedServers; - - public function __construct(TrustedServers $trustedServers) { - $this->trustedServers = $trustedServers; - } - - /** - * add servers to the list of trusted servers once a federated share was established - * - * @param array $params - */ - public function addServerHook($params) { - if ( - $this->trustedServers->getAutoAddServers() === true && - $this->trustedServers->isTrustedServer($params['server']) === false - ) { - $this->trustedServers->addServer($params['server']); - } - } -} diff --git a/apps/federation/templates/settings-admin.php b/apps/federation/templates/settings-admin.php index 2bc3684ccd..7498db0589 100644 --- a/apps/federation/templates/settings-admin.php +++ b/apps/federation/templates/settings-admin.php @@ -10,13 +10,6 @@ style('federation', 'settings-admin')

t('Trusted servers')); ?>

t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?>

-

- /> - -

-
  • diff --git a/apps/federation/tests/HooksTest.php b/apps/federation/tests/HooksTest.php deleted file mode 100644 index afb6b2408f..0000000000 --- a/apps/federation/tests/HooksTest.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @author Joas Schilling - * @author Roeland Jago Douma - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Federation\Tests; - -use OCA\Federation\Hooks; -use OCA\Federation\TrustedServers; -use Test\TestCase; - -class HooksTest extends TestCase { - - /** @var \PHPUnit_Framework_MockObject_MockObject | TrustedServers */ - private $trustedServers; - - /** @var Hooks */ - private $hooks; - - protected function setUp(): void { - parent::setUp(); - - $this->trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers') - ->disableOriginalConstructor()->getMock(); - - $this->hooks = new Hooks($this->trustedServers); - } - - /** - * @dataProvider dataTestAddServerHook - * - * @param bool $autoAddEnabled is auto-add enabled - * @param bool $isTrustedServer is the server already in the list of trusted servers - * @param bool $addServer should the server be added - */ - public function testAddServerHook($autoAddEnabled, $isTrustedServer, $addServer) { - $this->trustedServers->expects($this->any())->method('getAutoAddServers') - ->willReturn($autoAddEnabled); - $this->trustedServers->expects($this->any())->method('isTrustedServer') - ->with('url')->willReturn($isTrustedServer); - - if ($addServer) { - $this->trustedServers->expects($this->once())->method('addServer') - ->with('url'); - } else { - $this->trustedServers->expects($this->never())->method('addServer'); - } - - $this->hooks->addServerHook(['server' => 'url']); - } - - public function dataTestAddServerHook() { - return [ - [true, true, false], - [false, true, false], - [true, false, true], - [false, false, false], - ]; - } -}