Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions www/go/modules/community/ldapauthenticator/cli/controller/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,29 @@ private function getGOUserName(Record $record, Server $server): bool|string
}
}

$mailDomain = isset($record->mail[0]) ? explode('@', $record->mail[0])[1] : null;
// Determine email using LDAP mapping if available
$config = go()->getConfig();
$mapping = $config['ldapMapping'] ?? null;

$mail = null;

if (isset($mapping['email'])) {
if (is_callable($mapping['email'])) {
$mail = $mapping['email']($record);
} else {
$attr = strtolower($mapping['email']);
$mail = $record->{$attr}[0] ?? null;
}
}

// Fallback to default LDAP mail attribute
if (!$mail) {
$mail = $record->mail[0] ?? null;
}

$mailDomain = $mail && str_contains($mail, '@')
? explode('@', $mail, 2)[1]
: null;

if (empty($domain) || !in_array($domain, $this->domains)) {
go()->info("Using domain from mail property for " . $username);
Expand Down Expand Up @@ -527,4 +549,4 @@ private function logDeletes(array $deleteIds, int $totalInLDAP, int $maxDeletePe
throw new Exception("Delete Aborted because script was about to delete more then $maxDeletePercentage% (" . $percentageToDelete . "%, " . ($totalInGO - $totalInLDAP) . " groups)\n");
}
}
}
}