Verbindung auf LdapConnectionHelper umgestellt.

This commit is contained in:
blaerf 2025-11-19 07:54:12 +01:00
parent a6c6e8d67a
commit d268a8bf6a

View File

@ -19,6 +19,8 @@ class LdapAuthService
/** @var array<string, mixed> LDAP-spezifische Konfiguration (Server, Port, Domain-Suffix, Timeout, etc.) */
private array $config;
private LdapConnectionHelper $connectionHelper;
/**
* Erwartet den Teilbereich "ldap" aus der allgemeinen Konfiguration (config.php).
*
@ -28,6 +30,7 @@ class LdapAuthService
{
// LDAP-Konfiguration in der Instanz speichern.
$this->config = $ldapConfig;
$this->connectionHelper = new LdapConnectionHelper($ldapConfig);
}
/**
@ -50,30 +53,17 @@ class LdapAuthService
// Benötigte Werte aus der LDAP-Konfiguration auslesen.
// Falls einzelne Werte fehlen, werden sinnvolle Standardwerte gesetzt.
$server = (string)($this->config['server'] ?? '');
$port = (int)($this->config['port'] ?? 389);
$domainSuffix = (string)($this->config['domain_suffix'] ?? '');
$timeout = (int)($this->config['timeout'] ?? 5);
// Ohne Server-Adresse oder Domain-Suffix ist eine sinnvolle Anmeldung nicht möglich.
// Das ist ein Konfigurationsfehler und wird als technischer Fehler behandelt.
if ($server === '' || $domainSuffix === '') {
throw new RuntimeException('LDAP-Konfiguration ist unvollständig.');
if ($domainSuffix === '') {
throw new RuntimeException('LDAP-Konfiguration ist unvollständig (domain_suffix fehlt).');
}
// Verbindung zum LDAP/AD-Server herstellen.
// Rückgabewert ist eine Ressource (Verbindungshandle) oder false bei Fehlern.
$connection = ldap_connect($server, $port);
if ($connection === false) {
throw new RuntimeException('LDAP-Verbindung konnte nicht aufgebaut werden.');
}
// LDAP-Optionen setzen:
// - Protokollversion 3 (Standard in aktuellen Umgebungen)
// - Netzwerk-Timeout, damit die Anfrage nicht unendlich hängt
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_NETWORK_TIMEOUT, $timeout);
$connection = $this->connectionHelper->createConnection();
// UPN (User Principal Name) aus Benutzername und Domain-Suffix bilden.
// Beispiel: "administrator" + "@ITFA-PROJ-DOM.local" -> "administrator@ITFA-PROJ-DOM.local"