2021-10-05 10:32:20 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { useState } from "react";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, Path, PathValue, useFormContext } from "react-hook-form";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-10-05 10:32:20 +00:00
|
|
|
|
2023-05-24 12:11:06 +00:00
|
|
|
import { FormAccess } from "../../components/form/FormAccess";
|
2023-03-07 09:29:40 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2022-08-09 08:32:16 +00:00
|
|
|
import { convertAttributeNameToForm } from "../../util";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { FormFields } from "../ClientDetails";
|
2021-10-05 10:32:20 +00:00
|
|
|
|
2022-12-02 14:54:30 +00:00
|
|
|
type ToggleProps = {
|
|
|
|
name: PathValue<FormFields, Path<FormFields>>;
|
|
|
|
label: string;
|
|
|
|
};
|
|
|
|
export const Toggle = ({ name, label }: ToggleProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2022-12-02 14:54:30 +00:00
|
|
|
const { control } = useFormContext<FormFields>();
|
2021-10-05 10:32:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t(label)}
|
|
|
|
fieldId={label}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={t(`clients-help:${label}`)}
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId={`clients:${label}`}
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name={name}
|
|
|
|
defaultValue="false"
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2021-10-05 10:32:20 +00:00
|
|
|
<Switch
|
|
|
|
id={name!}
|
|
|
|
data-testid={label}
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value === "true"}
|
|
|
|
onChange={(value) => field.onChange(value.toString())}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t(label)}
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SamlConfig = () => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2022-12-02 14:54:30 +00:00
|
|
|
const { control } = useFormContext<FormFields>();
|
2021-10-05 10:32:20 +00:00
|
|
|
|
|
|
|
const [nameFormatOpen, setNameFormatOpen] = useState(false);
|
|
|
|
return (
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-clients"
|
|
|
|
className="keycloak__capability-config__form"
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("nameIdFormat")}
|
|
|
|
fieldId="nameIdFormat"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("nameIdFormatHelp")}
|
2023-09-13 14:05:17 +00:00
|
|
|
fieldLabelId="nameIdFormat"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.saml_name_id_format"
|
|
|
|
defaultValue="username"
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2021-10-05 10:32:20 +00:00
|
|
|
<Select
|
|
|
|
toggleId="samlNameIdFormat"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setNameFormatOpen}
|
2021-10-05 10:32:20 +00:00
|
|
|
onSelect={(_, value) => {
|
2022-12-02 14:54:30 +00:00
|
|
|
field.onChange(value.toString());
|
2021-10-05 10:32:20 +00:00
|
|
|
setNameFormatOpen(false);
|
|
|
|
}}
|
2022-12-02 14:54:30 +00:00
|
|
|
selections={field.value}
|
2021-10-05 10:32:20 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("nameIdFormat")}
|
|
|
|
isOpen={nameFormatOpen}
|
|
|
|
>
|
|
|
|
{["username", "email", "transient", "persistent"].map((name) => (
|
|
|
|
<SelectOption
|
2022-12-02 14:54:30 +00:00
|
|
|
selected={name === field.value}
|
2021-10-05 10:32:20 +00:00
|
|
|
key={name}
|
|
|
|
value={name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<Toggle
|
2023-03-02 13:15:18 +00:00
|
|
|
name="attributes.saml_force_name_id_format"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forceNameIdFormat"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.saml.force.post.binding")}
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forcePostBinding"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.saml.artifact.binding")}
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forceArtifactBinding"
|
|
|
|
/>
|
2022-03-02 21:38:52 +00:00
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.saml.authnstatement")}
|
2022-03-02 21:38:52 +00:00
|
|
|
label="includeAuthnStatement"
|
|
|
|
/>
|
2021-10-05 10:32:20 +00:00
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
2023-07-11 14:03:21 +00:00
|
|
|
"attributes.saml.onetimeuse.condition",
|
2022-08-09 08:32:16 +00:00
|
|
|
)}
|
2021-10-05 10:32:20 +00:00
|
|
|
label="includeOneTimeUseCondition"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
2023-07-11 14:03:21 +00:00
|
|
|
"attributes.saml.server.signature.keyinfo.ext",
|
2022-08-09 08:32:16 +00:00
|
|
|
)}
|
2021-10-05 10:32:20 +00:00
|
|
|
label="optimizeLookup"
|
|
|
|
/>
|
2023-06-12 10:46:03 +00:00
|
|
|
<Toggle
|
|
|
|
name={convertAttributeNameToForm("attributes.saml.allow.ecp.flow")}
|
|
|
|
label="allowEcpFlow"
|
|
|
|
/>
|
2021-10-05 10:32:20 +00:00
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|