Phase 6 (Teil 2): OpenID Connect, LDAP/AD und SAML 2
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m48s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m15s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m17s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m59s
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m48s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m15s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m17s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m59s
- Gemeinsamer Treiber-Unterbau (App\Identity\IdentityDriver, IdentityDrivers, IdentityLogin, AttributeProfile); Entra ID nutzt ihn ebenfalls - Plugins oidc, ldap und saml mit Profil- und Gruppen-Zuordnung - Admin: Verfahren wählen, Formular je Verfahren, zuletzt empfangene Angaben - onelogin/php-saml als neue Abhängigkeit Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0ab0838050
commit
4fcc41ed30
172 changed files with 18940 additions and 293 deletions
29
plugins-core/ldap/src/Connection/LdapConnection.php
Normal file
29
plugins-core/ldap/src/Connection/LdapConnection.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ldap\Connection;
|
||||
|
||||
/**
|
||||
* Eine Verbindung zum Verzeichnis. Einträge kommen normalisiert zurück:
|
||||
* ['dn' => '…', 'attributes' => ['kleingeschriebener name' => list<string>]].
|
||||
*/
|
||||
interface LdapConnection
|
||||
{
|
||||
/** Anmelden; null/null = anonym. false bei falschen Zugangsdaten. */
|
||||
public function bind(?string $dn, ?string $password): bool;
|
||||
|
||||
/**
|
||||
* @param list<string> $attributes
|
||||
* @return list<array{dn: string, attributes: array<string, list<string>>}>
|
||||
*/
|
||||
public function search(string $base, string $filter, array $attributes, int $limit = 0): array;
|
||||
|
||||
/**
|
||||
* Einen Eintrag direkt lesen.
|
||||
*
|
||||
* @param list<string> $attributes
|
||||
* @return array{dn: string, attributes: array<string, list<string>>}|null
|
||||
*/
|
||||
public function read(string $dn, array $attributes): ?array;
|
||||
|
||||
public function lastError(): string;
|
||||
}
|
||||
11
plugins-core/ldap/src/Connection/LdapConnector.php
Normal file
11
plugins-core/ldap/src/Connection/LdapConnector.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ldap\Connection;
|
||||
|
||||
interface LdapConnector
|
||||
{
|
||||
/**
|
||||
* @param array{hosts: list<string>, port: ?int, encryption: string, verify_tls: bool, timeout: int} $options
|
||||
*/
|
||||
public function connect(array $options): LdapConnection;
|
||||
}
|
||||
78
plugins-core/ldap/src/Connection/NativeLdapConnection.php
Normal file
78
plugins-core/ldap/src/Connection/NativeLdapConnection.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ldap\Connection;
|
||||
|
||||
use App\Identity\IdentityException;
|
||||
use LDAP\Connection;
|
||||
|
||||
class NativeLdapConnection implements LdapConnection
|
||||
{
|
||||
/** Ungültige Zugangsdaten – alles andere ist ein Verbindungs- oder Serverfehler. */
|
||||
private const INVALID_CREDENTIALS = 49;
|
||||
|
||||
public function __construct(private readonly Connection $link) {}
|
||||
|
||||
public function bind(?string $dn, ?string $password): bool
|
||||
{
|
||||
if (@ldap_bind($this->link, $dn, $password)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ldap_errno($this->link) === self::INVALID_CREDENTIALS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new IdentityException('Der Verzeichnisserver ist nicht erreichbar: '.ldap_error($this->link));
|
||||
}
|
||||
|
||||
public function search(string $base, string $filter, array $attributes, int $limit = 0): array
|
||||
{
|
||||
$result = @ldap_search($this->link, $base, $filter, $attributes, 0, $limit);
|
||||
|
||||
// 4 = Größenlimit erreicht: Teilergebnis ist in Ordnung.
|
||||
if ($result === false && ldap_errno($this->link) !== 4) {
|
||||
throw new IdentityException('Suche im Verzeichnis fehlgeschlagen: '.ldap_error($this->link));
|
||||
}
|
||||
|
||||
return $result === false ? [] : $this->entries($result);
|
||||
}
|
||||
|
||||
public function read(string $dn, array $attributes): ?array
|
||||
{
|
||||
$result = @ldap_read($this->link, $dn, '(objectClass=*)', $attributes);
|
||||
|
||||
return $result === false ? null : ($this->entries($result)[0] ?? null);
|
||||
}
|
||||
|
||||
public function lastError(): string
|
||||
{
|
||||
return ldap_error($this->link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{dn: string, attributes: array<string, list<string>>}>
|
||||
*/
|
||||
private function entries($result): array
|
||||
{
|
||||
$entries = [];
|
||||
|
||||
for ($entry = ldap_first_entry($this->link, $result); $entry !== false; $entry = ldap_next_entry($this->link, $entry)) {
|
||||
$attributes = [];
|
||||
|
||||
foreach (ldap_get_attributes($this->link, $entry) as $name => $values) {
|
||||
if (! is_string($name) || ! is_array($values) || $name === 'count') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Binärwerte (objectGUID, thumbnailPhoto) unverändert lesen.
|
||||
$raw = @ldap_get_values_len($this->link, $entry, $name) ?: [];
|
||||
unset($raw['count']);
|
||||
$attributes[strtolower($name)] = array_values($raw);
|
||||
}
|
||||
|
||||
$entries[] = ['dn' => (string) ldap_get_dn($this->link, $entry), 'attributes' => $attributes];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
}
|
||||
45
plugins-core/ldap/src/Connection/NativeLdapConnector.php
Normal file
45
plugins-core/ldap/src/Connection/NativeLdapConnector.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ldap\Connection;
|
||||
|
||||
use App\Identity\IdentityException;
|
||||
use LDAP\Connection;
|
||||
|
||||
/**
|
||||
* Verbindung über die PHP-Erweiterung „ldap“.
|
||||
*/
|
||||
class NativeLdapConnector implements LdapConnector
|
||||
{
|
||||
public function connect(array $options): LdapConnection
|
||||
{
|
||||
if (! function_exists('ldap_connect')) {
|
||||
throw new IdentityException('Die PHP-Erweiterung „ldap“ ist auf diesem Server nicht installiert.');
|
||||
}
|
||||
|
||||
$scheme = $options['encryption'] === 'ldaps' ? 'ldaps' : 'ldap';
|
||||
$port = $options['port'] ?: ($scheme === 'ldaps' ? 636 : 389);
|
||||
$uris = implode(' ', array_map(fn ($host) => str_contains($host, '://') ? $host : "{$scheme}://{$host}:{$port}", $options['hosts']));
|
||||
|
||||
if (! $options['verify_tls']) {
|
||||
// Muss vor ldap_connect gesetzt werden, damit es für die Verbindung gilt.
|
||||
ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
|
||||
}
|
||||
|
||||
$link = ldap_connect($uris);
|
||||
|
||||
if (! $link instanceof Connection) {
|
||||
throw new IdentityException('Die Adresse des Verzeichnisservers ist ungültig.');
|
||||
}
|
||||
|
||||
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($link, LDAP_OPT_REFERRALS, 0);
|
||||
ldap_set_option($link, LDAP_OPT_NETWORK_TIMEOUT, $options['timeout']);
|
||||
ldap_set_option($link, LDAP_OPT_TIMELIMIT, $options['timeout']);
|
||||
|
||||
if ($options['encryption'] === 'starttls' && ! @ldap_start_tls($link)) {
|
||||
throw new IdentityException('Verschlüsselte Verbindung (StartTLS) zum Verzeichnis fehlgeschlagen: '.ldap_error($link));
|
||||
}
|
||||
|
||||
return new NativeLdapConnection($link);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue