Skip to content

Commit

Permalink
Merge branch 'master' of github.com:/Intermesh/groupoffice
Browse files Browse the repository at this point in the history
  • Loading branch information
derjoachim committed Dec 9, 2024
2 parents a679901 + 8e8848d commit 08f319d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions www/go/modules/community/ldapauthenticator/model/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace go\modules\community\ldapauthenticator\model;

use Exception;
use GO\Base\Mail\ImapAuthenticationFailedException;
use GO\Base\Mail\Exception\ImapAuthenticationFailedException;
use go\core\auth\PrimaryAuthenticator;
use go\core\ErrorHandler;
use go\core\ldap\Record;
Expand Down Expand Up @@ -119,8 +119,6 @@ public function authenticate(string $username, string $password): bool|User

if($server->hasEmailAccount()) {



try {
$this->setEmailAccount($domain, $ldapUsername, $password, $mappedValues['email'], $server, $user);
} catch(ImapAuthenticationFailedException $e) {
Expand Down Expand Up @@ -161,6 +159,31 @@ private function addPostfixMailbox($domain, $username, $password, $email, Server
return false;
}

private function updatePostfixMailbox($domain, $username, $password, $email, Server $server, User $user) {
if(!go()->getModule("community", "serverclient")) {
return false;
}

$domains = \go\modules\community\serverclient\Module::getDomains();

if(!in_array($domain, $domains)) {
return false;
}

go()->debug("LDAPAUTH: Adding postfix mailbox for $username to $domain");

$postfixAdmin = new MailDomain($password);

try {
$postfixAdmin->setMailboxPassword($user, $domain);

return true;
} catch(Exception $e) {
ErrorHandler::logException($e);
}
return false;
}

/**
* @throws Exception
*/
Expand All @@ -180,6 +203,8 @@ private function setEmailAccount($domain, $username, $password, $email, Server $

if(!$accounts) {
$this->addPostfixMailbox($domain, $username, $password, $email, $server, $user);
} else {
$this->updatePostfixMailbox($domain, $username, $password, $email, $server, $user);
}

$foundForUser = false;
Expand Down

0 comments on commit 08f319d

Please sign in to comment.