Compare commits
No commits in common. "d268a8bf6ac5194bd51fe6663610b3b87cb9ae29" and "79332edd87e2bdef0b27ef0af93bd692af473697" have entirely different histories.
d268a8bf6a
...
79332edd87
0
app/Services/Ldap/.gitkeep
Normal file
0
app/Services/Ldap/.gitkeep
Normal file
@ -19,8 +19,6 @@ 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).
|
||||
*
|
||||
@ -30,7 +28,6 @@ class LdapAuthService
|
||||
{
|
||||
// LDAP-Konfiguration in der Instanz speichern.
|
||||
$this->config = $ldapConfig;
|
||||
$this->connectionHelper = new LdapConnectionHelper($ldapConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,17 +50,30 @@ 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 ($domainSuffix === '') {
|
||||
throw new RuntimeException('LDAP-Konfiguration ist unvollständig (domain_suffix fehlt).');
|
||||
if ($server === '' || $domainSuffix === '') {
|
||||
throw new RuntimeException('LDAP-Konfiguration ist unvollständig.');
|
||||
}
|
||||
|
||||
// Verbindung zum LDAP/AD-Server herstellen.
|
||||
// Rückgabewert ist eine Ressource (Verbindungshandle) oder false bei Fehlern.
|
||||
$connection = $this->connectionHelper->createConnection();
|
||||
$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);
|
||||
|
||||
// UPN (User Principal Name) aus Benutzername und Domain-Suffix bilden.
|
||||
// Beispiel: "administrator" + "@ITFA-PROJ-DOM.local" -> "administrator@ITFA-PROJ-DOM.local"
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Ldap;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class LdapConnectionHelper
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
private array $config;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user