From a6c6e8d67a040357bab82ff6defa833ddd6e80df Mon Sep 17 00:00:00 2001 From: blaerf Date: Wed, 19 Nov 2025 07:53:44 +0100 Subject: [PATCH] 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; + } +}