2022-04-25 11:23:59 +00:00
|
|
|
import { Button, FormGroup, Switch } from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, UseFormReturn } from "react-hook-form";
|
2020-10-30 20:15:37 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-04-19 18:10:34 +00:00
|
|
|
import { HelpItem } from "@keycloak/keycloak-ui-shared";
|
2024-05-08 08:23:43 +00:00
|
|
|
import { useAdminClient } from "../../admin-client";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { useAlerts } from "../../components/alert/Alerts";
|
2023-05-24 12:11:06 +00:00
|
|
|
import { FormAccess } from "../../components/form/FormAccess";
|
2021-01-04 21:33:18 +00:00
|
|
|
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
2022-04-25 11:23:59 +00:00
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { convertFormToSettings } from "./LdapSettingsConnection";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2021-01-04 21:33:18 +00:00
|
|
|
export type LdapSettingsAdvancedProps = {
|
2022-04-25 11:23:59 +00:00
|
|
|
id?: string;
|
2023-01-26 09:31:07 +00:00
|
|
|
form: UseFormReturn;
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading?: boolean;
|
|
|
|
showSectionDescription?: boolean;
|
|
|
|
};
|
|
|
|
|
2022-04-25 11:23:59 +00:00
|
|
|
const PASSWORD_MODIFY_OID = "1.3.6.1.4.1.4203.1.11.1";
|
|
|
|
|
2021-01-04 21:33:18 +00:00
|
|
|
export const LdapSettingsAdvanced = ({
|
2022-04-25 11:23:59 +00:00
|
|
|
id,
|
2021-01-26 01:41:14 +00:00
|
|
|
form,
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading = false,
|
|
|
|
showSectionDescription = false,
|
|
|
|
}: LdapSettingsAdvancedProps) => {
|
2024-05-08 08:23:43 +00:00
|
|
|
const { adminClient } = useAdminClient();
|
|
|
|
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2022-04-25 11:23:59 +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 },
|
2023-07-11 14:03:21 +00:00
|
|
|
{ ...settings, componentId: id },
|
2022-04-25 11:23:59 +00:00
|
|
|
);
|
|
|
|
addAlert(t("testSuccess"));
|
|
|
|
const passwordModifyOid = ldapOids.filter(
|
2023-07-11 14:03:21 +00:00
|
|
|
(id: { oid: string }) => id.oid === PASSWORD_MODIFY_OID,
|
2022-04-25 11:23:59 +00:00
|
|
|
);
|
|
|
|
form.setValue("config.usePasswordModifyExtendedOp", [
|
|
|
|
(passwordModifyOid.length > 0).toString(),
|
|
|
|
]);
|
|
|
|
} catch (error) {
|
2023-09-25 07:06:56 +00:00
|
|
|
addError("testError", error);
|
2022-04-25 11:23:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-01-04 21:33:18 +00:00
|
|
|
{showSectionHeading && (
|
|
|
|
<WizardSectionHeader
|
|
|
|
title={t("advancedSettings")}
|
2023-09-08 13:17:17 +00:00
|
|
|
description={t("ldapAdvancedSettingsDescription")}
|
2021-01-04 21:33:18 +00:00
|
|
|
showDescription={showSectionDescription}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("enableLdapv3Password")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("enableLdapv3PasswordHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="enableLdapv3Password"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-enable-ldapv3-password"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.usePasswordModifyExtendedOp"
|
2021-01-26 01:41:14 +00:00
|
|
|
defaultValue={["false"]}
|
|
|
|
control={form.control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2020-11-25 14:50:40 +00:00
|
|
|
<Switch
|
|
|
|
id={"kc-enable-ldapv3-password"}
|
2022-04-14 11:07:28 +00:00
|
|
|
data-testid="ldapv3-password"
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
2024-04-05 14:37:05 +00:00
|
|
|
onChange={(_event, value) => field.onChange([`${value}`])}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value[0] === "true"}
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("enableLdapv3Password")}
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
label={t("validatePasswordPolicy")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("validatePasswordPolicyHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="validatePasswordPolicy"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-validate-password-policy"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.validatePasswordPolicy"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue={["false"]}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2020-11-25 14:50:40 +00:00
|
|
|
<Switch
|
|
|
|
id={"kc-validate-password-policy"}
|
2022-04-14 11:07:28 +00:00
|
|
|
data-testid="password-policy"
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
2024-04-05 14:37:05 +00:00
|
|
|
onChange={(_event, value) => field.onChange([`${value}`])}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value[0] === "true"}
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("validatePasswordPolicy")}
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
label={t("trustEmail")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("trustEmailHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="trustEmail"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-trust-email"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.trustEmail"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue={["false"]}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2020-11-25 14:50:40 +00:00
|
|
|
<Switch
|
|
|
|
id={"kc-trust-email"}
|
2022-04-14 11:07:28 +00:00
|
|
|
data-testid="trust-email"
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
2024-04-05 14:37:05 +00:00
|
|
|
onChange={(_event, value) => field.onChange([`${value}`])}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value[0] === "true"}
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("trustEmail")}
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
2022-04-25 11:23:59 +00:00
|
|
|
<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>
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|