Skip to content

Commit

Permalink
Map loginname to username
Browse files Browse the repository at this point in the history
  • Loading branch information
noumar committed Nov 10, 2022
1 parent a74add7 commit ac00cee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions lib/Service/LdapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit ac00cee

Please sign in to comment.