import ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation"; import { FormGroup, Select, SelectOption, SelectVariant, } from "@patternfly/react-core"; import { useState } from "react"; import { Controller, UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem } from "ui-shared"; import { adminClient } from "../../admin-client"; import { FormAccess } from "../../components/form/FormAccess"; import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader"; import { useRealm } from "../../context/realm-context/RealmContext"; import { useFetch } from "../../utils/useFetch"; export type LdapSettingsGeneralProps = { form: UseFormReturn; showSectionHeading?: boolean; showSectionDescription?: boolean; vendorEdit?: boolean; }; export const LdapSettingsGeneral = ({ form, showSectionHeading = false, showSectionDescription = false, vendorEdit = false, }: LdapSettingsGeneralProps) => { const { t } = useTranslation(); const { realm } = useRealm(); useFetch( () => adminClient.realms.findOne({ realm }), (result) => form.setValue("parentId", result!.id), [], ); const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false); const setVendorDefaultValues = () => { switch (form.getValues("config.vendor[0]")) { case "ad": form.setValue("config.usernameLDAPAttribute[0]", "cn"); form.setValue("config.rdnLDAPAttribute[0]", "cn"); form.setValue("config.uuidLDAPAttribute[0]", "objectGUID"); form.setValue("config.krbPrincipalAttribute[0]", "userPrincipalName"); form.setValue( "config.userObjectClasses[0]", "person, organizationalPerson, user", ); break; case "rhds": form.setValue("config.usernameLDAPAttribute[0]", "uid"); form.setValue("config.rdnLDAPAttribute[0]", "uid"); form.setValue("config.uuidLDAPAttribute[0]", "nsuniqueid"); form.setValue("config.krbPrincipalAttribute[0]", "krbPrincipalName"); form.setValue( "config.userObjectClasses[0]", "inetOrgPerson, organizationalPerson", ); break; case "tivoli": form.setValue("config.usernameLDAPAttribute[0]", "uid"); form.setValue("config.rdnLDAPAttribute[0]", "uid"); form.setValue("config.uuidLDAPAttribute[0]", "uniqueidentifier"); form.setValue("config.krbPrincipalAttribute[0]", "krb5PrincipalName"); form.setValue( "config.userObjectClasses[0]", "inetOrgPerson, organizationalPerson", ); break; case "edirectory": form.setValue("config.usernameLDAPAttribute[0]", "uid"); form.setValue("config.rdnLDAPAttribute[0]", "uid"); form.setValue("config.uuidLDAPAttribute[0]", "guid"); form.setValue("config.krbPrincipalAttribute[0]", "krb5PrincipalName"); form.setValue( "config.userObjectClasses[0]", "inetOrgPerson, organizationalPerson", ); break; case "other": form.setValue("config.usernameLDAPAttribute[0]", "uid"); form.setValue("config.rdnLDAPAttribute[0]", "uid"); form.setValue("config.uuidLDAPAttribute[0]", "entryUUID"); form.setValue("config.krbPrincipalAttribute[0]", "krb5PrincipalName"); form.setValue( "config.userObjectClasses[0]", "inetOrgPerson, organizationalPerson", ); break; default: return ""; } }; return ( <> {showSectionHeading && ( )} } fieldId="kc-ui-display-name" isRequired validated={form.formState.errors.name ? "error" : "default"} helperTextInvalid={form.formState.errors.name?.message} > {/* These hidden fields are required so data object written back matches data retrieved */} } fieldId="kc-vendor" isRequired > ( )} > ); };