| 1 |
import React from "react"; |
| 2 |
// PatternFly |
| 3 |
import { |
| 4 |
DropdownItem, |
| 5 |
Flex, |
| 6 |
FlexItem, |
| 7 |
Form, |
| 8 |
FormGroup, |
| 9 |
JumpLinks, |
| 10 |
JumpLinksItem, |
| 11 |
Sidebar, |
| 12 |
SidebarContent, |
| 13 |
SidebarPanel, |
| 14 |
} from "@patternfly/react-core"; |
| 15 |
// Data types |
| 16 |
import { IDPServer, Metadata } from "src/utils/datatypes/globalDataTypes"; |
| 17 |
// Redux |
| 18 |
import { useAppDispatch } from "src/store/hooks"; |
| 19 |
// Hooks |
| 20 |
import useUpdateRoute from "src/hooks/useUpdateRoute"; |
| 21 |
import { addAlert } from "src/store/Global/alerts-slice"; |
| 22 |
// Utils |
| 23 |
import { asRecord } from "src/utils/subIdUtils"; |
| 24 |
// Icons |
| 25 |
import { OutlinedQuestionCircleIcon } from "@patternfly/react-icons"; |
| 26 |
// RPC |
| 27 |
import { IdpModPayload, useIdpModMutation } from "src/services/rpcIdp"; |
| 28 |
// Components |
| 29 |
import IpaTextInput from "src/components/Form/IpaTextInput/IpaTextInput"; |
| 30 |
import TabLayout from "src/components/layouts/TabLayout"; |
| 31 |
import SecondaryButton from "src/components/layouts/SecondaryButton"; |
| 32 |
import HelpTextWithIconLayout from "src/components/layouts/HelpTextWithIconLayout"; |
| 33 |
import IpaTextContent from "src/components/Form/IpaTextContent/IpaTextContent"; |
| 34 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 35 |
import IpaPasswordInput from "src/components/Form/IpaPasswordInput"; |
| 36 |
import KebabLayout from "src/components/layouts/KebabLayout"; |
| 37 |
import ResetIdpPassword from "src/components/ResetIdpPassword"; |
| 38 |
|
| 39 |
interface PropsToIdpRefSettings { |
| 40 |
idpRef: Partial<IDPServer>; |
| 41 |
originalIdpRef: Partial<IDPServer>; |
| 42 |
metadata: Metadata; |
| 43 |
onIdpRefChange: (idpRef: Partial<IDPServer>) => void; |
| 44 |
onRefresh: () => void; |
| 45 |
isModified: boolean; |
| 46 |
isDataLoading?: boolean; |
| 47 |
modifiedValues: () => Partial<IDPServer>; |
| 48 |
onResetValues: () => void; |
| 49 |
pathname: string; |
| 50 |
} |
| 51 |
|
| 52 |
const IdpRefSettings = (props: PropsToIdpRefSettings) => { |
| 53 |
const dispatch = useAppDispatch(); |
| 54 |
|
| 55 |
// Update current route data to Redux and highlight the current page in the Nav bar |
| 56 |
useUpdateRoute({ pathname: props.pathname }); |
| 57 |
|
| 58 |
// States |
| 59 |
const [isDataLoading, setIsDataLoading] = React.useState(false); |
| 60 |
|
| 61 |
// Get 'ipaObject' and 'recordOnChange' to use in 'IpaTextInput' |
| 62 |
const { ipaObject, recordOnChange } = asRecord( |
| 63 |
props.idpRef, |
| 64 |
props.onIdpRefChange |
| 65 |
); |
| 66 |
|
| 67 |
// API calls |
| 68 |
const [saveIdpRef] = useIdpModMutation(); |
| 69 |
|
| 70 |
// 'Revert' handler method |
| 71 |
const onRevert = () => { |
| 72 |
props.onIdpRefChange(props.originalIdpRef); |
| 73 |
props.onRefresh(); |
| 74 |
dispatch( |
| 75 |
addAlert({ |
| 76 |
name: "revert-success", |
| 77 |
title: "Identity Provider data reverted", |
| 78 |
variant: "success", |
| 79 |
}) |
| 80 |
); |
| 81 |
}; |
| 82 |
|
| 83 |
// Helper method to build the payload based on values |
| 84 |
const buildPayload = ( |
| 85 |
modifiedValues: Partial<IDPServer>, |
| 86 |
keyArray: string[] |
| 87 |
): IdpModPayload => { |
| 88 |
const payload: IdpModPayload = { |
| 89 |
idpId: props.idpRef.cn?.toString() as string, |
| 90 |
}; |
| 91 |
|
| 92 |
keyArray.forEach((key) => { |
| 93 |
// Modified values are either the value (in string) or an array ([]) when set to empty string |
| 94 |
if (modifiedValues[key] !== undefined) { |
| 95 |
if (modifiedValues[key] === "") { |
| 96 |
payload[key] = []; |
| 97 |
} else { |
| 98 |
payload[key] = modifiedValues[key].toString(); |
| 99 |
} |
| 100 |
} |
| 101 |
}); |
| 102 |
return payload; |
| 103 |
}; |
| 104 |
|
| 105 |
// on Save handler method |
| 106 |
const onSave = () => { |
| 107 |
setIsDataLoading(true); |
| 108 |
const modifiedValues = props.modifiedValues(); |
| 109 |
|
| 110 |
// Generate payload |
| 111 |
const payload = buildPayload(modifiedValues, [ |
| 112 |
"ipaidpclientid", |
| 113 |
"ipaidpclientsecret", |
| 114 |
"ipaidpscope", |
| 115 |
"ipaidpsub", |
| 116 |
"ipaidpauthendpoint", |
| 117 |
"ipaidpdevauthendpoint", |
| 118 |
"ipaidptokenendpoint", |
| 119 |
"ipaidpuserinfoendpoint", |
| 120 |
"ipaidpkeysendpoint", |
| 121 |
"ipaidpissuerurl", |
| 122 |
]); |
| 123 |
|
| 124 |
saveIdpRef(payload).then((response) => { |
| 125 |
if ("data" in response) { |
| 126 |
const data = response.data; |
| 127 |
if (data?.error) { |
| 128 |
dispatch( |
| 129 |
addAlert({ |
| 130 |
name: "error", |
| 131 |
title: (data.error as Error).message, |
| 132 |
variant: "danger", |
| 133 |
}) |
| 134 |
); |
| 135 |
} |
| 136 |
if (data?.result) { |
| 137 |
props.onIdpRefChange(data.result.result); |
| 138 |
dispatch( |
| 139 |
addAlert({ |
| 140 |
name: "success", |
| 141 |
title: "Identity Provider '" + props.idpRef.cn + "' updated", |
| 142 |
variant: "success", |
| 143 |
}) |
| 144 |
); |
| 145 |
// Reset values. Disable 'revert' and 'save' buttons |
| 146 |
props.onResetValues(); |
| 147 |
} |
| 148 |
} |
| 149 |
setIsDataLoading(false); |
| 150 |
}); |
| 151 |
}; |
| 152 |
|
| 153 |
// 'Reset password' option |
| 154 |
const [isResetPasswordModalOpen, setIsResetPasswordModalOpen] = |
| 155 |
React.useState(false); |
| 156 |
|
| 157 |
// Kebab |
| 158 |
const [isKebabOpen, setIsKebabOpen] = React.useState(false); |
| 159 |
|
| 160 |
const kebabItems = [ |
| 161 |
<DropdownItem |
| 162 |
data-cy="idp-references-tab-settings-kebab-reset-password" |
| 163 |
key="reset password" |
| 164 |
onClick={() => setIsResetPasswordModalOpen(true)} |
| 165 |
> |
| 166 |
Reset password |
| 167 |
</DropdownItem>, |
| 168 |
]; |
| 169 |
|
| 170 |
// Toolbar |
| 171 |
const toolbarFields = [ |
| 172 |
{ |
| 173 |
key: 0, |
| 174 |
element: ( |
| 175 |
<SecondaryButton |
| 176 |
dataCy="idp-references-tab-settings-button-refresh" |
| 177 |
onClickHandler={props.onRefresh} |
| 178 |
> |
| 179 |
Refresh |
| 180 |
</SecondaryButton> |
| 181 |
), |
| 182 |
}, |
| 183 |
{ |
| 184 |
key: 1, |
| 185 |
element: ( |
| 186 |
<SecondaryButton |
| 187 |
dataCy="idp-references-tab-settings-button-revert" |
| 188 |
isDisabled={!props.isModified || isDataLoading} |
| 189 |
onClickHandler={onRevert} |
| 190 |
> |
| 191 |
Revert |
| 192 |
</SecondaryButton> |
| 193 |
), |
| 194 |
}, |
| 195 |
{ |
| 196 |
key: 2, |
| 197 |
element: ( |
| 198 |
<SecondaryButton |
| 199 |
dataCy="idp-references-tab-settings-button-save" |
| 200 |
isDisabled={!props.isModified || isDataLoading} |
| 201 |
onClickHandler={onSave} |
| 202 |
> |
| 203 |
Save |
| 204 |
</SecondaryButton> |
| 205 |
), |
| 206 |
}, |
| 207 |
{ |
| 208 |
key: 3, |
| 209 |
element: ( |
| 210 |
<KebabLayout |
| 211 |
dataCy="idp-references-tab-settings-kebab" |
| 212 |
direction={"up"} |
| 213 |
onDropdownSelect={() => setIsKebabOpen(!isKebabOpen)} |
| 214 |
onKebabToggle={() => setIsKebabOpen(!isKebabOpen)} |
| 215 |
idKebab="toggle-action-buttons" |
| 216 |
isKebabOpen={isKebabOpen} |
| 217 |
dropdownItems={kebabItems} |
| 218 |
isDisabled={isDataLoading} |
| 219 |
/> |
| 220 |
), |
| 221 |
}, |
| 222 |
]; |
| 223 |
|
| 224 |
// Render component |
| 225 |
return ( |
| 226 |
<> |
| 227 |
<TabLayout id="settings-page" toolbarItems={toolbarFields}> |
| 228 |
<Sidebar isPanelRight> |
| 229 |
<SidebarPanel variant="sticky"> |
| 230 |
<HelpTextWithIconLayout |
| 231 |
textContent="Help" |
| 232 |
icon={ |
| 233 |
<OutlinedQuestionCircleIcon className="pf-v6-u-primary-color-100 pf-v6-u-mr-sm" /> |
| 234 |
} |
| 235 |
/> |
| 236 |
<JumpLinks |
| 237 |
isVertical |
| 238 |
label="Jump to section" |
| 239 |
scrollableSelector="#idp-reference-page" |
| 240 |
offset={220} // for masthead |
| 241 |
expandable={{ default: "expandable", md: "nonExpandable" }} |
| 242 |
className="pf-v6-u-mt-md" |
| 243 |
> |
| 244 |
<JumpLinksItem key={0} href="#oauth-client-settings"> |
| 245 |
OAuth 2.0 client details |
| 246 |
</JumpLinksItem> |
| 247 |
<JumpLinksItem key={1} href="#idp-details"> |
| 248 |
Identity provider details |
| 249 |
</JumpLinksItem> |
| 250 |
</JumpLinks> |
| 251 |
</SidebarPanel> |
| 252 |
<SidebarContent className="pf-v6-u-mr-xl"> |
| 253 |
<TitleLayout |
| 254 |
key={0} |
| 255 |
id="oauth-client-settings" |
| 256 |
text="OAuth 2.0 client details" |
| 257 |
headingLevel="h2" |
| 258 |
className="pf-v6-u-mt-lg pf-v6-u-mb-md" |
| 259 |
/> |
| 260 |
<Flex direction={{ default: "column", lg: "row" }}> |
| 261 |
<FlexItem flex={{ default: "flex_1" }}> |
| 262 |
<Form className="pf-v6-u-mb-lg"> |
| 263 |
<FormGroup |
| 264 |
label="Identity Provider reference name" |
| 265 |
role="group" |
| 266 |
> |
| 267 |
<IpaTextContent |
| 268 |
dataCy="idp-references-tab-settings-textbox-cn" |
| 269 |
name={"cn"} |
| 270 |
ariaLabel={"Identity Provider reference name"} |
| 271 |
ipaObject={ipaObject} |
| 272 |
objectName="idp" |
| 273 |
metadata={props.metadata} |
| 274 |
/> |
| 275 |
</FormGroup> |
| 276 |
<FormGroup |
| 277 |
label="Client identifier" |
| 278 |
fieldId="ipaidpclientid" |
| 279 |
isRequired |
| 280 |
> |
| 281 |
<IpaTextInput |
| 282 |
dataCy="idp-references-tab-settings-textbox-ipaidpclientid" |
| 283 |
name={"ipaidpclientid"} |
| 284 |
ariaLabel={"Client identifier"} |
| 285 |
ipaObject={ipaObject} |
| 286 |
onChange={recordOnChange} |
| 287 |
objectName="idp" |
| 288 |
metadata={props.metadata} |
| 289 |
/> |
| 290 |
</FormGroup> |
| 291 |
<FormGroup label="Secret" fieldId="ipaidpclientsecret"> |
| 292 |
<IpaPasswordInput |
| 293 |
dataCy="idp-references-tab-settings-textbox-ipaidpclientsecret" |
| 294 |
name={"ipaidpclientsecret"} |
| 295 |
ariaLabel={"Secret"} |
| 296 |
ipaObject={ipaObject} |
| 297 |
onChange={recordOnChange} |
| 298 |
objectName="idp" |
| 299 |
metadata={props.metadata} |
| 300 |
/> |
| 301 |
</FormGroup> |
| 302 |
</Form> |
| 303 |
</FlexItem> |
| 304 |
</Flex> |
| 305 |
<TitleLayout |
| 306 |
key={1} |
| 307 |
headingLevel="h2" |
| 308 |
id="idp-details" |
| 309 |
text="Identity provider details" |
| 310 |
className="pf-v6-u-mt-lg pf-v6-u-mb-md" |
| 311 |
/> |
| 312 |
<Flex direction={{ default: "column", lg: "row" }}> |
| 313 |
<FlexItem flex={{ default: "flex_1" }}> |
| 314 |
<Form className="pf-v6-u-mb-lg"> |
| 315 |
<FormGroup label="Scope" fieldId="ipaidpscope"> |
| 316 |
<IpaTextInput |
| 317 |
dataCy="idp-references-tab-settings-textbox-ipaidpscope" |
| 318 |
name={"ipaidpscope"} |
| 319 |
ariaLabel={"Scope"} |
| 320 |
ipaObject={ipaObject} |
| 321 |
onChange={recordOnChange} |
| 322 |
objectName="idp" |
| 323 |
metadata={props.metadata} |
| 324 |
/> |
| 325 |
</FormGroup> |
| 326 |
<FormGroup |
| 327 |
label="External IdP user identifier attribute" |
| 328 |
fieldId="ipaidpsub" |
| 329 |
> |
| 330 |
<IpaTextInput |
| 331 |
dataCy="idp-references-tab-settings-textbox-ipaidpsub" |
| 332 |
name={"ipaidpsub"} |
| 333 |
ariaLabel={"External IdP user identifier attribute"} |
| 334 |
ipaObject={ipaObject} |
| 335 |
onChange={recordOnChange} |
| 336 |
objectName="idp" |
| 337 |
metadata={props.metadata} |
| 338 |
/> |
| 339 |
</FormGroup> |
| 340 |
<FormGroup |
| 341 |
label="Authorization URI" |
| 342 |
fieldId="ipaidpauthendpoint" |
| 343 |
> |
| 344 |
<IpaTextInput |
| 345 |
dataCy="idp-references-tab-settings-textbox-ipaidpauthendpoint" |
| 346 |
name={"ipaidpauthendpoint"} |
| 347 |
ariaLabel={"Authorization URI"} |
| 348 |
ipaObject={ipaObject} |
| 349 |
onChange={recordOnChange} |
| 350 |
objectName="idp" |
| 351 |
metadata={props.metadata} |
| 352 |
/> |
| 353 |
</FormGroup> |
| 354 |
<FormGroup |
| 355 |
label="Device authorization URI" |
| 356 |
fieldId="ipaidpdevauthendpoint" |
| 357 |
> |
| 358 |
<IpaTextInput |
| 359 |
dataCy="idp-references-tab-settings-textbox-ipaidpdevauthendpoint" |
| 360 |
name={"ipaidpdevauthendpoint"} |
| 361 |
ariaLabel={"Device authorization URI"} |
| 362 |
ipaObject={ipaObject} |
| 363 |
onChange={recordOnChange} |
| 364 |
objectName="idp" |
| 365 |
metadata={props.metadata} |
| 366 |
/> |
| 367 |
</FormGroup> |
| 368 |
<FormGroup label="Token URI" fieldId="ipaidptokenendpoint"> |
| 369 |
<IpaTextInput |
| 370 |
dataCy="idp-references-tab-settings-textbox-ipaidptokenendpoint" |
| 371 |
name={"ipaidptokenendpoint"} |
| 372 |
ariaLabel={"Token URI"} |
| 373 |
ipaObject={ipaObject} |
| 374 |
onChange={recordOnChange} |
| 375 |
objectName="idp" |
| 376 |
metadata={props.metadata} |
| 377 |
/> |
| 378 |
</FormGroup> |
| 379 |
<FormGroup |
| 380 |
label="User info URI" |
| 381 |
fieldId="ipaidpuserinfoendpoint" |
| 382 |
> |
| 383 |
<IpaTextInput |
| 384 |
dataCy="idp-references-tab-settings-textbox-ipaidpuserinfoendpoint" |
| 385 |
name={"ipaidpuserinfoendpoint"} |
| 386 |
ariaLabel={"User info URI"} |
| 387 |
ipaObject={ipaObject} |
| 388 |
onChange={recordOnChange} |
| 389 |
objectName="idp" |
| 390 |
metadata={props.metadata} |
| 391 |
/> |
| 392 |
</FormGroup> |
| 393 |
<FormGroup label="JWKS URI" fieldId="ipaidpkeysendpoint"> |
| 394 |
<IpaTextInput |
| 395 |
dataCy="idp-references-tab-settings-textbox-ipaidpkeysendpoint" |
| 396 |
name={"ipaidpkeysendpoint"} |
| 397 |
ariaLabel={"JWKS URI"} |
| 398 |
ipaObject={ipaObject} |
| 399 |
onChange={recordOnChange} |
| 400 |
objectName="idp" |
| 401 |
metadata={props.metadata} |
| 402 |
/> |
| 403 |
</FormGroup> |
| 404 |
<FormGroup label="OIDC URL" fieldId="ipaidpissuerurl"> |
| 405 |
<IpaTextInput |
| 406 |
dataCy="idp-references-tab-settings-textbox-ipaidpissuerurl" |
| 407 |
name={"ipaidpissuerurl"} |
| 408 |
ariaLabel={"OIDC URL"} |
| 409 |
ipaObject={ipaObject} |
| 410 |
onChange={recordOnChange} |
| 411 |
objectName="idp" |
| 412 |
metadata={props.metadata} |
| 413 |
/> |
| 414 |
</FormGroup> |
| 415 |
</Form> |
| 416 |
</FlexItem> |
| 417 |
</Flex> |
| 418 |
</SidebarContent> |
| 419 |
</Sidebar> |
| 420 |
<ResetIdpPassword |
| 421 |
idpId={props.idpRef.cn as string} |
| 422 |
isOpen={isResetPasswordModalOpen} |
| 423 |
onClose={() => setIsResetPasswordModalOpen(false)} |
| 424 |
onIdpRefChange={props.onIdpRefChange} |
| 425 |
onRefresh={props.onRefresh} |
| 426 |
/> |
| 427 |
</TabLayout> |
| 428 |
</> |
| 429 |
); |
| 430 |
}; |
| 431 |
|
| 432 |
export default IdpRefSettings; |