2020-09-17 13:51:40 +00:00
|
|
|
import React from "react";
|
2020-09-22 12:43:51 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-04-26 11:48:09 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
2020-08-31 18:26:25 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Switch,
|
|
|
|
Checkbox,
|
|
|
|
Grid,
|
|
|
|
GridItem,
|
2021-03-19 07:49:33 +00:00
|
|
|
InputGroup,
|
2020-08-31 18:26:25 +00:00
|
|
|
} from "@patternfly/react-core";
|
2021-04-26 11:48:09 +00:00
|
|
|
|
2020-10-28 18:17:15 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { ClientForm } from "../ClientDetails";
|
2021-03-09 13:59:41 +00:00
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
|
|
|
2021-04-26 11:48:09 +00:00
|
|
|
import "./capability-config.css";
|
|
|
|
|
2021-03-09 13:59:41 +00:00
|
|
|
type CapabilityConfigProps = {
|
|
|
|
unWrap?: boolean;
|
|
|
|
protocol?: string;
|
|
|
|
};
|
2020-10-28 18:17:15 +00:00
|
|
|
|
2021-03-09 13:59:41 +00:00
|
|
|
export const CapabilityConfig = ({
|
|
|
|
unWrap,
|
|
|
|
protocol: type,
|
|
|
|
}: CapabilityConfigProps) => {
|
2020-09-17 13:51:40 +00:00
|
|
|
const { t } = useTranslation("clients");
|
2021-03-19 07:49:33 +00:00
|
|
|
const { control, watch, setValue } = useFormContext<ClientForm>();
|
2021-03-09 13:59:41 +00:00
|
|
|
const protocol = type || watch("protocol");
|
2021-03-19 07:49:33 +00:00
|
|
|
const clientAuthentication = watch("publicClient");
|
2021-04-26 07:40:59 +00:00
|
|
|
const authorization = watch("authorizationServicesEnabled");
|
2021-03-09 13:59:41 +00:00
|
|
|
|
2020-09-17 13:51:40 +00:00
|
|
|
return (
|
2021-04-26 11:48:09 +00:00
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-clients"
|
|
|
|
unWrap={unWrap}
|
|
|
|
className="keycloak__capability-config__form"
|
|
|
|
>
|
2021-03-09 13:59:41 +00:00
|
|
|
<>
|
|
|
|
{protocol === "openid-connect" && (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("clientAuthentication")}
|
|
|
|
fieldId="kc-authentication"
|
2021-04-13 00:05:00 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:authentication"
|
|
|
|
forLabel={t("authentication")}
|
|
|
|
forID="kc-authentication"
|
|
|
|
/>
|
|
|
|
}
|
2021-03-09 13:59:41 +00:00
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="publicClient"
|
2021-04-26 07:40:59 +00:00
|
|
|
defaultValue={false}
|
2021-03-09 13:59:41 +00:00
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="authentication"
|
2021-03-09 13:59:41 +00:00
|
|
|
id="kc-authentication"
|
|
|
|
name="publicClient"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2021-04-06 18:14:56 +00:00
|
|
|
isChecked={!value}
|
2021-04-26 11:48:09 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
onChange(!value);
|
|
|
|
if (!value) {
|
|
|
|
setValue("authorizationServicesEnabled", false);
|
|
|
|
setValue("serviceAccountsEnabled", false);
|
|
|
|
}
|
|
|
|
}}
|
2021-03-09 13:59:41 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("clientAuthorization")}
|
|
|
|
fieldId="kc-authorization"
|
2021-04-13 00:05:00 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:authorization"
|
|
|
|
forLabel={t("authorization")}
|
|
|
|
forID="kc-authorization"
|
|
|
|
/>
|
|
|
|
}
|
2021-03-09 13:59:41 +00:00
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="authorizationServicesEnabled"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="authorization"
|
2021-03-09 13:59:41 +00:00
|
|
|
id="kc-authorization"
|
|
|
|
name="authorizationServicesEnabled"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2021-04-26 07:40:59 +00:00
|
|
|
isChecked={value && !clientAuthentication}
|
2021-03-19 07:49:33 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
onChange(value);
|
|
|
|
if (value) {
|
|
|
|
setValue("serviceAccountsEnabled", true);
|
|
|
|
}
|
|
|
|
}}
|
2021-04-06 18:14:56 +00:00
|
|
|
isDisabled={clientAuthentication}
|
2021-03-09 13:59:41 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("authenticationFlow")}
|
|
|
|
fieldId="kc-flow"
|
|
|
|
>
|
|
|
|
<Grid>
|
2021-04-26 11:48:09 +00:00
|
|
|
<GridItem lg={4} sm={6}>
|
2021-03-09 13:59:41 +00:00
|
|
|
<Controller
|
|
|
|
name="standardFlowEnabled"
|
2021-03-19 07:49:33 +00:00
|
|
|
defaultValue={true}
|
2021-03-09 13:59:41 +00:00
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
2021-03-19 07:49:33 +00:00
|
|
|
<InputGroup>
|
|
|
|
<Checkbox
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="standard"
|
2021-03-19 07:49:33 +00:00
|
|
|
label={t("standardFlow")}
|
|
|
|
id="kc-flow-standard"
|
|
|
|
name="standardFlowEnabled"
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:standardFlow"
|
|
|
|
forLabel={t("standardFlow")}
|
|
|
|
forID="kc-flow-standard"
|
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-03-09 13:59:41 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</GridItem>
|
2021-04-26 11:48:09 +00:00
|
|
|
<GridItem lg={8} sm={6}>
|
2021-03-09 13:59:41 +00:00
|
|
|
<Controller
|
|
|
|
name="directAccessGrantsEnabled"
|
2021-03-19 07:49:33 +00:00
|
|
|
defaultValue={true}
|
2021-03-09 13:59:41 +00:00
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
2021-03-19 07:49:33 +00:00
|
|
|
<InputGroup>
|
|
|
|
<Checkbox
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="direct"
|
2021-03-19 07:49:33 +00:00
|
|
|
label={t("directAccess")}
|
|
|
|
id="kc-flow-direct"
|
|
|
|
name="directAccessGrantsEnabled"
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:directAccess"
|
|
|
|
forLabel={t("directAccess")}
|
|
|
|
forID="kc-flow-direct"
|
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-03-09 13:59:41 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</GridItem>
|
2021-04-26 11:48:09 +00:00
|
|
|
<GridItem lg={4} sm={6}>
|
2021-03-09 13:59:41 +00:00
|
|
|
<Controller
|
|
|
|
name="implicitFlowEnabled"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
2021-03-19 07:49:33 +00:00
|
|
|
<InputGroup>
|
|
|
|
<Checkbox
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="implicit"
|
2021-03-19 07:49:33 +00:00
|
|
|
label={t("implicitFlow")}
|
|
|
|
id="kc-flow-implicit"
|
|
|
|
name="implicitFlowEnabled"
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:implicitFlow"
|
|
|
|
forLabel={t("implicitFlow")}
|
|
|
|
forID="kc-flow-implicit"
|
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-03-09 13:59:41 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</GridItem>
|
2021-04-26 11:48:09 +00:00
|
|
|
<GridItem lg={8} sm={6}>
|
2021-03-09 13:59:41 +00:00
|
|
|
<Controller
|
|
|
|
name="serviceAccountsEnabled"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
2021-03-19 07:49:33 +00:00
|
|
|
<InputGroup>
|
|
|
|
<Checkbox
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="service-account"
|
2021-03-19 07:49:33 +00:00
|
|
|
label={t("serviceAccount")}
|
|
|
|
id="kc-flow-service-account"
|
|
|
|
name="serviceAccountsEnabled"
|
2021-04-23 09:55:15 +00:00
|
|
|
isChecked={
|
2021-04-26 07:40:59 +00:00
|
|
|
value || (clientAuthentication && authorization)
|
2021-03-19 07:49:33 +00:00
|
|
|
}
|
2021-04-23 09:55:15 +00:00
|
|
|
onChange={onChange}
|
2021-04-26 07:40:59 +00:00
|
|
|
isDisabled={
|
|
|
|
(clientAuthentication && !authorization) ||
|
|
|
|
(!clientAuthentication && authorization)
|
|
|
|
}
|
2021-03-19 07:49:33 +00:00
|
|
|
/>
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:serviceAccount"
|
|
|
|
forLabel={t("serviceAccount")}
|
|
|
|
forID="kc-flow-service-account"
|
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-03-09 13:59:41 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</GridItem>
|
|
|
|
</Grid>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
<>
|
|
|
|
{protocol === "saml" && (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:encryptAssertions"
|
|
|
|
forLabel={t("encryptAssertions")}
|
|
|
|
forID="kc-encrypt"
|
2020-09-17 13:51:40 +00:00
|
|
|
/>
|
2021-03-09 13:59:41 +00:00
|
|
|
}
|
|
|
|
label={t("encryptAssertions")}
|
|
|
|
fieldId="kc-encrypt"
|
2021-04-13 00:05:00 +00:00
|
|
|
hasNoPaddingTop
|
2021-03-09 13:59:41 +00:00
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.saml_encrypt"
|
|
|
|
control={control}
|
|
|
|
defaultValue="false"
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="encrypt"
|
2021-03-09 13:59:41 +00:00
|
|
|
id="kc-encrypt"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange("" + value)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:clientSignature"
|
|
|
|
forLabel={t("clientSignature")}
|
|
|
|
forID="kc-client-signature"
|
2020-09-17 13:51:40 +00:00
|
|
|
/>
|
2021-03-09 13:59:41 +00:00
|
|
|
}
|
|
|
|
label={t("clientSignature")}
|
|
|
|
fieldId="kc-client-signature"
|
2021-04-13 00:05:00 +00:00
|
|
|
hasNoPaddingTop
|
2021-03-09 13:59:41 +00:00
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="attributes.saml_client_signature"
|
|
|
|
control={control}
|
|
|
|
defaultValue="false"
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
2021-04-01 14:14:19 +00:00
|
|
|
data-testid="client-signature"
|
2021-03-09 13:59:41 +00:00
|
|
|
id="kc-client-signature"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange("" + value)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
2020-10-28 18:17:15 +00:00
|
|
|
</FormAccess>
|
2020-09-17 13:51:40 +00:00
|
|
|
);
|
|
|
|
};
|