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

- 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:
Friederich Loheide 2026-09-26 12:38:32 +00:00
parent 0ab0838050
commit 4fcc41ed30
172 changed files with 18940 additions and 293 deletions

View 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;
}

View 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;
}

View 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;
}
}

View 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);
}
}

View file

@ -0,0 +1,289 @@
<?php
namespace Inhaus\Plugins\Ldap;
use App\Identity\AttributeProfile;
use App\Identity\ExternalUser;
use App\Identity\IdentityException;
use App\Models\IdentityProvider;
use Inhaus\Plugins\Ldap\Connection\LdapConnection;
use Inhaus\Plugins\Ldap\Connection\LdapConnector;
/**
* Anmeldung und Abfragen gegen Active Directory bzw. OpenLDAP.
*
* Ablauf: mit dem Dienstkonto verbinden, Person über den Filter suchen, mit ihrem
* DN und Passwort anmelden (prüft das Passwort), danach Gruppen, Vorgesetzte*n und
* Foto mit dem Dienstkonto lesen.
*/
class LdapDirectory
{
public const PRESETS = [
'ad' => [
'user_filter' => '(&(objectCategory=person)(objectClass=user)(|(sAMAccountName={username})(userPrincipalName={username})(mail={username})))',
'uid_attribute' => 'objectGUID',
'photo_attribute' => 'thumbnailPhoto',
'group_filter' => '(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={dn}))',
],
'openldap' => [
'user_filter' => '(&(objectClass=inetOrgPerson)(|(uid={username})(mail={username})))',
'uid_attribute' => 'entryUUID',
'photo_attribute' => 'jpegPhoto',
'group_filter' => '(|(&(objectClass=groupOfNames)(member={dn}))(&(objectClass=groupOfUniqueNames)(uniqueMember={dn}))(&(objectClass=posixGroup)(memberUid={username})))',
],
];
public const DEFAULT_MAPS = [
'ad' => [
'first_name' => 'givenName', 'last_name' => 'sn', 'email' => 'mail', 'job_title' => 'title',
'department' => 'department', 'location' => 'physicalDeliveryOfficeName', 'phone' => 'telephoneNumber', 'mobile' => 'mobile',
],
'openldap' => [
'first_name' => 'givenName', 'last_name' => 'sn', 'email' => 'mail', 'job_title' => 'title',
'department' => 'ou', 'location' => 'l', 'phone' => 'telephoneNumber', 'mobile' => 'mobile',
],
];
/** Attribute, die nie als Text gespeichert oder angezeigt werden. */
private const BINARY = ['objectguid', 'objectsid', 'thumbnailphoto', 'jpegphoto', 'usercertificate', 'msexchmailboxguid', 'msexchmailboxsecuritydescriptor'];
private const SECRET = ['userpassword', 'unicodepwd', 'ntpassword', 'lmpassword'];
public function __construct(private readonly LdapConnector $connector) {}
public function authenticate(IdentityProvider $provider, string $username, string $password): ExternalUser
{
$username = trim($username);
if ($username === '' || $password === '' || str_contains($username, "\0")) {
throw new IdentityException('Benutzername oder Passwort ist falsch.');
}
$connection = $this->connectAsService($provider);
$entry = $this->findUser($connection, $provider, $username);
// Leeres Passwort wäre eine anonyme Anmeldung – oben ausgeschlossen.
if (! $entry || ! $connection->bind($entry['dn'], $password)) {
throw new IdentityException('Benutzername oder Passwort ist falsch.');
}
if ($this->isDisabled($entry)) {
throw new IdentityException('Ihr Konto ist im Verzeichnis deaktiviert. Bitte wenden Sie sich an die Administration.');
}
// Für Gruppen und Vorgesetzte wieder als Dienstkonto.
$this->bindService($connection, $provider);
return $this->toExternal($connection, $provider, $entry, $username);
}
/**
* Für „Verbindung testen“ im Admin: Dienstkonto prüfen und optional eine Person
* nachschlagen (ohne Passwort).
*
* @return array{user: ?ExternalUser, dn: ?string}
*/
public function test(IdentityProvider $provider, ?string $username): array
{
$connection = $this->connectAsService($provider);
if ($username === null || trim($username) === '') {
return ['user' => null, 'dn' => null];
}
$entry = $this->findUser($connection, $provider, trim($username));
if (! $entry) {
throw new IdentityException('Verbindung in Ordnung, aber „'.trim($username).'“ wurde mit dem Suchfilter nicht gefunden.');
}
return ['user' => $this->toExternal($connection, $provider, $entry, trim($username)), 'dn' => $entry['dn']];
}
public function connectAsService(IdentityProvider $provider): LdapConnection
{
$hosts = preg_split('/[\s,;]+/', (string) $provider->setting('hosts'), -1, PREG_SPLIT_NO_EMPTY) ?: [];
if ($hosts === [] || trim((string) $provider->setting('base_dn')) === '') {
throw new IdentityException('Die LDAP-Anmeldung ist nicht vollständig eingerichtet.');
}
$connection = $this->connector->connect([
'hosts' => $hosts,
'port' => ((int) $provider->setting('port')) ?: null,
'encryption' => (string) $provider->setting('encryption', 'ldaps'),
'verify_tls' => (bool) $provider->setting('verify_tls', true),
'timeout' => 8,
]);
$this->bindService($connection, $provider);
return $connection;
}
/**
* @return array{dn: string, attributes: array<string, list<string>>}|null
*/
public function findUser(LdapConnection $connection, IdentityProvider $provider, string $username): ?array
{
$filter = str_replace('{username}', self::escape($username), $this->setting($provider, 'user_filter'));
$entries = $connection->search((string) $provider->setting('base_dn'), $filter, ['*', '+', $this->setting($provider, 'uid_attribute')], 2);
// Mehrdeutige Treffer nie anmelden.
return count($entries) === 1 ? $entries[0] : null;
}
public function setting(IdentityProvider $provider, string $key): string
{
$value = trim((string) $provider->setting($key));
return $value !== '' ? $value : (self::PRESETS[$this->schema($provider)][$key] ?? '');
}
public function schema(IdentityProvider $provider): string
{
return $provider->setting('schema') === 'openldap' ? 'openldap' : 'ad';
}
/**
* Wert für einen LDAP-Filter maskieren (RFC 4515).
*/
public static function escape(string $value): string
{
return strtr($value, ['\\' => '\5c', '*' => '\2a', '(' => '\28', ')' => '\29', "\0" => '\00']);
}
/**
* objectGUID (binär, gemischte Byte-Reihenfolge) als Text.
*/
public static function guid(string $binary): string
{
if (strlen($binary) !== 16) {
return $binary;
}
$hex = unpack('Va/v2b/n2c/Nd', $binary);
return sprintf('%08x-%04x-%04x-%04x-%04x%08x', $hex['a'], $hex['b1'], $hex['b2'], $hex['c1'], $hex['c2'], $hex['d']);
}
private function bindService(LdapConnection $connection, IdentityProvider $provider): void
{
$dn = trim((string) $provider->setting('bind_dn'));
if (! $connection->bind($dn !== '' ? $dn : null, $dn !== '' ? (string) $provider->setting('bind_password') : null)) {
throw new IdentityException('Das Dienstkonto für das Verzeichnis wurde abgelehnt. Bitte wenden Sie sich an die Administration.');
}
}
/**
* @param array{dn: string, attributes: array<string, list<string>>} $entry
*/
private function isDisabled(array $entry): bool
{
$control = (int) ($entry['attributes']['useraccountcontrol'][0] ?? 0);
return ($control & 2) === 2;
}
/**
* @param array{dn: string, attributes: array<string, list<string>>} $entry
*/
private function subject(IdentityProvider $provider, array $entry): string
{
$attribute = strtolower($this->setting($provider, 'uid_attribute'));
$value = $entry['attributes'][$attribute][0] ?? null;
if ($value === null || $value === '') {
throw new IdentityException('Im Verzeichnis fehlt die eindeutige Kennung („'.$this->setting($provider, 'uid_attribute').'“).');
}
return $attribute === 'objectguid' ? self::guid($value) : $value;
}
/**
* @param array{dn: string, attributes: array<string, list<string>>} $entry
*/
private function toExternal(LdapConnection $connection, IdentityProvider $provider, array $entry, string $username): ExternalUser
{
$attributes = array_diff_key($entry['attributes'], array_flip(self::SECRET));
$text = array_diff_key($attributes, array_flip(self::BINARY));
$text['dn'] = [$entry['dn']];
$profile = AttributeProfile::build($provider, $text, [
'display_name' => 'displayName',
'first_name' => 'givenName',
'last_name' => 'sn',
'email' => 'mail',
]);
if ($provider->syncsManager()) {
$profile['manager_subject'] = $this->managerSubject($connection, $provider, $attributes['manager'][0] ?? null);
}
$photo = false;
if ($provider->setting('sync_photo', false)) {
$photo = $attributes[strtolower($this->setting($provider, 'photo_attribute'))][0] ?? null;
}
return new ExternalUser(
subject: $this->subject($provider, $entry),
profile: $profile,
groups: $this->groups($connection, $provider, $entry, $username),
attributes: $text,
photo: $photo,
);
}
/**
* Gruppen-DNs: direkt aus memberOf und – falls eingestellt – über eine Gruppensuche
* (AD: inklusive verschachtelter Gruppen).
*
* @param array{dn: string, attributes: array<string, list<string>>} $entry
* @return list<string>
*/
private function groups(LdapConnection $connection, IdentityProvider $provider, array $entry, string $username): array
{
$groups = $entry['attributes']['memberof'] ?? [];
if ($provider->setting('group_search', true)) {
$filter = strtr($this->setting($provider, 'group_filter'), [
'{dn}' => self::escape($entry['dn']),
'{username}' => self::escape($username),
]);
$base = trim((string) $provider->setting('group_base_dn')) ?: (string) $provider->setting('base_dn');
try {
foreach ($connection->search($base, $filter, ['dn'], 1000) as $group) {
$groups[] = $group['dn'];
}
} catch (IdentityException $e) {
logger()->warning('LDAP-Gruppensuche fehlgeschlagen: '.$e->getMessage());
}
}
$unique = [];
foreach ($groups as $dn) {
$unique[strtolower($dn)] ??= $dn;
}
return array_values($unique);
}
private function managerSubject(LdapConnection $connection, IdentityProvider $provider, ?string $managerDn): ?string
{
if (! $managerDn) {
return null;
}
$entry = $connection->read($managerDn, [$this->setting($provider, 'uid_attribute')]);
try {
return $entry ? $this->subject($provider, $entry) : null;
} catch (IdentityException) {
return null;
}
}
}

View file

@ -0,0 +1,196 @@
<?php
namespace Inhaus\Plugins\Ldap;
use App\Identity\ExternalUser;
use App\Identity\IdentityDriver;
use App\Models\IdentityProvider;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Support\Icons\Heroicon;
use Illuminate\Http\Request;
use Illuminate\Support\HtmlString;
use Inertia\Inertia;
use Inhaus\Plugins\Ldap\Connection\LdapConnector;
use Inhaus\Plugins\Ldap\Connection\NativeLdapConnector;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
/**
* Anmeldung mit Benutzername und Passwort gegen Active Directory oder OpenLDAP.
*/
class LdapDriver extends IdentityDriver
{
public const TYPE = 'ldap';
public function __construct(private readonly LdapDirectory $directory) {}
public function type(): string
{
return self::TYPE;
}
public function label(): string
{
return 'LDAP / Active Directory';
}
public function description(): string
{
return 'Lokales Active Directory oder OpenLDAP – Anmeldung mit dem Windows- bzw. Verzeichnis-Passwort.';
}
public function defaultButtonLabel(IdentityProvider $provider): string
{
return 'Mit Firmenkonto anmelden';
}
public function unavailableReason(): ?string
{
return function_exists('ldap_connect') || ! app(LdapConnector::class) instanceof NativeLdapConnector
? null
: 'Die PHP-Erweiterung „ldap“ ist auf diesem Server nicht installiert. Bitte beim Hoster aktivieren lassen.';
}
public function connectionHelp(?IdentityProvider $provider): string
{
return 'Das Portal meldet sich mit einem Dienstkonto (nur Leserechte) am Verzeichnis an, sucht die Person und prüft dann ihr Passwort. '
.'Die Verbindung sollte verschlüsselt sein (LDAPS oder StartTLS) – Passwörter gehen sonst im Klartext über das Netz.';
}
public function connectionSchema(): array
{
return [
Select::make('config.schema')->label('Verzeichnis')->native(false)->required()->default('ad')->selectablePlaceholder(false)->live()
->options(['ad' => 'Microsoft Active Directory', 'openldap' => 'OpenLDAP / andere']),
TextInput::make('config.hosts')->label('Server')->required()->maxLength(500)
->placeholder('dc1.firma.local dc2.firma.local')
->helperText('Mehrere Server mit Leerzeichen trennen – der nächste wird genutzt, wenn einer ausfällt.'),
Select::make('config.encryption')->label('Verschlüsselung')->native(false)->required()->default('ldaps')->selectablePlaceholder(false)
->options(['ldaps' => 'LDAPS (Port 636)', 'starttls' => 'StartTLS (Port 389)', 'none' => 'Keine – nicht empfohlen']),
TextInput::make('config.port')->label('Port')->numeric()->minValue(1)->maxValue(65535)->placeholder('Standard'),
Toggle::make('config.verify_tls')->label('Zertifikat des Servers prüfen')->default(true)
->helperText('Nur für Tests mit selbst signierten Zertifikaten ausschalten.')->columnSpanFull(),
TextInput::make('config.base_dn')->label('Suchbasis (Base DN)')->required()->maxLength(500)->placeholder('DC=firma,DC=local')->columnSpanFull(),
TextInput::make('config.bind_dn')->label('Dienstkonto (DN oder UPN)')->maxLength(500)->placeholder('CN=svc-portal,OU=Dienste,DC=firma,DC=local'),
TextInput::make('config.bind_password')->label('Passwort des Dienstkontos')->password()->revealable()->maxLength(1000)
->helperText(fn (string $operation) => $operation === 'edit' ? 'Leer lassen, um das gespeicherte Passwort zu behalten.' : null),
TextInput::make('config.user_filter')->label('Suchfilter für Personen')->maxLength(1000)->columnSpanFull()
->placeholder(fn (Get $get) => LdapDirectory::PRESETS[$get('config.schema') === 'openldap' ? 'openldap' : 'ad']['user_filter'])
->helperText('{username} steht für die Eingabe. Leer = Standard für das gewählte Verzeichnis.'),
TextInput::make('config.uid_attribute')->label('Eindeutige Kennung')->maxLength(100)
->placeholder(fn (Get $get) => LdapDirectory::PRESETS[$get('config.schema') === 'openldap' ? 'openldap' : 'ad']['uid_attribute'])
->helperText('Darf sich nie ändern – nicht den Benutzernamen verwenden.'),
TextInput::make('config.username_label')->label('Beschriftung des Benutzernamens')->maxLength(60)->placeholder('Benutzername'),
Toggle::make('config.group_search')->label('Gruppen zusätzlich suchen')->default(true)->live()
->helperText('AD: inklusive verschachtelter Gruppen. Sonst zählt nur memberOf.'),
TextInput::make('config.group_base_dn')->label('Suchbasis für Gruppen')->maxLength(500)->placeholder('wie oben')
->visible(fn (Get $get) => (bool) $get('config.group_search')),
TextInput::make('config.group_filter')->label('Suchfilter für Gruppen')->maxLength(1000)->columnSpanFull()
->placeholder(fn (Get $get) => LdapDirectory::PRESETS[$get('config.schema') === 'openldap' ? 'openldap' : 'ad']['group_filter'])
->helperText('{dn} = DN der Person, {username} = Eingabe. Leer = Standard.')
->visible(fn (Get $get) => (bool) $get('config.group_search')),
];
}
public function adminActions(): array
{
return [
Action::make('testLdap')->label('Verbindung testen')->icon(Heroicon::OutlinedSignal)->color('gray')->size('sm')
->modalHeading('Verbindung zum Verzeichnis testen')
->modalDescription('Prüft das Dienstkonto mit den gespeicherten Einstellungen. Mit Benutzername zeigt der Test, welche Angaben und Gruppen das Portal erhält – ohne Passwort, ohne Anmeldung.')
->modalSubmitActionLabel('Testen')
->schema([TextInput::make('username')->label('Benutzername (optional)')->maxLength(191)])
->action(function (array $data, IdentityProvider $record, Action $action) {
try {
$result = $this->directory->test($record, $data['username'] ?? null);
} catch (Throwable $e) {
Notification::make()->danger()->title('Test fehlgeschlagen')->body($e->getMessage())->persistent()->send();
$action->halt();
return;
}
if (! $result['user']) {
Notification::make()->success()->title('Verbindung und Dienstkonto in Ordnung')->send();
return;
}
Notification::make()->success()->persistent()->title('Gefunden: '.$result['dn'])
->body(new HtmlString(self::summary($result['user'])))->send();
}),
];
}
public function secretFields(): array
{
return ['bind_password'];
}
public function defaultAttributeMap(): array
{
return LdapDirectory::DEFAULT_MAPS['ad'];
}
public function attributeSuggestions(?IdentityProvider $provider): array
{
return [
'givenName' => 'Vorname', 'sn' => 'Nachname', 'displayName' => 'Anzeigename', 'mail' => 'E-Mail',
'title' => 'Funktion', 'department' => 'Abteilung', 'company' => 'Firma', 'physicalDeliveryOfficeName' => 'Büro',
'l' => 'Ort', 'telephoneNumber' => 'Telefon', 'mobile' => 'Mobil', 'employeeID' => 'Personalnummer (AD)',
'employeeNumber' => 'Personalnummer', 'sAMAccountName' => 'Anmeldename (AD)', 'uid' => 'Benutzername (OpenLDAP)',
'extensionAttribute1' => 'Erweiterungsattribut 1 (AD)', 'extensionAttribute2' => 'Erweiterungsattribut 2 (AD)',
];
}
public function supportsManager(): bool
{
return true;
}
public function supportsPhoto(): bool
{
return true;
}
public function groupValueLabel(): string
{
return 'DN der Gruppe';
}
public function start(IdentityProvider $provider, Request $request): Response
{
return Inertia::render('Auth/DirectoryLogin', [
'provider' => [
'name' => $provider->name,
'label' => $provider->buttonLabel(),
'action' => route('identity.login', $provider),
'username_label' => $provider->setting('username_label') ?: 'Benutzername',
],
])->toResponse($request);
}
protected function authenticate(IdentityProvider $provider, Request $request): ExternalUser
{
return $this->directory->authenticate($provider, (string) $request->input('username'), (string) $request->input('password'));
}
public static function summary(ExternalUser $user): string
{
$rows = collect($user->profile)->except('custom')->filter(fn ($v) => is_scalar($v) && $v !== '')
->map(fn ($v, $k) => e($k).': '.e((string) $v));
$rows->push('Kennung: '.e($user->subject));
$rows->push('Gruppen: '.($user->groups === [] ? 'keine' : e(implode(' · ', array_slice($user->groups, 0, 15)))));
if ($user->photo !== false) {
$rows->push('Foto: '.($user->photo ? 'vorhanden' : 'keins'));
}
return $rows->implode('<br>');
}
}

View file

@ -0,0 +1,17 @@
<?php
namespace Inhaus\Plugins\Ldap;
use App\Identity\IdentityDrivers;
use App\Plugins\Plugin;
use Inhaus\Plugins\Ldap\Connection\LdapConnector;
use Inhaus\Plugins\Ldap\Connection\NativeLdapConnector;
class LdapPlugin extends Plugin
{
public function register(): void
{
$this->app->bindIf(LdapConnector::class, NativeLdapConnector::class);
$this->app->make(IdentityDrivers::class)->add(LdapDriver::TYPE, LdapDriver::class);
}
}