keycloak-scim/js/apps/admin-ui/src/user-federation/ldap/LdapSettingsAdvanced.tsx

168 lines
5.4 KiB
TypeScript
Raw Normal View History

import { Button, FormGroup, Switch } from "@patternfly/react-core";
import { Controller, UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { HelpItem } from "ui-shared";
import { adminClient } from "../../admin-client";
import { useAlerts } from "../../components/alert/Alerts";
import { FormAccess } from "../../components/form/FormAccess";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
import { useRealm } from "../../context/realm-context/RealmContext";
import { convertFormToSettings } from "./LdapSettingsConnection";
export type LdapSettingsAdvancedProps = {
id?: string;
form: UseFormReturn;
showSectionHeading?: boolean;
showSectionDescription?: boolean;
};
const PASSWORD_MODIFY_OID = "1.3.6.1.4.1.4203.1.11.1";
export const LdapSettingsAdvanced = ({
id,
form,
showSectionHeading = false,
showSectionDescription = false,
}: LdapSettingsAdvancedProps) => {
const { t } = useTranslation("user-federation");
2021-12-14 14:56:36 +00:00
const { t: helpText } = useTranslation("user-federation-help");
2020-11-25 14:50:40 +00:00
const { realm } = useRealm();
const { addAlert, addError } = useAlerts();
const testLdap = async () => {
if (!(await form.trigger())) return;
try {
const settings = convertFormToSettings(form);
const ldapOids = await adminClient.realms.ldapServerCapabilities(
{ realm },
{ ...settings, componentId: id },
);
addAlert(t("testSuccess"));
const passwordModifyOid = ldapOids.filter(
(id: { oid: string }) => id.oid === PASSWORD_MODIFY_OID,
);
form.setValue("config.usePasswordModifyExtendedOp", [
(passwordModifyOid.length > 0).toString(),
]);
} catch (error) {
addError("user-federation:testError", error);
}
};
return (
<>
{showSectionHeading && (
<WizardSectionHeader
title={t("advancedSettings")}
description={helpText("ldapAdvancedSettingsDescription")}
showDescription={showSectionDescription}
/>
)}
2020-11-25 16:17:50 +00:00
<FormAccess role="manage-realm" isHorizontal>
<FormGroup
label={t("enableLdapv3Password")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:enableLdapv3PasswordHelp")}
fieldLabelId="user-federation:enableLdapv3Password"
/>
}
fieldId="kc-enable-ldapv3-password"
hasNoPaddingTop
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.usePasswordModifyExtendedOp"
defaultValue={["false"]}
control={form.control}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Switch
id={"kc-enable-ldapv3-password"}
data-testid="ldapv3-password"
2020-11-25 14:50:40 +00:00
isDisabled={false}
onChange={(value) => field.onChange([`${value}`])}
isChecked={field.value[0] === "true"}
2020-11-25 14:50:40 +00:00
label={t("common:on")}
labelOff={t("common:off")}
aria-label={t("enableLdapv3Password")}
2020-11-25 14:50:40 +00:00
/>
)}
></Controller>
</FormGroup>
<FormGroup
label={t("validatePasswordPolicy")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:validatePasswordPolicyHelp")}
fieldLabelId="user-federation:validatePasswordPolicy"
/>
}
fieldId="kc-validate-password-policy"
hasNoPaddingTop
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.validatePasswordPolicy"
2021-02-19 23:13:07 +00:00
defaultValue={["false"]}
control={form.control}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Switch
id={"kc-validate-password-policy"}
data-testid="password-policy"
2020-11-25 14:50:40 +00:00
isDisabled={false}
onChange={(value) => field.onChange([`${value}`])}
isChecked={field.value[0] === "true"}
2020-11-25 14:50:40 +00:00
label={t("common:on")}
labelOff={t("common:off")}
aria-label={t("validatePasswordPolicy")}
2020-11-25 14:50:40 +00:00
/>
)}
></Controller>
</FormGroup>
<FormGroup
label={t("trustEmail")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:trustEmailHelp")}
fieldLabelId="user-federation:trustEmail"
/>
}
fieldId="kc-trust-email"
hasNoPaddingTop
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.trustEmail"
2021-02-19 23:13:07 +00:00
defaultValue={["false"]}
control={form.control}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Switch
id={"kc-trust-email"}
data-testid="trust-email"
2020-11-25 14:50:40 +00:00
isDisabled={false}
onChange={(value) => field.onChange([`${value}`])}
isChecked={field.value[0] === "true"}
2020-11-25 14:50:40 +00:00
label={t("common:on")}
labelOff={t("common:off")}
aria-label={t("trustEmail")}
2020-11-25 14:50:40 +00:00
/>
)}
></Controller>
</FormGroup>
<FormGroup fieldId="query-extensions">
<Button
variant="secondary"
id="query-extensions"
data-testid="query-extensions"
onClick={testLdap}
>
{t("queryExtensions")}
</Button>
</FormGroup>
2020-11-25 16:17:50 +00:00
</FormAccess>
</>
);
};