Connection Helper-Klasse erstellt
This commit is contained in:
parent
a7bb3cac6e
commit
a6c6e8d67a
49
app/Services/Ldap/LdapConnectionHelper.php
Normal file
49
app/Services/Ldap/LdapConnectionHelper.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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