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-access/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"); const { t: helpText } = useTranslation("user-federation-help"); 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 && ( )} } fieldId="kc-enable-ldapv3-password" hasNoPaddingTop > ( field.onChange([`${value}`])} isChecked={field.value[0] === "true"} label={t("common:on")} labelOff={t("common:off")} aria-label={t("enableLdapv3Password")} /> )} > } fieldId="kc-validate-password-policy" hasNoPaddingTop > ( field.onChange([`${value}`])} isChecked={field.value[0] === "true"} label={t("common:on")} labelOff={t("common:off")} aria-label={t("validatePasswordPolicy")} /> )} > } fieldId="kc-trust-email" hasNoPaddingTop > ( field.onChange([`${value}`])} isChecked={field.value[0] === "true"} label={t("common:on")} labelOff={t("common:off")} aria-label={t("trustEmail")} /> )} > ); };