By default, the current version of the Nextcloud and Zimbra connector uses Zimbra’s uid as the username for the user. This means that if you have nextcloud user named user@domain.com, Zimbra will NOT use this. Instead, Zimbra will use the uid (a long string like ae0351f4-0269-49b2-bc36-c3cefe81897d as the username for Nextcloud. If the user does not exist, Nextcloud will create the user. Obviously this sucks. Here is a simple fix:
The file abstractzimbrausersbackend.php has a function called checkPassword():
public function checkPassword($uid, $password)
{
if(!$this->allow_zimbra_users_login)
{
return false;
}
$httpRequestResponse = $this->doZimbraAuthenticationRequest($uid, $password);
if ($httpRequestResponse->getHttpCode() === 200) {
$response = json_decode($httpRequestResponse->getRawResponse());
$userId = $response->{'accountId'};
$userDisplayName = $response->{'displayName'};
$userEmail = $response->{'email'};
if(!$this->userManager->userExists($userId))
{
$this->createUser($userId, $userDisplayName);
}
$this->setDefaultUserAttributes($userId, $userEmail, $userDisplayName);
return $userId;
} else {
return false;
}
}
The highlighted line, $userId = $response->{‘accountId’}; determines the username of the Zimbra user. Zimbra sends the uid, e-mail address and display name of the user, so we can modify this. All we need to do is change it into:
$userId = $response->{'email'};
And we’re done.
