1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
"use client";
import {
Background,
Controls,
MiniMap,
ReactFlow,
ReactFlowProvider,
useEdgesState,
useNodesState,
useReactFlow,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import { useCallback, useEffect, useMemo, useState } from "react";
import { ChevronLeft, ChevronRight, ShieldCheck } from "lucide-react";
import { ZTFlowNode } from "./ZTFlowNode";
import { ZERO_TRUST_SCENARIOS } from "./scenarios";
import type { ZTScenarioDefinition, ZTScenarioStep } from "./types";
import { PILLAR_LABELS } from "./types";
import { cn } from "@/lib/utils";
const nodeTypes = { ztNode: ZTFlowNode };
const CROSS_CUTTING = [
"Never trust, always verify — aucune confiance implicite au réseau seul.",
"Moindre privilège sur les accès, comptes de service et flux.",
"Supposer la compromission : limiter le rayon d’explosion (blast radius).",
"Vérification continue : identité, contexte et signaux de risque.",
"Journalisation, corrélation et observabilité pour détecter les abus.",
];
function applyStepStyle(
scenario: ZTScenarioDefinition,
step: ZTScenarioStep | undefined,
) {
const hn = step?.highlightNodes ?? [];
const he = step?.highlightEdges ?? [];
const nodeDim =
hn.length > 0 ? (id: string) => !hn.includes(id) : () => false;
const edgeDim =
he.length > 0 ? (id: string) => !he.includes(id) : () => false;
const nodes = scenario.nodes.map((n) => ({
...n,
className: cn(
"transition-all duration-300",
nodeDim(n.id) ? "opacity-[0.38]" : "opacity-100",
hn.includes(n.id) &&
"ring-2 ring-araucaria-400 ring-offset-2 ring-offset-cosmos-950 rounded-xl",
),
}));
const edges = scenario.edges.map((e) => {
const dimE = edgeDim(e.id);
const baseStyle = (e.style as Record<string, unknown> | undefined) ?? {};
return {
...e,
animated: he.length === 0 ? e.animated : he.includes(e.id),
style: {
...baseStyle,
opacity: dimE ? 0.32 : 1,
},
labelStyle: {
...(e.labelStyle as object),
opacity: dimE ? 0.45 : 1,
},
zIndex: he.includes(e.id) ? 10 : 0,
};
});
return { nodes, edges };
}
function FitViewSync({
scenarioId,
stepIndex,
}: {
scenarioId: string;
stepIndex: number;
}) {
const { fitView } = useReactFlow();
const run = useCallback(() => {
const id = requestAnimationFrame(() => {
fitView({ padding: 0.18, duration: 280, maxZoom: 1.35 });
});
return () => cancelAnimationFrame(id);
}, [fitView]);
useEffect(() => {
const t = setTimeout(run, 60);
return () => clearTimeout(t);
}, [scenarioId, stepIndex, run]);
return null;
}
function FlowCanvas({
scenario,
step,
}: {
scenario: ZTScenarioDefinition;
step: ZTScenarioStep | undefined;
}) {
const { nodes: initialNodes, edges: initialEdges } = useMemo(
() => applyStepStyle(scenario, step),
[scenario, step],
);
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
useEffect(() => {
const styled = applyStepStyle(scenario, step);
setNodes(styled.nodes);
setEdges(styled.edges);
}, [scenario, step, setNodes, setEdges]);
return (
<div className="h-[min(70vh,560px)] min-h-[420px] w-full rounded-xl border border-cosmos-700 bg-cosmos-950">
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
nodeTypes={nodeTypes}
fitView
attributionPosition="bottom-left"
proOptions={{ hideAttribution: true }}
className="bg-cosmos-950"
defaultEdgeOptions={{
type: "smoothstep",
}}
aria-label="Schéma interactif des flux et des composants de sécurité"
>
<FitViewSync
scenarioId={scenario.id}
stepIndex={step ? scenario.steps.indexOf(step) : 0}
/>
<Background color="#475569" gap={20} size={1} />
<Controls
className="!m-3 !border-cosmos-600 !bg-cosmos-900 !fill-nieve [&_button]:!border-cosmos-600 [&_button:hover]:!bg-cosmos-800"
showInteractive={false}
/>
<MiniMap
nodeStrokeWidth={2}
className="!m-3 !rounded-lg !border !border-cosmos-600 !bg-cosmos-900"
maskColor="rgba(15, 23, 42, 0.75)"
/>
</ReactFlow>
</div>
);
}
export function ZeroTrustScenarioViewer() {
const [scenarioIndex, setScenarioIndex] = useState(0);
const [stepIndex, setStepIndex] = useState(0);
const scenario = ZERO_TRUST_SCENARIOS[scenarioIndex]!;
const step = scenario.steps[stepIndex];
useEffect(() => {
setStepIndex(0);
}, [scenarioIndex]);
const goPrev = () =>
setStepIndex((i) => Math.max(0, i - 1));
const goNext = () =>
setStepIndex((i) => Math.min(scenario.steps.length - 1, i + 1));
return (
<div className="space-y-8">
<div className="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
<div className="max-w-xl">
<label htmlFor="zt-scenario" className="sr-only">
Choisir un scénario
</label>
<select
id="zt-scenario"
value={scenario.id}
onChange={(e) => {
const idx = ZERO_TRUST_SCENARIOS.findIndex(
(s) => s.id === e.target.value,
);
if (idx >= 0) setScenarioIndex(idx);
}}
className="w-full rounded-lg border border-cosmos-600 bg-nieve px-4 py-2.5 text-sm font-medium text-cosmos-900 shadow-sm focus:border-araucaria-500 focus:outline-none focus:ring-2 focus:ring-araucaria-400 sm:max-w-md"
>
{ZERO_TRUST_SCENARIOS.map((s) => (
<option key={s.id} value={s.id}>
{s.title}
</option>
))}
</select>
<p className="mt-2 text-sm text-muted">{scenario.subtitle}</p>
</div>
<div className="flex items-center gap-2">
<button
type="button"
onClick={goPrev}
disabled={stepIndex === 0}
className="inline-flex items-center gap-1 rounded-lg border border-cosmos-600 bg-nieve px-3 py-2 text-sm font-medium text-cosmos-800 shadow-sm transition hover:bg-cosmos-50 disabled:cursor-not-allowed disabled:opacity-40"
>
<ChevronLeft className="h-4 w-4" aria-hidden />
Étape précédente
</button>
<button
type="button"
onClick={goNext}
disabled={stepIndex >= scenario.steps.length - 1}
className="inline-flex items-center gap-1 rounded-lg border border-cosmos-600 bg-nieve px-3 py-2 text-sm font-medium text-cosmos-800 shadow-sm transition hover:bg-cosmos-50 disabled:cursor-not-allowed disabled:opacity-40"
>
Étape suivante
<ChevronRight className="h-4 w-4" aria-hidden />
</button>
</div>
</div>
<p className="text-sm leading-relaxed text-cosmos-700">{scenario.intro}</p>
<ReactFlowProvider>
<FlowCanvas scenario={scenario} step={step} />
</ReactFlowProvider>
<div className="grid gap-8 lg:grid-cols-2">
<div className="rounded-xl border border-border bg-nieve p-6 shadow-sm">
<div className="flex items-center gap-2 text-cosmos-900">
<ShieldCheck className="h-5 w-5 text-araucaria-600" aria-hidden />
<h3 className="text-lg font-semibold">
Étape {stepIndex + 1} — {step?.title}
</h3>
</div>
<p className="mt-3 text-sm leading-relaxed text-muted">
{step?.description}
</p>
{step && step.pillars.length > 0 && (
<div className="mt-4">
<p className="text-xs font-semibold uppercase tracking-wide text-cosmos-500">
Piliers NIST SP 800-207 (rappel)
</p>
<ul className="mt-2 flex flex-wrap gap-2">
{step.pillars.map((p) => (
<li
key={p}
className="rounded-full bg-araucaria-50 px-3 py-1 text-xs font-medium text-araucaria-900 ring-1 ring-araucaria-200"
>
{PILLAR_LABELS[p]}
</li>
))}
</ul>
</div>
)}
{step && (
<ul className="mt-4 list-disc space-y-2 pl-5 text-sm text-cosmos-800">
{step.practices.map((line, i) => (
<li key={i}>{line}</li>
))}
</ul>
)}
</div>
<div className="rounded-xl border border-border bg-cosmos-900/5 p-6">
<h3 className="text-lg font-semibold text-cosmos-900">
Principes transverses Zero Trust
</h3>
<ul className="mt-4 space-y-3 text-sm leading-relaxed text-cosmos-800">
{CROSS_CUTTING.map((line, i) => (
<li key={i} className="flex gap-2">
<span className="mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-araucaria-500" />
<span>{line}</span>
</li>
))}
</ul>
<p className="mt-6 text-xs text-cosmos-500">
Référence : modèle en piliers décrit dans NIST SP 800-207 (Zero Trust
Architecture). Les libellés sont vulgarisés pour l’interface.
</p>
</div>
</div>
</div>
);
}
|