Loheide-eu-mitarbeiterplatt.../app/Filament/Resources/IdentityProviders/Pages/EditIdentityProvider.php
Friederich Loheide f1202bea08
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Sicherheitsupdate nach Audit (0.29.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 11:34:54 +00:00

89 lines
3.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Resources\IdentityProviders\Pages;
use App\Filament\Resources\IdentityProviders\IdentityProviderResource;
use App\Models\IdentityProvider;
use App\Support\Audit;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
use Filament\Support\Icons\Heroicon;
use Illuminate\Validation\ValidationException;
class EditIdentityProvider extends EditRecord
{
protected static string $resource = IdentityProviderResource::class;
/**
* Das Geheimnis nie ins Formular (und damit in den Browser) schreiben.
*/
protected function mutateFormDataBeforeFill(array $data): array
{
foreach ($this->secretFields() as $field) {
$data['config'][$field] = null;
}
// Ältere Konfiguration (feste Feldliste) als Zuordnung anzeigen.
if (! is_array($data['config']['attribute_map'] ?? null)) {
$data['config']['attribute_map'] = collect($this->record->attributeMap())
->map(fn ($attribute, $target) => ['target' => $target, 'attribute' => $attribute])->values()->all();
$data['config']['sync_manager'] = $this->record->syncsManager();
}
return $data;
}
/**
* Leeres Geheimnis = gespeichertes behalten.
*/
protected function mutateFormDataBeforeSave(array $data): array
{
$destinationChanged = collect($this->record->driver()?->destinationFields() ?? [])
->contains(fn (string $field) => (string) ($data['config'][$field] ?? '') !== (string) ($this->record->setting($field) ?? ''));
foreach ($this->secretFields() as $field) {
if (blank($data['config'][$field] ?? null)) {
// Gespeichertes Geheimnis nur für dasselbe Ziel weiterverwenden
if ($destinationChanged && filled($this->record->setting($field))) {
throw ValidationException::withMessages(["data.config.{$field}" => 'Server bzw. Aussteller wurden geändert – bitte das Geheimnis erneut eingeben.']);
}
$data['config'][$field] = $this->record->setting($field);
}
}
if ($this->record->type === IdentityProvider::ENTRA) {
// Geladene Erweiterungen liegen nur in der Datenbank, nicht im Formular.
$data['config']['extension_properties'] = $this->record->fresh()?->setting('extension_properties', []) ?? [];
}
$data['config']['attribute_map'] = array_values((array) ($data['config']['attribute_map'] ?? []));
unset($data['config']['synced_fields']);
return $data;
}
/**
* @return list<string>
*/
private function secretFields(): array
{
return $this->record->driver()?->secretFields() ?? ['client_secret', 'bind_password'];
}
protected function afterSave(): void
{
Audit::log('identity.provider_updated', ['provider' => $this->record->name, 'enabled' => $this->record->enabled]);
}
protected function getHeaderActions(): array
{
return [
Action::make('test')->label('Mapping testen')->icon(Heroicon::OutlinedBeaker)->color('gray')
->visible($this->record->type === IdentityProvider::ENTRA)
->url(fn () => IdentityProviderResource::getUrl('test', ['record' => $this->record])),
DeleteAction::make()->modalDescription('Verknüpfungen und Rollen aus Gruppen dieses Anbieters werden entfernt. Die Konten selbst bleiben bestehen.'),
];
}
}