diff --git a/lib/Controller/LoginController.php b/lib/Controller/LoginController.php index 0ae3b997..b66a5137 100644 --- a/lib/Controller/LoginController.php +++ b/lib/Controller/LoginController.php @@ -464,6 +464,7 @@ private function provisionUser(string $userId, int $providerId, object $idTokenP // so new users will be directly available even if they were not synced before this login attempt $this->userManager->search($userId); // when auto provision is disabled, we assume the user has been created by another user backend (or manually) + $userId = $this->ldapService->mapLoginName2UserName($userId); $user = $this->userManager->get($userId); if (is_null($user) || $this->ldapService->isLdapDeletedUser($user)) { $this->logger->warning("Won't provision user: " . $userId); diff --git a/lib/Service/LdapService.php b/lib/Service/LdapService.php index 4642cd50..cd928a7a 100644 --- a/lib/Service/LdapService.php +++ b/lib/Service/LdapService.php @@ -72,4 +72,22 @@ public function isLdapDeletedUser(IUser $user): bool { // did we find the user in the LDAP deleted user list? return $searchDisabledUser !== false; } + + /** + * @param string $userId + * @return string + */ + public function mapLoginName2UserName(string $userId): string { + try { + $proxy = \OC::$server->get(\OCA\User_LDAP\User_Proxy::class); + $mappedUserId = $proxy->loginName2UserName($userId); + if ($mappedUserId !== false && $mappedUserId !== $userId) { + $userId = $mappedUserId; + } + } catch (QueryException $e) { + $this->logger->debug($e->getMessage()); + } finally { + return $userId; + } + } }