2021-10-05 10:32:20 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import type { ClientForm } from "../ClientDetails";
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
|
|
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 = [
|
|
|
|
{ name: "EXCLUSIVE", value: "http://www.w3.org/2001/10/xml-exc-c14n#" },
|
|
|
|
{
|
|
|
|
name: "EXCLUSIVE_WITH_COMMENTS",
|
|
|
|
value: "http://www.w3.org/2001/10/xml-exc-c14n#WithComments",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "INCLUSIVE",
|
|
|
|
value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "INCLUSIVE_WITH_COMMENTS",
|
|
|
|
value: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments",
|
|
|
|
},
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
export const SamlSignature = () => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const [algOpen, setAlgOpen] = useState(false);
|
|
|
|
const [keyOpen, setKeyOpen] = useState(false);
|
|
|
|
const [canOpen, setCanOpen] = useState(false);
|
|
|
|
|
|
|
|
const { control, watch } = useFormContext<ClientForm>();
|
|
|
|
|
2021-12-08 15:08:42 +00:00
|
|
|
const signDocs = watch("attributes.saml.server.signature");
|
|
|
|
const signAssertion = watch("attributes.saml.assertion.signature");
|
2021-10-05 10:32:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-clients"
|
|
|
|
className="keycloak__capability-config__form"
|
|
|
|
>
|
2021-12-08 15:08:42 +00:00
|
|
|
<Toggle name="attributes.saml.server.signature" label="signDocuments" />
|
2021-10-05 10:32:20 +00:00
|
|
|
<Toggle
|
2021-12-08 15:08:42 +00:00
|
|
|
name="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
|
|
|
|
helpText="clients-help:signatureAlgorithm"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:signatureAlgorithm"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.signature.algorithm"
|
2021-10-05 10:32:20 +00:00
|
|
|
defaultValue={SIGNATURE_ALGORITHMS[0]}
|
|
|
|
Key
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="signatureAlgorithm"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setAlgOpen}
|
2021-10-05 10:32:20 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value.toString());
|
|
|
|
setAlgOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("signatureAlgorithm")}
|
|
|
|
isOpen={algOpen}
|
|
|
|
>
|
|
|
|
{SIGNATURE_ALGORITHMS.map((algorithm) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={algorithm === value}
|
|
|
|
key={algorithm}
|
|
|
|
value={algorithm}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("signatureKeyName")}
|
|
|
|
fieldId="signatureKeyName"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:signatureKeyName"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="clients:signatureKeyName"
|
2021-10-05 10:32:20 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
2021-12-08 15:08:42 +00:00
|
|
|
name="attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer"
|
2021-10-05 10:32:20 +00:00
|
|
|
defaultValue={KEYNAME_TRANSFORMER[0]}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="signatureKeyName"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setKeyOpen}
|
2021-10-05 10:32:20 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value.toString());
|
|
|
|
setKeyOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("signatureKeyName")}
|
|
|
|
isOpen={keyOpen}
|
|
|
|
>
|
|
|
|
{KEYNAME_TRANSFORMER.map((key) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={key === value}
|
|
|
|
key={key}
|
|
|
|
value={key}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("canonicalization")}
|
|
|
|
fieldId="canonicalization"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="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}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="canonicalization"
|
2021-11-30 13:07:44 +00:00
|
|
|
onToggle={setCanOpen}
|
2021-10-05 10:32:20 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value.toString());
|
|
|
|
setCanOpen(false);
|
|
|
|
}}
|
|
|
|
selections={
|
|
|
|
CANONICALIZATION.find((can) => can.value === value)?.name
|
|
|
|
}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("canonicalization")}
|
|
|
|
isOpen={canOpen}
|
|
|
|
>
|
|
|
|
{CANONICALIZATION.map((can) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={can.value === value}
|
|
|
|
key={can.name}
|
|
|
|
value={can.value}
|
|
|
|
>
|
|
|
|
{can.name}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|