-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat(ldap): Allow to search one user by one of its LDAP attribute #59928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,21 +16,23 @@ | |||||
| use OCA\User_LDAP\User\User; | ||||||
| use OCP\Accounts\IAccountManager; | ||||||
| use OCP\IUserBackend; | ||||||
| use OCP\LDAP\Exceptions\MultipleUsersReturnedException; | ||||||
| use OCP\Notification\IManager as INotificationManager; | ||||||
| use OCP\User\Backend\ICountMappedUsersBackend; | ||||||
| use OCP\User\Backend\ILimitAwareCountUsersBackend; | ||||||
| use OCP\User\Backend\IPropertyPermissionBackend; | ||||||
| use OCP\User\Backend\IProvideEnabledStateBackend; | ||||||
| use OCP\UserInterface; | ||||||
| use Override; | ||||||
| use Psr\Log\LoggerInterface; | ||||||
|
|
||||||
| class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend, IPropertyPermissionBackend { | ||||||
| public function __construct( | ||||||
| Access $access, | ||||||
| protected INotificationManager $notificationManager, | ||||||
| protected UserPluginManager $userPluginManager, | ||||||
| protected LoggerInterface $logger, | ||||||
| protected DeletedUsersIndex $deletedUsersIndex, | ||||||
| protected readonly INotificationManager $notificationManager, | ||||||
| protected readonly UserPluginManager $userPluginManager, | ||||||
| protected readonly LoggerInterface $logger, | ||||||
| protected readonly DeletedUsersIndex $deletedUsersIndex, | ||||||
| ) { | ||||||
| parent::__construct($access); | ||||||
| } | ||||||
|
|
@@ -701,4 +703,25 @@ | |||||
| default => true, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| #[Override] | ||||||
| public function getUserFromCustomAttribute(string $attribute, string $searchTerm): ?string { | ||||||
| $searchTerm = $this->access->escapeFilterPart($searchTerm); | ||||||
| $attribute = $this->access->escapeFilterPart($attribute); | ||||||
|
|
||||||
| $filter = "($attribute=$searchTerm)"; | ||||||
|
|
||||||
| $records = $this->access->searchUsers($filter, ['dn']); | ||||||
| $this->logger->error($filter); | ||||||
| if (count($records) === 1) { | ||||||
| return $this->access->dn2username($records[0]['dn'][0]); | ||||||
|
Check failure on line 717 in apps/user_ldap/lib/User_LDAP.php
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to psalm you need to convert false into null here
Suggested change
But if you do it like this it will most likely complain about falsy string 🙈 |
||||||
| } elseif (count($records) > 1) { | ||||||
| $this->logger->error( | ||||||
| 'Multiple users found for filter: ' . $filter, | ||||||
| ['app' => 'user_ldap'] | ||||||
| ); | ||||||
| throw new MultipleUsersReturnedException(); | ||||||
| } | ||||||
| return null; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
|
CarlSchwan marked this conversation as resolved.
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCP\LDAP\Exceptions; | ||
|
|
||
| use OCP\AppFramework\Attribute\Consumable; | ||
|
|
||
| /** | ||
| * Exception for a ldap search that unexpectedly returns multiple users. | ||
| * | ||
| * @since 34.0.0 | ||
| */ | ||
| #[Consumable(since: '34.0.0')] | ||
| class MultipleUsersReturnedException extends \Exception { | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.