chore(user_ldap): Remove ajax endpoints

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
Côme Chilliet 2025-10-07 11:44:06 +02:00 committed by Louis Chmn
parent 28cef3ed6b
commit c62166241a
6 changed files with 1 additions and 291 deletions

View file

@ -1,53 +0,0 @@
<?php
/**
* 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\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();
\OC_JSON::checkAppEnabled('user_ldap');
\OC_JSON::callCheck();
$subject = (string)$_POST['ldap_clear_mapping'];
$mapping = null;
try {
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 = Server::get(GroupMapping::class);
$result = $mapping->clear();
}
if ($mapping === null || !$result) {
$l = Util::getL10N('user_ldap');
throw new \Exception($l->t('Failed to clear the mappings.'));
}
\OC_JSON::success();
} catch (\Exception $e) {
\OC_JSON::error(['message' => $e->getMessage()]);
}

View file

@ -1,33 +0,0 @@
<?php
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
use OCP\Server;
/**
* 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 = Server::get(Helper::class);
$nk = $helper->getNextServerConfigurationPrefix();
$resultData = ['configPrefix' => $nk];
$newConfig = new Configuration($nk, false);
if (isset($_POST['copyConfig'])) {
$originalConfig = new Configuration($_POST['copyConfig']);
$newConfig->setConfiguration($originalConfig->getConfiguration());
} else {
$configuration = new Configuration($nk, false);
$newConfig->setConfiguration($configuration->getDefaults());
$resultData['defaults'] = $configuration->getDefaults();
}
$newConfig->saveConfiguration();
\OC_JSON::success($resultData);

View file

@ -1,76 +0,0 @@
<?php
use OCA\User_LDAP\Exceptions\ConfigurationIssueException;
use OCA\User_LDAP\LDAP;
use OCP\ISession;
use OCP\Server;
use OCP\Util;
/**
* 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 = Util::getL10N('user_ldap');
$ldapWrapper = new LDAP();
$connection = new \OCA\User_LDAP\Connection($ldapWrapper, $_POST['ldap_serverconfig_chooser']);
try {
$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
* bind is possible on AD or not. Because AD happily and constantly
* replies with success to any anonymous bind request, we need to
* fire up a broken operation. If AD does not allow anonymous bind,
* it will end up with LDAP error code 1 which is turned into an
* exception by the LDAP wrapper. We catch this. Other cases may
* pass (like e.g. expected syntax error).
*/
try {
$ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']);
} catch (\Exception $e) {
if ($e->getCode() === 1) {
\OC_JSON::error(['message' => $l->t('Invalid configuration: Anonymous binding is not allowed.')]);
exit;
}
}
\OC_JSON::success(['message'
=> $l->t('Valid configuration, connection established!')]);
} else {
\OC_JSON::error(['message'
=> $l->t('Valid configuration, but binding failed. Please check the server settings and credentials.')]);
}
} else {
\OC_JSON::error(['message'
=> $l->t('Invalid configuration: %s', $configurationError)]);
}
} catch (\Exception $e) {
\OC_JSON::error(['message' => $e->getMessage()]);
}

View file

@ -1,120 +0,0 @@
<?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;
/**
* 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 = Util::getL10N('user_ldap');
if (!isset($_POST['action'])) {
\OC_JSON::error(['message' => $l->t('No action specified')]);
}
$action = (string)$_POST['action'];
if (!isset($_POST['ldap_serverconfig_chooser'])) {
\OC_JSON::error(['message' => $l->t('No configuration specified')]);
}
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
$ldapWrapper = new LDAP();
$configuration = new Configuration($prefix);
$con = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix, null);
$con->setConfiguration($configuration->getConfiguration());
$con->ldapConfigurationActive = (string)true;
$con->setIgnoreValidation(true);
$factory = Server::get(AccessFactory::class);
$access = $factory->get($con);
$wizard = new Wizard($configuration, $ldapWrapper, $access);
switch ($action) {
case 'guessPortAndTLS':
case 'guessBaseDN':
case 'detectEmailAttribute':
case 'detectUserDisplayNameAttribute':
case 'determineGroupMemberAssoc':
case 'determineUserObjectClasses':
case 'determineGroupObjectClasses':
case 'determineGroupsForUsers':
case 'determineGroupsForGroups':
case 'determineAttributes':
case 'getUserListFilter':
case 'getUserLoginFilter':
case 'getGroupFilter':
case 'countUsers':
case 'countGroups':
case 'countInBaseDN':
try {
$result = $wizard->$action();
if ($result !== false) {
\OC_JSON::success($result->getResultArray());
exit;
}
} catch (\Exception $e) {
\OC_JSON::error(['message' => $e->getMessage(), 'code' => $e->getCode()]);
exit;
}
\OC_JSON::error();
exit;
break;
case 'testLoginName': {
try {
$loginName = $_POST['ldap_test_loginname'];
$result = $wizard->$action($loginName);
if ($result !== false) {
\OC_JSON::success($result->getResultArray());
exit;
}
} catch (\Exception $e) {
\OC_JSON::error(['message' => $e->getMessage()]);
exit;
}
\OC_JSON::error();
exit;
break;
}
case 'save':
$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 = [$key => $val];
$setParameters = [];
$configuration->setConfiguration($cfg, $setParameters);
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\Connection($ldapWrapper, $prefix);
$connection->clearCache();
\OC_JSON::success();
break;
default:
\OC_JSON::error(['message' => $l->t('Action does not exist')]);
break;
}

View file

@ -7,14 +7,6 @@ declare(strict_types=1);
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
$this->create('user_ldap_ajax_clearMappings', 'apps/user_ldap/ajax/clearMappings.php')
->actionInclude('user_ldap/ajax/clearMappings.php');
$this->create('user_ldap_ajax_getNewServerConfigPrefix', 'apps/user_ldap/ajax/getNewServerConfigPrefix.php')
->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php');
$this->create('user_ldap_ajax_testConfiguration', 'apps/user_ldap/ajax/testConfiguration.php')
->actionInclude('user_ldap/ajax/testConfiguration.php');
$this->create('user_ldap_ajax_wizard', 'apps/user_ldap/ajax/wizard.php')
->actionInclude('user_ldap/ajax/wizard.php');
return [
'routes' => [

View file

@ -199,7 +199,7 @@ class Wizard extends LDAPUtility {
$count = (int)$this->countUsersWithAttribute($attr, true);
if ($count > 0) {
//no change, but we sent it back to make sure the user interface
//is still correct, even if the ajax call was cancelled meanwhile
//is still correct, even if the call was cancelled meanwhile
$this->result->addChange('ldap_display_name', $attr);
return $this->result;
}