feat(auth): Anmeldung mit Passwort und OIDC, Schutz aller Seiten (#013)
Signierte Sitzungs-Cookies mit jose, OIDC ueber openid-client (authentik), Schutz in proxy.ts, Anmeldeseite, Audit-Log-Ansicht, Sicherheits-Kopfzeilen und Rate-Limit. Kein Auth.js, weil Version 5 Beta ist. 147 Tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import Link from "next/link";
|
||||
import { ContentHeader } from "@/components/layout/ContentHeader";
|
||||
import { Card } from "@/components/ui/Card";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { formatDatumZeit } from "@/lib/format";
|
||||
|
||||
export const metadata = { title: "Protokoll" };
|
||||
|
||||
type SuchParameter = Promise<Record<string, string | string[] | undefined>>;
|
||||
|
||||
export default async function AuditSeite({ searchParams }: { searchParams: SuchParameter }) {
|
||||
const roh = await searchParams;
|
||||
const einzeln = (wert: string | string[] | undefined) => (Array.isArray(wert) ? wert[0] : wert);
|
||||
const aktion = einzeln(roh.aktion);
|
||||
const entitaet = einzeln(roh.entitaet);
|
||||
|
||||
const [eintraege, aktionen] = await Promise.all([
|
||||
prisma.auditEintrag.findMany({
|
||||
where: {
|
||||
...(aktion ? { aktion } : {}),
|
||||
...(entitaet ? { entitaet } : {}),
|
||||
},
|
||||
orderBy: { erstelltAm: "desc" },
|
||||
take: 200,
|
||||
include: { benutzer: { select: { name: true, email: true } } },
|
||||
}),
|
||||
prisma.auditEintrag.groupBy({ by: ["aktion"], _count: { _all: true }, orderBy: { aktion: "asc" } }),
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContentHeader titel="Protokoll" brotkrumen={[{ titel: "Einstellungen" }, { titel: "Protokoll" }]} />
|
||||
|
||||
<div className="app-content">
|
||||
<div className="container-fluid">
|
||||
<Card titel={`Letzte ${eintraege.length} Einträge`} rahmen="primary" tabelle>
|
||||
<form className="row g-2 p-3 border-bottom">
|
||||
<div className="col-md-4">
|
||||
<select name="aktion" defaultValue={aktion ?? ""} className="form-select" aria-label="Aktion">
|
||||
<option value="">Alle Aktionen</option>
|
||||
{aktionen.map((eintrag) => (
|
||||
<option key={eintrag.aktion} value={eintrag.aktion}>
|
||||
{eintrag.aktion} ({eintrag._count._all})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<input
|
||||
name="entitaet"
|
||||
defaultValue={entitaet ?? ""}
|
||||
className="form-control"
|
||||
placeholder="Entität, z. B. Host"
|
||||
aria-label="Entität"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-2">
|
||||
<button type="submit" className="btn btn-primary w-100">
|
||||
Filtern
|
||||
</button>
|
||||
</div>
|
||||
<div className="col-md-3 d-flex align-items-center">
|
||||
{aktion || entitaet ? <Link href="/einstellungen/audit">Filter zurücksetzen</Link> : null}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div className="table-responsive">
|
||||
<table className="table table-striped align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Zeitpunkt</th>
|
||||
<th scope="col">Aktion</th>
|
||||
<th scope="col">Entität</th>
|
||||
<th scope="col">Benutzer</th>
|
||||
<th scope="col">Details</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{eintraege.map((eintrag) => (
|
||||
<tr key={eintrag.id}>
|
||||
<td className="small">{formatDatumZeit(eintrag.erstelltAm)}</td>
|
||||
<td className="pl-mono small">{eintrag.aktion}</td>
|
||||
<td className="small">
|
||||
{eintrag.entitaet}
|
||||
{eintrag.entitaetId ? (
|
||||
<div className="text-body-secondary pl-mono">{eintrag.entitaetId}</div>
|
||||
) : null}
|
||||
</td>
|
||||
<td className="small">{eintrag.benutzer?.name ?? "System"}</td>
|
||||
<td className="small text-body-secondary" style={{ maxWidth: "28rem" }}>
|
||||
<span className="d-inline-block text-truncate w-100">
|
||||
{eintrag.aenderung ? JSON.stringify(eintrag.aenderung) : "–"}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{eintraege.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="text-center text-body-secondary py-4">
|
||||
Keine Einträge gefunden.
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Footer } from "@/components/layout/Footer";
|
||||
import { Header } from "@/components/layout/Header";
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import { SITZUNGS_COOKIE, sitzungLesen } from "@/lib/sitzung";
|
||||
import { kennzahlen, offeneAlerts, suchIndex } from "@/server/queries/hosts";
|
||||
|
||||
/**
|
||||
@@ -9,9 +12,11 @@ import { kennzahlen, offeneAlerts, suchIndex } from "@/server/queries/hosts";
|
||||
*/
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const BENUTZER = "Florian";
|
||||
|
||||
export default async function DashboardLayout({ children }: { children: React.ReactNode }) {
|
||||
// Der Schutz liegt in proxy.ts; hier wird zusätzlich geprüft, damit kein Zustand ohne Benutzer entsteht.
|
||||
const sitzung = await sitzungLesen((await cookies()).get(SITZUNGS_COOKIE)?.value);
|
||||
if (!sitzung) redirect("/login");
|
||||
|
||||
const [zahlen, alerts, suche] = await Promise.all([kennzahlen(), offeneAlerts(), suchIndex()]);
|
||||
|
||||
return (
|
||||
@@ -25,13 +30,13 @@ export default async function DashboardLayout({ children }: { children: React.Re
|
||||
hostId: alert.hostId,
|
||||
}))}
|
||||
suchEintraege={suche}
|
||||
benutzer={BENUTZER}
|
||||
benutzer={sitzung.name}
|
||||
/>
|
||||
<Sidebar
|
||||
hostsAnzahl={zahlen.hostsGesamt}
|
||||
offeneRechnungspunkte={zahlen.offeneRechnungspunkte}
|
||||
offeneWarnungen={zahlen.offeneAlerts}
|
||||
benutzer={BENUTZER}
|
||||
benutzer={sitzung.name}
|
||||
/>
|
||||
<main className="app-main">{children}</main>
|
||||
<Footer />
|
||||
|
||||
Reference in New Issue
Block a user