2021-10-05 10:32:20 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
} 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, 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
|
|
|
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2023-03-07 09:29:40 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { convertAttributeNameToForm } from "../../util";
|
|
|
|
import { FormFields } from "../ClientDetails";
|
2021-10-05 10:32:20 +00:00
|
|
|
import { Toggle } from "./SamlConfig";
|
|
|
|
|
|
|
|
const SIGNATURE_ALGORITHMS = [
|
|
|
|
"RSA_SHA1",
|
|
|
|
"RSA_SHA256",
|
|
|
|
"RSA_SHA256_MGF1",
|
|
|
|
"RSA_SHA512",
|
|
|
|
"RSA_SHA512_MGF1",
|
|
|
|
"DSA_SHA1",
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
const KEYNAME_TRANSFORMER = ["NONE", "KEY_ID", "CERT_SUBJECT"] as const;
|
|
|
|
|
|
|
|
const CANONICALIZATION = [
|
2022-05-19 13:44:08 +00:00
|
|
|
{ name: "EXCLUSIVE", value: "http://www.w3.org/2001/10/xml-exc-c14n#" },
|
2021-10-05 10:32:20 +00:00
|
|
|
{
|
|
|
|
name: "EXCLUSIVE_WITH_COMMENTS",
|
2022-05-19 13:44:08 +00:00
|
|
|
value: "http://www.w3.org/2001/10/xml-exc-c14n#WithComments",
|
2021-10-05 10:32:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "INCLUSIVE",
|
2022-05-19 13:44:08 +00:00
|
|
|
value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
|
2021-10-05 10:32:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "INCLUSIVE_WITH_COMMENTS",
|
2022-05-19 13:44:08 +00:00
|
|
|
value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments",
|
2021-10-05 10:32:20 +00:00
|
|
|
},
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
export const SamlSignature = () => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const [algOpen, setAlgOpen] = useState(false);
|
|
|
|
const [keyOpen, setKeyOpen] = useState(false);
|
|
|
|
const [canOpen, setCanOpen] = useState(false);
|
|
|
|
|
2022-12-02 14:54:30 +00:00
|
|
|
const { control, watch } = useFormContext<FormFields>();
|
2021-10-05 10:32:20 +00:00
|
|
|
|
2022-09-29 11:07:02 +00:00
|
|
|
const signDocs = watch(
|
2022-12-02 14:54:30 +00:00
|
|
|
convertAttributeNameToForm<FormFields>("attributes.saml.server.signature")
|
2022-09-29 11:07:02 +00:00
|
|
|
);
|
|
|
|
const signAssertion = watch(
|
2022-12-02 14:54:30 +00:00
|
|
|
convertAttributeNameToForm<FormFields>(
|
|
|
|
"attributes.saml.assertion.signature"
|
|
|
|
)
|
2022-09-29 11:07:02 +00:00
|
|
|
);
|
2021-10-05 10:32:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-clients"
|
|
|
|
className="keycloak__capability-config__form"
|
|
|
|
>
|
|
|
|
<Toggle
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.saml.server.signature")}
|
|
|
|
label="signDocuments"
|
|
|
|
/>
|
|
|
|
<Toggle
|
|
|
|
name={convertAttributeNameToForm("attributes.saml.assertion.signature")}
|
2021-10-05 10:32:20 +00:00
|
|
|
label="signAssertions"
|
|
|
|
/>
|
|
|
|
{(signDocs === "true" || signAssertion === "true") && (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
label={t("signatureAlgorithm")}
|
|
|
|
fieldId="signatureAlgorithm"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("clients-help:signatureAlgorithm")}
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:signatureAlgorithm"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
2022-12-02 14:54:30 +00:00
|
|
|
name={convertAttributeNameToForm<FormFields>(
|
2022-08-09 08:32:16 +00:00
|
|
|
"attributes.saml.signature.algorithm"
|
|
|
|
)}
|
2021-10-05 10:32:20 +00:00
|
|
|
defaultValue={SIGNATURE_ALGORITHMS[0]}
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2021-10-05 10:32:20 +00:00
|
|
|
<Select
|
|
|
|
toggleId="signatureAlgorithm"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setAlgOpen}
|
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
|
|
|
setAlgOpen(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("signatureAlgorithm")}
|
|
|
|
isOpen={algOpen}
|
|
|
|
>
|
|
|
|
{SIGNATURE_ALGORITHMS.map((algorithm) => (
|
|
|
|
<SelectOption
|
2022-12-02 14:54:30 +00:00
|
|
|
selected={algorithm === field.value}
|
2021-10-05 10:32:20 +00:00
|
|
|
key={algorithm}
|
|
|
|
value={algorithm}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("signatureKeyName")}
|
|
|
|
fieldId="signatureKeyName"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("clients-help:signatureKeyName")}
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:signatureKeyName"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
2022-12-02 14:54:30 +00:00
|
|
|
name={convertAttributeNameToForm<FormFields>(
|
|
|
|
"attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer"
|
2022-08-09 08:32:16 +00:00
|
|
|
)}
|
2021-10-05 10:32:20 +00:00
|
|
|
defaultValue={KEYNAME_TRANSFORMER[0]}
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2021-10-05 10:32:20 +00:00
|
|
|
<Select
|
|
|
|
toggleId="signatureKeyName"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setKeyOpen}
|
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
|
|
|
setKeyOpen(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("signatureKeyName")}
|
|
|
|
isOpen={keyOpen}
|
|
|
|
>
|
|
|
|
{KEYNAME_TRANSFORMER.map((key) => (
|
|
|
|
<SelectOption
|
2022-12-02 14:54:30 +00:00
|
|
|
selected={key === field.value}
|
2021-10-05 10:32:20 +00:00
|
|
|
key={key}
|
|
|
|
value={key}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("canonicalization")}
|
|
|
|
fieldId="canonicalization"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("clients-help:canonicalization")}
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:canonicalization"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.saml_signature_canonicalization_method"
|
|
|
|
defaultValue={CANONICALIZATION[0].value}
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2021-10-05 10:32:20 +00:00
|
|
|
<Select
|
|
|
|
toggleId="canonicalization"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setCanOpen}
|
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
|
|
|
setCanOpen(false);
|
|
|
|
}}
|
|
|
|
selections={
|
2022-12-02 14:54:30 +00:00
|
|
|
CANONICALIZATION.find((can) => can.value === field.value)
|
|
|
|
?.name
|
2021-10-05 10:32:20 +00:00
|
|
|
}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("canonicalization")}
|
|
|
|
isOpen={canOpen}
|
|
|
|
>
|
|
|
|
{CANONICALIZATION.map((can) => (
|
|
|
|
<SelectOption
|
2022-12-02 14:54:30 +00:00
|
|
|
selected={can.value === field.value}
|
2021-10-05 10:32:20 +00:00
|
|
|
key={can.name}
|
|
|
|
value={can.value}
|
|
|
|
>
|
|
|
|
{can.name}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|