diff options
Diffstat (limited to 'apps/user_ldap/ajax')
-rw-r--r-- | apps/user_ldap/ajax/clearMappings.php | 53 | ||||
-rw-r--r-- | apps/user_ldap/ajax/deleteConfiguration.php | 36 | ||||
-rw-r--r-- | apps/user_ldap/ajax/getConfiguration.php | 31 | ||||
-rw-r--r-- | apps/user_ldap/ajax/getNewServerConfigPrefix.php | 40 | ||||
-rw-r--r-- | apps/user_ldap/ajax/setConfiguration.php | 30 | ||||
-rw-r--r-- | apps/user_ldap/ajax/testConfiguration.php | 52 | ||||
-rw-r--r-- | apps/user_ldap/ajax/wizard.php | 51 |
7 files changed, 100 insertions, 193 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index ecc45a60de7..c3b64f08a16 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -1,30 +1,19 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christopher Schäpers <kondou@ts.unde.re> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Lukas Reschke <lukas@statuscode.ch> - * @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/> - * + * 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\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 \OC_JSON::checkAdminUser(); @@ -35,22 +24,28 @@ $subject = (string)$_POST['ldap_clear_mapping']; $mapping = null; try { if ($subject === 'user') { - $mapping = \OCP\Server::get(UserMapping::class); + $mapping = Server::get(UserMapping::class); + /** @var IEventDispatcher $dispatcher */ + $dispatcher = Server::get(IEventDispatcher::class); $result = $mapping->clearCb( - function ($uid) { - \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]); + 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 ($uid) { - \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$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(\OC::$server->getDatabaseConnection()); + $mapping = new GroupMapping(Server::get(IDBConnection::class)); $result = $mapping->clear(); } if ($mapping === null || !$result) { - $l = \OCP\Util::getL10N('user_ldap'); + $l = Util::getL10N('user_ldap'); throw new \Exception($l->t('Failed to clear the mappings.')); } \OC_JSON::success(); diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php index 2f1ca3d724f..68bce69f982 100644 --- a/apps/user_ldap/ajax/deleteConfiguration.php +++ b/apps/user_ldap/ajax/deleteConfiguration.php @@ -1,29 +1,13 @@ <?php + +use OCA\User_LDAP\Helper; +use OCP\Server; +use OCP\Util; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Robin Appelman <robin@icewind.nl> - * @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/> - * + * 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 \OC_JSON::checkAdminUser(); @@ -31,10 +15,10 @@ \OC_JSON::callCheck(); $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); +$helper = Server::get(Helper::class); if ($helper->deleteServerConfiguration($prefix)) { \OC_JSON::success(); } else { - $l = \OCP\Util::getL10N('user_ldap'); + $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 b541dbfbea5..79a7372813c 100644 --- a/apps/user_ldap/ajax/getConfiguration.php +++ b/apps/user_ldap/ajax/getConfiguration.php @@ -1,28 +1,11 @@ <?php + +use OCA\User_LDAP\LDAP; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Lukas Reschke <lukas@statuscode.ch> - * @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/> - * + * 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 \OC_JSON::checkAdminUser(); @@ -30,7 +13,7 @@ \OC_JSON::callCheck(); $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); $configuration = $connection->getConfiguration(); if (isset($configuration['ldap_agent_password']) && $configuration['ldap_agent_password'] !== '') { diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php index d2194d5ceb7..e5ba6375c73 100644 --- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php +++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php @@ -1,48 +1,34 @@ <?php + +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCP\Server; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @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/> - * + * 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 \OC_JSON::checkAdminUser(); \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); +$helper = Server::get(Helper::class); $serverConnections = $helper->getServerConfigurationPrefixes(); sort($serverConnections); $lk = array_pop($serverConnections); $ln = (int)str_replace('s', '', $lk); -$nk = 's'.str_pad($ln + 1, 2, '0', STR_PAD_LEFT); +$nk = 's' . str_pad((string)($ln + 1), 2, '0', STR_PAD_LEFT); $resultData = ['configPrefix' => $nk]; -$newConfig = new \OCA\User_LDAP\Configuration($nk, false); +$newConfig = new Configuration($nk, false); if (isset($_POST['copyConfig'])) { - $originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']); + $originalConfig = new Configuration($_POST['copyConfig']); $newConfig->setConfiguration($originalConfig->getConfiguration()); } else { - $configuration = new \OCA\User_LDAP\Configuration($nk, false); + $configuration = new Configuration($nk, false); $newConfig->setConfiguration($configuration->getDefaults()); $resultData['defaults'] = $configuration->getDefaults(); } diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php index 93717b7d114..815ef040257 100644 --- a/apps/user_ldap/ajax/setConfiguration.php +++ b/apps/user_ldap/ajax/setConfiguration.php @@ -1,27 +1,11 @@ <?php + +use OCA\User_LDAP\LDAP; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @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/> - * + * 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 \OC_JSON::checkAdminUser(); @@ -41,7 +25,7 @@ foreach ($chkboxes as $boxid) { } } -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); $connection->setConfiguration($_POST); $connection->saveConfiguration(); diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php index 187eeb4295b..b77439fa3e8 100644 --- a/apps/user_ldap/ajax/testConfiguration.php +++ b/apps/user_ldap/ajax/testConfiguration.php @@ -1,50 +1,40 @@ <?php + +use OCA\User_LDAP\Exceptions\ConfigurationIssueException; +use OCA\User_LDAP\LDAP; +use OCP\ISession; +use OCP\Server; +use OCP\Util; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @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 \OC_JSON::checkAdminUser(); \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OCP\Util::getL10N('user_ldap'); +$l = Util::getL10N('user_ldap'); -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $_POST['ldap_serverconfig_chooser']); try { - $configurationOk = true; + $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'; - $configurationOk = $connection->setConfiguration($conf); } - if ($configurationOk) { + 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 @@ -52,7 +42,7 @@ try { * 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. */ - \OC::$server->getSession()->close(); + Server::get(ISession::class)->close(); if ($connection->bind()) { /* * This shiny if block is an ugly hack to find out whether anonymous @@ -79,7 +69,7 @@ try { } } else { \OC_JSON::error(['message' - => $l->t('Invalid configuration. Please have a look at the logs for further details.')]); + => $l->t('Invalid configuration: %s', $configurationError)]); } } catch (\Exception $e) { \OC_JSON::error(['message' => $e->getMessage()]); diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index 63241667825..056299e1bff 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -1,37 +1,23 @@ <?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; + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Roger Szabo <roger.szabo@web.de> - * - * @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 \OC_JSON::checkAdminUser(); \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OCP\Util::getL10N('user_ldap'); +$l = Util::getL10N('user_ldap'); if (!isset($_POST['action'])) { \OC_JSON::error(['message' => $l->t('No action specified')]); @@ -43,18 +29,18 @@ if (!isset($_POST['ldap_serverconfig_chooser'])) { } $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$ldapWrapper = new \OCA\User_LDAP\LDAP(); -$configuration = new \OCA\User_LDAP\Configuration($prefix); +$ldapWrapper = new LDAP(); +$configuration = new Configuration($prefix); $con = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix, null); $con->setConfiguration($configuration->getConfiguration()); -$con->ldapConfigurationActive = true; +$con->ldapConfigurationActive = (string)true; $con->setIgnoreValidation(true); -$factory = \OC::$server->get(\OCA\User_LDAP\AccessFactory::class); +$factory = Server::get(AccessFactory::class); $access = $factory->get($con); -$wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access); +$wizard = new Wizard($configuration, $ldapWrapper, $access); switch ($action) { case 'guessPortAndTLS': @@ -119,8 +105,7 @@ switch ($action) { $setParameters = []; $configuration->setConfiguration($cfg, $setParameters); if (!in_array($key, $setParameters)) { - \OC_JSON::error(['message' => $l->t($key. - ' Could not set configuration %s', $setParameters[0])]); + \OC_JSON::error(['message' => $l->t('Could not set configuration %1$s to %2$s', [$key, $setParameters[0]])]); exit; } $configuration->saveConfiguration(); |