Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2dea21a
chore: Get rid of unused user_ldap AJAX endpoints
come-nc Oct 2, 2025
e842874
fix(user_ldap): Add OCS endpoint for testing configurations
come-nc Oct 2, 2025
36475f2
fix(user_ldap): Add OCS endpoint for copying configurations
come-nc Oct 2, 2025
a0e5548
feat(user_ldap): Add a wizard OCS API
come-nc Oct 2, 2025
777c729
feat(user_ldap): Adapt frontend to call new endpoints
artonge Oct 2, 2025
9d41d81
fix(ldap): Fix wizard controller action route
come-nc Oct 6, 2025
ac078b6
chore: Fix typing in WizardResult
come-nc Oct 7, 2025
c414a7b
fix: Fix documentation for controllers and update openapi.json
come-nc Oct 7, 2025
28cef3e
fix(ldap): Add OCS route for clearing mapping without using ajax
come-nc Oct 7, 2025
c621662
chore(user_ldap): Remove ajax endpoints
come-nc Oct 7, 2025
aed0e82
fix(user_ldap): Remove last ajax call from frontend
come-nc Oct 7, 2025
92efa01
chore: Update psalm baseline
come-nc Oct 7, 2025
f9abfe0
fix(tests): Use testing application for testing ajax endpoints, not u…
come-nc Oct 7, 2025
00349e6
chore: npm run lint:fix
come-nc Oct 7, 2025
1afa2a5
chore: remove unused imports
come-nc Oct 7, 2025
687fa0a
fix(user_ldap): Call config API instead of wizard save action
come-nc Oct 7, 2025
3906998
feat(user_ldap): Save base on detect
artonge Nov 21, 2025
f57fb6e
feat(user_ldap): Disable countInBaseDN button when base is empty
artonge Nov 21, 2025
ac690ea
fix(user_ldap): Properly handle new wizard OCS endpoint error
artonge Nov 21, 2025
e9b1e7a
chore: Compile assets
artonge Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(user_ldap): Add OCS endpoint for testing configurations
Signed-off-by: Côme Chilliet <[email protected]>
Signed-off-by: Louis Chmn <[email protected]>
  • Loading branch information
come-nc authored and artonge committed Nov 21, 2025
commit e842874a0ac513f206ad83440474c848168029a9
73 changes: 73 additions & 0 deletions apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Exceptions\ConfigurationIssueException;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Settings\Admin;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
Expand All @@ -18,7 +21,9 @@
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Server;
use Psr\Log\LoggerInterface;

class ConfigAPIController extends OCSController {
Expand All @@ -28,6 +33,7 @@ public function __construct(
private Helper $ldapHelper,
private LoggerInterface $logger,
private ConnectionFactory $connectionFactory,
private IL10N $l,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -227,6 +233,73 @@ public function show($configID, $showPassword = false) {
return new DataResponse($data);
}

/**
* Test a configuration
*
* @return DataResponse<Http::STATUS_OK, array{success:bool,message:string}, array{}>
* @throws OCSException An unexpected error happened
* @throws OCSNotFoundException Config not found
*
* 200: Test was run and results are returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/test')]
public function testConfiguration(string $configID) {
try {
$this->ensureConfigIDExists($configID);
$connection = $this->connectionFactory->get($configID);
$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) {
return new DataResponse([
'success' => false,
'message' => $this->l->t('Invalid configuration: %s', $e->getHint()),
]);
}
// Configuration is okay
if (!$connection->bind()) {
return new DataResponse([
'success' => false,
'message' => $this->l->t('Valid configuration, but binding failed. Please check the server settings and credentials.'),
]);
}
/*
* 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 = Server::get(ILDAPWrapper::class);
$ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']);
} catch (\Exception $e) {
if ($e->getCode() === 1) {
return new DataResponse([
'success' => false,
'message' => $this->l->t('Invalid configuration: Anonymous binding is not allowed.'),
]);
}
}
return new DataResponse([
'success' => true,
'message' => $this->l->t('Valid configuration, connection established!'),
]);
} catch (OCSException $e) {
throw $e;
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException('An issue occurred when testing the config.');
}
}

/**
* If the given config ID is not available, an exception is thrown
*
Expand Down