aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/ajax/testConfiguration.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/ajax/testConfiguration.php')
-rw-r--r--apps/user_ldap/ajax/testConfiguration.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php
index 93e4813d8b0..b77439fa3e8 100644
--- a/apps/user_ldap/ajax/testConfiguration.php
+++ b/apps/user_ldap/ajax/testConfiguration.php
@@ -1,5 +1,11 @@
<?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.
@@ -10,21 +16,25 @@
\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
@@ -32,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
@@ -59,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()]);