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.php27
-rw-r--r--apps/user_ldap/ajax/deleteConfiguration.php8
-rw-r--r--apps/user_ldap/ajax/getConfiguration.php4
-rw-r--r--apps/user_ldap/ajax/getNewServerConfigPrefix.php14
-rw-r--r--apps/user_ldap/ajax/setConfiguration.php4
-rw-r--r--apps/user_ldap/ajax/testConfiguration.php24
-rw-r--r--apps/user_ldap/ajax/wizard.php20
7 files changed, 71 insertions, 30 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php
index 0616281b415..c3b64f08a16 100644
--- a/apps/user_ldap/ajax/clearMappings.php
+++ b/apps/user_ldap/ajax/clearMappings.php
@@ -7,6 +7,13 @@
*/
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();
@@ -17,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 b8e9a09dc1c..68bce69f982 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -1,5 +1,9 @@
<?php
+use OCA\User_LDAP\Helper;
+use OCP\Server;
+use OCP\Util;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,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 31372e89c20..79a7372813c 100644
--- a/apps/user_ldap/ajax/getConfiguration.php
+++ b/apps/user_ldap/ajax/getConfiguration.php
@@ -1,5 +1,7 @@
<?php
+use OCA\User_LDAP\LDAP;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,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 8064ce92833..e5ba6375c73 100644
--- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php
+++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
@@ -1,5 +1,9 @@
<?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.
@@ -10,21 +14,21 @@
\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 afa3b551899..815ef040257 100644
--- a/apps/user_ldap/ajax/setConfiguration.php
+++ b/apps/user_ldap/ajax/setConfiguration.php
@@ -1,5 +1,7 @@
<?php
+use OCA\User_LDAP\LDAP;
+
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -23,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 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()]);
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index 5c2cddc7672..056299e1bff 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -1,5 +1,12 @@
<?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.
@@ -10,7 +17,7 @@
\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')]);
@@ -22,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 = (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':
@@ -98,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();