From a7bb3cac6e44964adf7c93d74bab8f68ecd0c869 Mon Sep 17 00:00:00 2001 From: blaerf Date: Wed, 19 Nov 2025 07:53:10 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Datei=20gel=C3=B6scht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Ldap/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/Services/Ldap/.gitkeep diff --git a/app/Services/Ldap/.gitkeep b/app/Services/Ldap/.gitkeep deleted file mode 100644 index e69de29..0000000 -- 2.45.2 From a6c6e8d67a040357bab82ff6defa833ddd6e80df Mon Sep 17 00:00:00 2001 From: blaerf Date: Wed, 19 Nov 2025 07:53:44 +0100 Subject: [PATCH 2/3] Connection Helper-Klasse erstellt --- app/Services/Ldap/LdapConnectionHelper.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/Services/Ldap/LdapConnectionHelper.php diff --git a/app/Services/Ldap/LdapConnectionHelper.php b/app/Services/Ldap/LdapConnectionHelper.php new file mode 100644 index 0000000..e7e9444 --- /dev/null +++ b/app/Services/Ldap/LdapConnectionHelper.php @@ -0,0 +1,49 @@ + */ + private array $config; + + /** + * @param array $ldapConfig + */ + public function __construct(array $ldapConfig) + { + $this->config = $ldapConfig; + } + + /** + * Erstellt eine LDAP-Verbindung mit gesetzten Optionen (Protokollversion, Timeout), + * aber ohne Bind. Den Bind führen die aufrufenden Services durch. + * + * @return resource LDAP-Verbindungs-Handle + */ + public function createConnection() + { + $server = (string)($this->config['server'] ?? ''); + $port = (int)($this->config['port'] ?? 636); + $timeout = (int)($this->config['timeout'] ?? 5); + + if ($server === '') { + throw new RuntimeException('LDAP-Konfiguration ist unvollständig (server fehlt).'); + } + + $connection = ldap_connect($server, $port); + + if ($connection === false) { + throw new RuntimeException('LDAP-Verbindung konnte nicht aufgebaut werden.'); + } + + ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); + ldap_set_option($connection, LDAP_OPT_NETWORK_TIMEOUT, $timeout); + + return $connection; + } +} -- 2.45.2 From d268a8bf6ac5194bd51fe6663610b3b87cb9ae29 Mon Sep 17 00:00:00 2001 From: blaerf Date: Wed, 19 Nov 2025 07:54:12 +0100 Subject: [PATCH 3/3] Verbindung auf LdapConnectionHelper umgestellt. --- app/Services/Ldap/LdapAuthService.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/app/Services/Ldap/LdapAuthService.php b/app/Services/Ldap/LdapAuthService.php index bfae62c..39e0bec 100644 --- a/app/Services/Ldap/LdapAuthService.php +++ b/app/Services/Ldap/LdapAuthService.php @@ -19,6 +19,8 @@ class LdapAuthService /** @var array 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" -- 2.45.2