aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/ajax')
-rw-r--r--apps/user_ldap/ajax/clearMappings.php74
-rw-r--r--apps/user_ldap/ajax/deleteConfiguration.php47
-rw-r--r--apps/user_ldap/ajax/getConfiguration.php44
-rw-r--r--apps/user_ldap/ajax/getNewServerConfigPrefix.php51
-rw-r--r--apps/user_ldap/ajax/setConfiguration.php48
-rw-r--r--apps/user_ldap/ajax/testConfiguration.php87
-rw-r--r--apps/user_ldap/ajax/wizard.php117
7 files changed, 205 insertions, 263 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php
index 8f9cf981e57..c3b64f08a16 100644
--- a/apps/user_ldap/ajax/clearMappings.php
+++ b/apps/user_ldap/ajax/clearMappings.php
@@ -1,48 +1,54 @@
<?php
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
-use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Mapping\GroupMapping;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Server;
+use OCP\User\Events\BeforeUserIdUnassignedEvent;
+use OCP\User\Events\UserIdUnassignedEvent;
+use OCP\Util;
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
$subject = (string)$_POST['ldap_clear_mapping'];
$mapping = null;
-if($subject === 'user') {
- $mapping = new UserMapping(\OC::$server->getDatabaseConnection());
-} else if($subject === 'group') {
- $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
-}
try {
- if(is_null($mapping) || !$mapping->clear()) {
- $l = \OC::$server->getL10N('user_ldap');
+ if ($subject === 'user') {
+ $mapping = Server::get(UserMapping::class);
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = Server::get(IEventDispatcher::class);
+ $result = $mapping->clearCb(
+ function (string $uid) use ($dispatcher): void {
+ $dispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
+ /** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
+ Server::get(IUserManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]);
+ },
+ function (string $uid) use ($dispatcher): void {
+ $dispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
+ /** @psalm-suppress UndefinedInterfaceMethod For now we have to emit, will be removed when all hooks are removed */
+ Server::get(IUserManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]);
+ }
+ );
+ } elseif ($subject === 'group') {
+ $mapping = new GroupMapping(Server::get(IDBConnection::class));
+ $result = $mapping->clear();
+ }
+
+ if ($mapping === null || !$result) {
+ $l = Util::getL10N('user_ldap');
throw new \Exception($l->t('Failed to clear the mappings.'));
}
- OCP\JSON::success();
+ \OC_JSON::success();
} catch (\Exception $e) {
- OCP\JSON::error(array('message' => $e->getMessage()));
+ \OC_JSON::error(['message' => $e->getMessage()]);
}
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
index 780a4bc35d0..68bce69f982 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -1,39 +1,24 @@
<?php
+
+use OCA\User_LDAP\Helper;
+use OCP\Server;
+use OCP\Util;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
-$helper = new \OCA\user_ldap\lib\Helper();
-if($helper->deleteServerConfiguration($prefix)) {
- OCP\JSON::success();
+$helper = Server::get(Helper::class);
+if ($helper->deleteServerConfiguration($prefix)) {
+ \OC_JSON::success();
} else {
- $l = \OC::$server->getL10N('user_ldap');
- OCP\JSON::error(array('message' => $l->t('Failed to delete the server configuration')));
+ $l = Util::getL10N('user_ldap');
+ \OC_JSON::error(['message' => $l->t('Failed to delete the server configuration')]);
}
diff --git a/apps/user_ldap/ajax/getConfiguration.php b/apps/user_ldap/ajax/getConfiguration.php
index 795261bc91d..79a7372813c 100644
--- a/apps/user_ldap/ajax/getConfiguration.php
+++ b/apps/user_ldap/ajax/getConfiguration.php
@@ -1,33 +1,23 @@
<?php
+
+use OCA\User_LDAP\LDAP;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
-$ldapWrapper = new OCA\user_ldap\lib\LDAP();
-$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
-OCP\JSON::success(array('configuration' => $connection->getConfiguration()));
+$ldapWrapper = new LDAP();
+$connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
+$configuration = $connection->getConfiguration();
+if (isset($configuration['ldap_agent_password']) && $configuration['ldap_agent_password'] !== '') {
+ // hide password
+ $configuration['ldap_agent_password'] = '**PASSWORD SET**';
+}
+\OC_JSON::success(['configuration' => $configuration]);
diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
index df85d99f2c7..e5ba6375c73 100644
--- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php
+++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
@@ -1,48 +1,37 @@
<?php
+
+use OCA\User_LDAP\Configuration;
+use OCA\User_LDAP\Helper;
+use OCP\Server;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
-$helper = new \OCA\user_ldap\lib\Helper();
+$helper = Server::get(Helper::class);
$serverConnections = $helper->getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);
-$ln = intval(str_replace('s', '', $lk));
-$nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT);
+$ln = (int)str_replace('s', '', $lk);
+$nk = 's' . str_pad((string)($ln + 1), 2, '0', STR_PAD_LEFT);
-$resultData = array('configPrefix' => $nk);
+$resultData = ['configPrefix' => $nk];
-$newConfig = new \OCA\user_ldap\lib\Configuration($nk, false);
-if(isset($_POST['copyConfig'])) {
- $originalConfig = new \OCA\user_ldap\lib\Configuration($_POST['copyConfig']);
+$newConfig = new Configuration($nk, false);
+if (isset($_POST['copyConfig'])) {
+ $originalConfig = new Configuration($_POST['copyConfig']);
$newConfig->setConfiguration($originalConfig->getConfiguration());
} else {
- $configuration = new \OCA\user_ldap\lib\Configuration($nk, false);
+ $configuration = new Configuration($nk, false);
$newConfig->setConfiguration($configuration->getDefaults());
$resultData['defaults'] = $configuration->getDefaults();
}
$newConfig->saveConfiguration();
-OCP\JSON::success($resultData);
+\OC_JSON::success($resultData);
diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php
index a2e73783e00..815ef040257 100644
--- a/apps/user_ldap/ajax/setConfiguration.php
+++ b/apps/user_ldap/ajax/setConfiguration.php
@@ -1,48 +1,32 @@
<?php
+
+use OCA\User_LDAP\LDAP;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Lennart Rosam <hello@takuto.de>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
// Checkboxes are not submitted, when they are unchecked. Set them manually.
// only legacy checkboxes (Advanced and Expert tab) need to be handled here,
// the Wizard-like tabs handle it on their own
-$chkboxes = array('ldap_configuration_active', 'ldap_override_main_server',
- 'ldap_turn_off_cert_check');
-foreach($chkboxes as $boxid) {
- if(!isset($_POST[$boxid])) {
+$chkboxes = ['ldap_configuration_active', 'ldap_override_main_server',
+ 'ldap_turn_off_cert_check'];
+foreach ($chkboxes as $boxid) {
+ if (!isset($_POST[$boxid])) {
$_POST[$boxid] = 0;
}
}
-$ldapWrapper = new OCA\user_ldap\lib\LDAP();
-$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
+$ldapWrapper = new LDAP();
+$connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
$connection->setConfiguration($_POST);
$connection->saveConfiguration();
-OCP\JSON::success();
+\OC_JSON::success();
diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php
index e9f5167bfe7..b77439fa3e8 100644
--- a/apps/user_ldap/ajax/testConfiguration.php
+++ b/apps/user_ldap/ajax/testConfiguration.php
@@ -1,43 +1,48 @@
<?php
+
+use OCA\User_LDAP\Exceptions\ConfigurationIssueException;
+use OCA\User_LDAP\LDAP;
+use OCP\ISession;
+use OCP\Server;
+use OCP\Util;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
-$l = \OC::$server->getL10N('user_ldap');
+$l = Util::getL10N('user_ldap');
+
+$ldapWrapper = new LDAP();
+$connection = new \OCA\User_LDAP\Connection($ldapWrapper, $_POST['ldap_serverconfig_chooser']);
-$ldapWrapper = new OCA\user_ldap\lib\LDAP();
-$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null);
-//needs to be true, otherwise it will also fail with an irritating message
-$_POST['ldap_configuration_active'] = 1;
try {
- if ($connection->setConfiguration($_POST)) {
+ $configurationError = '';
+ $conf = $connection->getConfiguration();
+ if ($conf['ldap_configuration_active'] === '0') {
+ //needs to be true, otherwise it will also fail with an irritating message
+ $conf['ldap_configuration_active'] = '1';
+ }
+ try {
+ $connection->setConfiguration($conf, throw: true);
+ } catch (ConfigurationIssueException $e) {
+ $configurationError = $e->getHint();
+ }
+ if ($configurationError === '') {
//Configuration is okay
+ /*
+ * Closing the session since it won't be used from this point on. There might be a potential
+ * race condition if a second request is made: either this request or the other might not
+ * contact the LDAP backup server the first time when it should, but there shouldn't be any
+ * problem with that other than the extra connection.
+ */
+ Server::get(ISession::class)->close();
if ($connection->bind()) {
/*
* This shiny if block is an ugly hack to find out whether anonymous
@@ -49,23 +54,23 @@ try {
* pass (like e.g. expected syntax error).
*/
try {
- $ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', array('dn'));
+ $ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']);
} catch (\Exception $e) {
- if($e->getCode() === 1) {
- OCP\JSON::error(array('message' => $l->t('The configuration is invalid: anonymous bind is not allowed.')));
+ if ($e->getCode() === 1) {
+ \OC_JSON::error(['message' => $l->t('Invalid configuration: Anonymous binding is not allowed.')]);
exit;
}
}
- OCP\JSON::success(array('message'
- => $l->t('The configuration is valid and the connection could be established!')));
+ \OC_JSON::success(['message'
+ => $l->t('Valid configuration, connection established!')]);
} else {
- OCP\JSON::error(array('message'
- => $l->t('The configuration is valid, but the Bind failed. Please check the server settings and credentials.')));
+ \OC_JSON::error(['message'
+ => $l->t('Valid configuration, but binding failed. Please check the server settings and credentials.')]);
}
} else {
- OCP\JSON::error(array('message'
- => $l->t('The configuration is invalid. Please have a look at the logs for further details.')));
+ \OC_JSON::error(['message'
+ => $l->t('Invalid configuration: %s', $configurationError)]);
}
} catch (\Exception $e) {
- OCP\JSON::error(array('message' => $e->getMessage()));
+ \OC_JSON::error(['message' => $e->getMessage()]);
}
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index f3e5efffc24..056299e1bff 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -1,68 +1,48 @@
<?php
+
+use OCA\User_LDAP\AccessFactory;
+use OCA\User_LDAP\Configuration;
+use OCA\User_LDAP\LDAP;
+use OCA\User_LDAP\Wizard;
+use OCP\Server;
+use OCP\Util;
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
// Check user and app status
-OCP\JSON::checkAdminUser();
-OCP\JSON::checkAppEnabled('user_ldap');
-OCP\JSON::callCheck();
+\OC_JSON::checkAdminUser();
+\OC_JSON::checkAppEnabled('user_ldap');
+\OC_JSON::callCheck();
-$l = \OC::$server->getL10N('user_ldap');
+$l = Util::getL10N('user_ldap');
-if(!isset($_POST['action'])) {
- \OCP\JSON::error(array('message' => $l->t('No action specified')));
+if (!isset($_POST['action'])) {
+ \OC_JSON::error(['message' => $l->t('No action specified')]);
}
$action = (string)$_POST['action'];
-
-if(!isset($_POST['ldap_serverconfig_chooser'])) {
- \OCP\JSON::error(array('message' => $l->t('No configuration specified')));
+if (!isset($_POST['ldap_serverconfig_chooser'])) {
+ \OC_JSON::error(['message' => $l->t('No configuration specified')]);
}
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
-$ldapWrapper = new \OCA\user_ldap\lib\LDAP();
-$configuration = new \OCA\user_ldap\lib\Configuration($prefix);
+$ldapWrapper = new LDAP();
+$configuration = new Configuration($prefix);
-$con = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null);
+$con = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix, null);
$con->setConfiguration($configuration->getConfiguration());
-$con->ldapConfigurationActive = true;
+$con->ldapConfigurationActive = (string)true;
$con->setIgnoreValidation(true);
-$userManager = new \OCA\user_ldap\lib\user\Manager(
- \OC::$server->getConfig(),
- new \OCA\user_ldap\lib\FilesystemHelper(),
- new \OCA\user_ldap\lib\LogWrapper(),
- \OC::$server->getAvatarManager(),
- new \OCP\Image(),
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager());
+$factory = Server::get(AccessFactory::class);
+$access = $factory->get($con);
-$access = new \OCA\user_ldap\lib\Access($con, $ldapWrapper, $userManager);
+$wizard = new Wizard($configuration, $ldapWrapper, $access);
-$wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper, $access);
-
-switch($action) {
+switch ($action) {
case 'guessPortAndTLS':
case 'guessBaseDN':
case 'detectEmailAttribute':
@@ -81,15 +61,15 @@ switch($action) {
case 'countInBaseDN':
try {
$result = $wizard->$action();
- if($result !== false) {
- OCP\JSON::success($result->getResultArray());
+ if ($result !== false) {
+ \OC_JSON::success($result->getResultArray());
exit;
}
} catch (\Exception $e) {
- \OCP\JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode()));
+ \OC_JSON::error(['message' => $e->getMessage(), 'code' => $e->getCode()]);
exit;
}
- \OCP\JSON::error();
+ \OC_JSON::error();
exit;
break;
@@ -97,41 +77,44 @@ switch($action) {
try {
$loginName = $_POST['ldap_test_loginname'];
$result = $wizard->$action($loginName);
- if($result !== false) {
- OCP\JSON::success($result->getResultArray());
+ if ($result !== false) {
+ \OC_JSON::success($result->getResultArray());
exit;
}
} catch (\Exception $e) {
- \OCP\JSON::error(array('message' => $e->getMessage()));
+ \OC_JSON::error(['message' => $e->getMessage()]);
exit;
}
- \OCP\JSON::error();
+ \OC_JSON::error();
exit;
break;
}
case 'save':
- $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
- $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
- if($key === false || is_null($val)) {
- \OCP\JSON::error(array('message' => $l->t('No data specified')));
+ $key = $_POST['cfgkey'] ?? false;
+ $val = $_POST['cfgval'] ?? null;
+ if ($key === false || is_null($val)) {
+ \OC_JSON::error(['message' => $l->t('No data specified')]);
+ exit;
+ }
+ if (is_array($key)) {
+ \OC_JSON::error(['message' => $l->t('Invalid data specified')]);
exit;
}
- $cfg = array($key => $val);
- $setParameters = array();
+ $cfg = [$key => $val];
+ $setParameters = [];
$configuration->setConfiguration($cfg, $setParameters);
- if(!in_array($key, $setParameters)) {
- \OCP\JSON::error(array('message' => $l->t($key.
- ' Could not set configuration %s', $setParameters[0])));
+ if (!in_array($key, $setParameters)) {
+ \OC_JSON::error(['message' => $l->t('Could not set configuration %1$s to %2$s', [$key, $setParameters[0]])]);
exit;
}
$configuration->saveConfiguration();
//clear the cache on save
- $connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
+ $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
$connection->clearCache();
- OCP\JSON::success();
+ \OC_JSON::success();
break;
default:
- \OCP\JSON::error(array('message' => $l->t('Action does not exist')));
+ \OC_JSON::error(['message' => $l->t('Action does not exist')]);
break;
}