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
196
plugins-core/ldap/src/LdapDriver.php
Normal file
196
plugins-core/ldap/src/LdapDriver.php
Normal 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>');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue