2021-10-05 10:32:20 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import type { ClientForm } from "../ClientDetails";
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
|
|
|
|
|
|
export const Toggle = ({ name, label }: { name: string; label: string }) => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const { control } = useFormContext<ClientForm>();
|
|
|
|
|
|
|
|
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}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id={name!}
|
|
|
|
data-testid={label}
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange(value.toString())}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SamlConfig = () => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const { control } = useFormContext<ClientForm>();
|
|
|
|
|
|
|
|
const [nameFormatOpen, setNameFormatOpen] = useState(false);
|
|
|
|
return (
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-clients"
|
|
|
|
className="keycloak__capability-config__form"
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("nameIdFormat")}
|
|
|
|
fieldId="nameIdFormat"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:nameIdFormat"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:nameIdFormat"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.saml_name_id_format"
|
|
|
|
defaultValue="username"
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="samlNameIdFormat"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setNameFormatOpen}
|
2021-10-05 10:32:20 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value.toString());
|
|
|
|
setNameFormatOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("nameIdFormat")}
|
|
|
|
isOpen={nameFormatOpen}
|
|
|
|
>
|
|
|
|
{["username", "email", "transient", "persistent"].map((name) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={name === value}
|
|
|
|
key={name}
|
|
|
|
value={name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.force.name.id.format"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forceNameIdFormat"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.force.post.binding"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forcePostBinding"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.artifact.binding"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="forceArtifactBinding"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.onetimeuse.condition"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="includeOneTimeUseCondition"
|
|
|
|
/>
|
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.server.signature.keyinfo.ext"
|
2021-10-05 10:32:20 +00:00
|
|
|
label="optimizeLookup"
|
|
|
|
/>
|
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|