No longer add trusted servers on federated share creation
It was disabled by default for ages. And often resulted in unwanted behavior. If admins want trusted servers they just have to do it manually. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
d18aa63560
commit
771dfc8170
|
@ -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
|
||||
|
|
|
@ -37,11 +37,13 @@ namespace Composer\Autoload;
|
|||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Björn Schießle <bjoern@schiessle.org>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,6 @@ style('federation', 'settings-admin')
|
|||
<h2><?php p($l->t('Trusted servers')); ?></h2>
|
||||
<p class="settings-hint"><?php p($l->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.')); ?></p>
|
||||
|
||||
<p>
|
||||
<input id="autoAddServers" type="checkbox" class="checkbox" <?php if ($_['autoAddServers']) {
|
||||
p('checked');
|
||||
} ?> />
|
||||
<label for="autoAddServers"><?php p($l->t('Add server automatically once a federated share was created successfully')); ?></label>
|
||||
</p>
|
||||
|
||||
<ul id="listOfTrustedServers">
|
||||
<?php foreach ($_['trustedServers'] as $trustedServer) { ?>
|
||||
<li id="<?php p($trustedServer['id']); ?>">
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Björn Schießle <bjoern@schiessle.org>
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
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],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue