Debian Codegraph @

install/freeipa-webui/src/pages/KrbTicketPolicy/KrbTicketPolicy.tsx

raw
1 import React from "react";
2 // PatternFly
3 import {
4 Flex,
5 FlexItem,
6 Form,
7 FormGroup,
8 JumpLinks,
9 JumpLinksItem,
10 Sidebar,
11 SidebarContent,
12 SidebarPanel,
13 } from "@patternfly/react-core";
14 // Data types
15 import { KrbTicket } from "src/utils/datatypes/globalDataTypes";
16 // Redux
17 import { useAppDispatch } from "src/store/hooks";
18 // Hooks
19 import { addAlert } from "src/store/Global/alerts-slice";
20 import useUpdateRoute from "src/hooks/useUpdateRoute";
21 import { useKrbTicketPolicyData } from "src/hooks/useKrbTicketPolicyData";
22 // Icons
23 import { OutlinedQuestionCircleIcon } from "@patternfly/react-icons";
24 // RPC
25 import {
26 KrbTicketModPayload,
27 useKrbTicketModMutation,
28 } from "src/services/rpcKrbTicketPolicy";
29 // Components
30 import { NotFound } from "src/components/errors/PageErrors";
31 import DataSpinner from "src/components/layouts/DataSpinner";
32 import TitleLayout from "src/components/layouts/TitleLayout";
33 import HelpTextWithIconLayout from "src/components/layouts/HelpTextWithIconLayout";
34 import { asRecord } from "src/utils/krbTicketUtils";
35 import SecondaryButton from "src/components/layouts/SecondaryButton";
36 import IpaTextInput from "src/components/Form/IpaTextInput";
37 import PageWithGrayBorderLayout from "src/components/layouts/PageWithGrayBorderLayout";
38
39 const KrbTicketPolicy = () => {
40 const dispatch = useAppDispatch();
41
42 // API calls
43 const krbTicketPolicyData = useKrbTicketPolicyData();
44 const [saveKrbTicketPolicy] = useKrbTicketModMutation();
45
46 // Update current route data to Redux and highlight the current page in the Nav bar
47 const { browserTitle } = useUpdateRoute({
48 pathname: "kerberos-ticket-policy",
49 });
50
51 // Set the page title to be shown in the browser tab
52 React.useEffect(() => {
53 document.title = browserTitle;
54 }, [browserTitle]);
55
56 // States
57 const [isDataLoading, setIsDataLoading] = React.useState(false);
58
59 // Get 'ipaObject' and 'recordOnChange' to use in 'IpaTextInput'
60 const { ipaObject, recordOnChange } = asRecord(
61 krbTicketPolicyData.krbTicket,
62 krbTicketPolicyData.setKrbTicket
63 );
64
65 // Helper method to build the payload based on values
66 const buildPayload = (
67 modifiedValues: Partial<KrbTicket>,
68 keyArray: string[]
69 ): KrbTicketModPayload => {
70 const payload: KrbTicketModPayload = {};
71
72 keyArray.forEach((key) => {
73 // Modified values are either the value (in string) or an array ([]) when set to empty string
74 if (modifiedValues[key] !== undefined) {
75 if (modifiedValues[key] === "") {
76 payload[key] = [];
77 } else {
78 payload[key] = modifiedValues[key];
79 }
80 }
81 });
82 return payload;
83 };
84
85 // 'Revert' handler method
86 const onRevert = () => {
87 krbTicketPolicyData.setKrbTicket(krbTicketPolicyData.originalPwPolicy);
88 krbTicketPolicyData.refetch();
89 dispatch(
90 addAlert({
91 name: "revert-success",
92 title: "Password policy data reverted",
93 variant: "success",
94 })
95 );
96 };
97
98 // on Save handler method
99 const onSave = () => {
100 setIsDataLoading(true);
101 const modifiedValues = krbTicketPolicyData.modifiedValues();
102
103 // Generate payload
104 const payload = buildPayload(modifiedValues, [
105 "krbmaxrenewableage",
106 "krbmaxticketlife",
107 "krbauthindmaxrenewableage_radius",
108 "krbauthindmaxticketlife_radius",
109 "krbauthindmaxrenewableage_otp",
110 "krbauthindmaxticketlife_otp",
111 "krbauthindmaxrenewableage_pkinit",
112 "krbauthindmaxticketlife_pkinit",
113 "krbauthindmaxrenewableage_hardened",
114 "krbauthindmaxticketlife_hardened",
115 "krbauthindmaxticketlife_idp",
116 "krbauthindmaxticketlife_passkey",
117 "krbauthindmaxrenewableage_passkey",
118 "krbauthindmaxrenewableage_idp",
119 ]);
120
121 saveKrbTicketPolicy(payload).then((response) => {
122 if ("data" in response) {
123 const data = response.data;
124 if (data?.error) {
125 dispatch(
126 addAlert({
127 name: "error",
128 title: (data.error as Error).message,
129 variant: "danger",
130 })
131 );
132 }
133 if (data?.result) {
134 krbTicketPolicyData.setKrbTicket(data.result.result);
135 dispatch(
136 addAlert({
137 name: "success",
138 title: "Kerberos ticket policy updated",
139 variant: "success",
140 })
141 );
142 // Reset values. Disable 'revert' and 'save' buttons
143 krbTicketPolicyData.resetValues();
144 }
145 }
146 setIsDataLoading(false);
147 });
148 };
149
150 // Toolbar
151 const toolbarFields = [
152 {
153 key: 0,
154 element: (
155 <SecondaryButton
156 dataCy="krb-ticket-policy-button-refresh"
157 onClickHandler={krbTicketPolicyData.refetch}
158 >
159 Refresh
160 </SecondaryButton>
161 ),
162 },
163 {
164 key: 1,
165 element: (
166 <SecondaryButton
167 dataCy="krb-ticket-policy-button-revert"
168 isDisabled={!krbTicketPolicyData.modified || isDataLoading}
169 onClickHandler={onRevert}
170 >
171 Revert
172 </SecondaryButton>
173 ),
174 },
175 {
176 key: 2,
177 element: (
178 <SecondaryButton
179 dataCy="krb-ticket-policy-button-save"
180 isDisabled={!krbTicketPolicyData.modified || isDataLoading}
181 onClickHandler={onSave}
182 >
183 Save
184 </SecondaryButton>
185 ),
186 },
187 ];
188
189 // Handling of the API data
190 if (krbTicketPolicyData.isLoading || !krbTicketPolicyData.krbTicket) {
191 return <DataSpinner />;
192 }
193
194 // Show the 'NotFound' page if the host is not found
195 if (
196 !krbTicketPolicyData.isLoading &&
197 Object.keys(krbTicketPolicyData.krbTicket).length === 0
198 ) {
199 return <NotFound />;
200 }
201
202 // Return component
203 return (
204 <PageWithGrayBorderLayout
205 id="krb-ticket-policy-page"
206 pageTitle="Kerberos ticket policy"
207 toolbarItems={toolbarFields}
208 >
209 <>
210 <Sidebar isPanelRight className="pf-v6-u-mb-0">
211 <SidebarPanel variant="sticky">
212 <HelpTextWithIconLayout
213 textContent="Help"
214 icon={
215 <OutlinedQuestionCircleIcon className="pf-v6-u-primary-color-100 pf-v6-u-mr-sm" />
216 }
217 />
218 <JumpLinks
219 isVertical
220 label="Jump to section"
221 scrollableSelector="#krb-ticket-policy-page"
222 offset={220} // for masthead
223 expandable={{ default: "expandable", md: "nonExpandable" }}
224 className="pf-v6-u-mt-md"
225 >
226 <JumpLinksItem key={0} href="#krb-ticket-policy">
227 Kerberos Ticket Policy
228 </JumpLinksItem>
229 <JumpLinksItem key={1} href="#authentication-indicators">
230 Authentication indicators
231 </JumpLinksItem>
232 </JumpLinks>
233 </SidebarPanel>
234 <SidebarContent className="pf-v6-u-mr-xl">
235 <TitleLayout
236 key={0}
237 headingLevel="h2"
238 id="krb-ticket-policy"
239 text="Kerberos Ticket Policy"
240 className="pf-v6-u-mt-0 pf-v6-u-ml-0 pf-v6-u-mb-md"
241 />
242 <Flex direction={{ default: "column", lg: "row" }}>
243 <FlexItem flex={{ default: "flex_1" }}>
244 <Form className="pf-v6-u-mb-lg">
245 <FormGroup
246 label="Max renew (seconds)"
247 fieldId="krbmaxrenewableage"
248 >
249 <IpaTextInput
250 dataCy="krb-ticket-policy-textbox-max-renew"
251 name={"krbmaxrenewableage"}
252 ariaLabel={"Max renew (seconds)"}
253 ipaObject={ipaObject}
254 onChange={recordOnChange}
255 objectName="krbtpolicy"
256 metadata={krbTicketPolicyData.metadata}
257 />
258 </FormGroup>
259 </Form>
260 </FlexItem>
261 <FlexItem flex={{ default: "flex_1" }}>
262 <Form className="pf-v6-u-mb-lg">
263 <FormGroup
264 label="Max life (seconds)"
265 fieldId="krbmaxticketlife"
266 >
267 <IpaTextInput
268 dataCy="krb-ticket-policy-textbox-max-life"
269 name={"krbmaxticketlife"}
270 ariaLabel={"Max life (seconds)"}
271 ipaObject={ipaObject}
272 onChange={recordOnChange}
273 objectName="krbtpolicy"
274 metadata={krbTicketPolicyData.metadata}
275 />
276 </FormGroup>
277 </Form>
278 </FlexItem>
279 </Flex>
280 <TitleLayout
281 key={1}
282 headingLevel="h2"
283 id="authentication-indicators"
284 text="Authentication indicators"
285 className="pf-v6-u-mt-lg pf-v6-u-mb-md"
286 />
287 <Flex direction={{ default: "column", lg: "row" }}>
288 <FlexItem flex={{ default: "flex_1" }}>
289 <Form className="pf-v6-u-mb-lg">
290 <FormGroup
291 label="RADIUS max renew (seconds)"
292 fieldId="krbauthindmaxrenewableage_radius"
293 >
294 <IpaTextInput
295 dataCy="krb-ticket-policy-textbox-radius-max-renew"
296 name={"krbauthindmaxrenewableage_radius"}
297 ariaLabel={"RADIUS max renew (seconds)"}
298 ipaObject={ipaObject}
299 onChange={recordOnChange}
300 objectName="krbtpolicy"
301 metadata={krbTicketPolicyData.metadata}
302 />
303 </FormGroup>
304 <FormGroup
305 label="RADIUS max life (seconds)"
306 fieldId="krbauthindmaxticketlife_radius"
307 >
308 <IpaTextInput
309 dataCy="krb-ticket-policy-textbox-radius-max-life"
310 name={"krbauthindmaxticketlife_radius"}
311 ariaLabel={"RADIUS max life (seconds)"}
312 ipaObject={ipaObject}
313 onChange={recordOnChange}
314 objectName="krbtpolicy"
315 metadata={krbTicketPolicyData.metadata}
316 />
317 </FormGroup>
318 <FormGroup
319 label="OTP max renew (seconds)"
320 fieldId="krbauthindmaxrenewableage_otp"
321 >
322 <IpaTextInput
323 dataCy="krb-ticket-policy-textbox-otp-max-renew"
324 name={"krbauthindmaxrenewableage_otp"}
325 ariaLabel={"OTP max renew (seconds)"}
326 ipaObject={ipaObject}
327 onChange={recordOnChange}
328 objectName="krbtpolicy"
329 metadata={krbTicketPolicyData.metadata}
330 />
331 </FormGroup>
332 <FormGroup
333 label="OTP max life (seconds)"
334 fieldId="krbauthindmaxticketlife_otp"
335 >
336 <IpaTextInput
337 dataCy="krb-ticket-policy-textbox-otp-max-life"
338 name={"krbauthindmaxticketlife_otp"}
339 ariaLabel={"OTP max life (seconds)"}
340 ipaObject={ipaObject}
341 onChange={recordOnChange}
342 objectName="krbtpolicy"
343 metadata={krbTicketPolicyData.metadata}
344 />
345 </FormGroup>
346 <FormGroup
347 label="PKINIT max renew (seconds)"
348 fieldId="krbauthindmaxrenewableage_pkinit"
349 >
350 <IpaTextInput
351 dataCy="krb-ticket-policy-textbox-pkinit-max-renew"
352 name={"krbauthindmaxrenewableage_pkinit"}
353 ariaLabel={"PKINIT max renew (seconds)"}
354 ipaObject={ipaObject}
355 onChange={recordOnChange}
356 objectName="krbtpolicy"
357 metadata={krbTicketPolicyData.metadata}
358 />
359 </FormGroup>
360 <FormGroup
361 label="PKINIT max life (seconds)"
362 fieldId="krbauthindmaxticketlife_pkinit"
363 >
364 <IpaTextInput
365 dataCy="krb-ticket-policy-textbox-pkinit-max-life"
366 name={"krbauthindmaxticketlife_pkinit"}
367 ariaLabel={"PKINIT max life (seconds)"}
368 ipaObject={ipaObject}
369 onChange={recordOnChange}
370 objectName="krbtpolicy"
371 metadata={krbTicketPolicyData.metadata}
372 />
373 </FormGroup>
374 </Form>
375 </FlexItem>
376 <FlexItem flex={{ default: "flex_1" }}>
377 <Form className="pf-v6-u-mb-lg">
378 <FormGroup
379 label="Hardened max renew (seconds)"
380 fieldId="krbauthindmaxrenewableage_hardened"
381 >
382 <IpaTextInput
383 dataCy="krb-ticket-policy-textbox-hardened-max-renew"
384 name={"krbauthindmaxrenewableage_hardened"}
385 ariaLabel={"Hardened max renew (seconds)"}
386 ipaObject={ipaObject}
387 onChange={recordOnChange}
388 objectName="krbtpolicy"
389 metadata={krbTicketPolicyData.metadata}
390 />
391 </FormGroup>
392 <FormGroup
393 label="Hardened max life (seconds)"
394 fieldId="krbauthindmaxticketlife_hardened"
395 >
396 <IpaTextInput
397 dataCy="krb-ticket-policy-textbox-hardened-max-life"
398 name={"krbauthindmaxticketlife_hardened"}
399 ariaLabel={"Hardened max life (seconds)"}
400 ipaObject={ipaObject}
401 onChange={recordOnChange}
402 objectName="krbtpolicy"
403 metadata={krbTicketPolicyData.metadata}
404 />
405 </FormGroup>
406 <FormGroup
407 label="IdP max renew (seconds)"
408 fieldId="krbauthindmaxrenewableage_idp"
409 >
410 <IpaTextInput
411 dataCy="krb-ticket-policy-textbox-idp-max-renew"
412 name={"krbauthindmaxrenewableage_idp"}
413 ariaLabel={"IdP max renew (seconds)"}
414 ipaObject={ipaObject}
415 onChange={recordOnChange}
416 objectName="krbtpolicy"
417 metadata={krbTicketPolicyData.metadata}
418 />
419 </FormGroup>
420 <FormGroup
421 label="IdP max life (seconds)"
422 fieldId="krbauthindmaxticketlife_idp"
423 >
424 <IpaTextInput
425 dataCy="krb-ticket-policy-textbox-idp-max-life"
426 name={"krbauthindmaxticketlife_idp"}
427 ariaLabel={"IdP max life (seconds)"}
428 ipaObject={ipaObject}
429 onChange={recordOnChange}
430 objectName="krbtpolicy"
431 metadata={krbTicketPolicyData.metadata}
432 />
433 </FormGroup>
434 <FormGroup
435 label="Passkey max renew (seconds)"
436 fieldId="krbauthindmaxrenewableage_passkey"
437 >
438 <IpaTextInput
439 dataCy="krb-ticket-policy-textbox-passkey-max-renew"
440 name={"krbauthindmaxrenewableage_passkey"}
441 ariaLabel={"Passkey max renew (seconds)"}
442 ipaObject={ipaObject}
443 onChange={recordOnChange}
444 objectName="krbtpolicy"
445 metadata={krbTicketPolicyData.metadata}
446 />
447 </FormGroup>
448 <FormGroup
449 label="Passkey max life (seconds)"
450 fieldId="krbauthindmaxticketlife_passkey"
451 >
452 <IpaTextInput
453 dataCy="krb-ticket-policy-textbox-passkey-max-life"
454 name={"krbauthindmaxticketlife_passkey"}
455 ariaLabel={"Passkey max life (seconds)"}
456 ipaObject={ipaObject}
457 onChange={recordOnChange}
458 objectName="krbtpolicy"
459 metadata={krbTicketPolicyData.metadata}
460 />
461 </FormGroup>
462 </Form>
463 </FlexItem>
464 </Flex>
465 </SidebarContent>
466 </Sidebar>
467 </>
468 </PageWithGrayBorderLayout>
469 );
470 };
471
472 export default KrbTicketPolicy;