UNPKG

@keycloakify/keycloak-admin-ui

Version:
64 lines 5.53 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { HelpItem, KeycloakSelect, SelectVariant, TextControl, } from "../../ui-shared"; import { FormGroup, SelectOption } from "@patternfly/react-core"; import { useEffect, useState } from "react"; import { Controller, FormProvider } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../../components/form/FormAccess"; import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader"; import { useRealm } from "../../context/realm-context/RealmContext"; export const LdapSettingsGeneral = ({ form, showSectionHeading = false, showSectionDescription = false, vendorEdit = false, }) => { const { t } = useTranslation(); const { realm, realmRepresentation } = useRealm(); useEffect(() => form.setValue("parentId", realmRepresentation === null || realmRepresentation === void 0 ? void 0 : realmRepresentation.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 (_jsxs(FormProvider, { ...form, children: [showSectionHeading && (_jsx(WizardSectionHeader, { title: t("generalOptions"), description: t("ldapGeneralOptionsSettingsDescription"), showDescription: showSectionDescription })), _jsxs(FormAccess, { role: "manage-realm", isHorizontal: true, children: [_jsx("input", { type: "hidden", defaultValue: "ldap", ...form.register("providerId") }), _jsx("input", { type: "hidden", defaultValue: "org.keycloak.storage.UserStorageProvider", ...form.register("providerType") }), _jsx("input", { type: "hidden", defaultValue: realm, ...form.register("parentId") }), _jsx(TextControl, { name: "name", label: t("uiDisplayName"), labelIcon: t("uiDisplayNameHelp"), defaultValue: "ldap", rules: { required: t("validateName"), } }), _jsx(FormGroup, { label: t("vendor"), labelIcon: _jsx(HelpItem, { helpText: t("vendorHelp"), fieldLabelId: "vendor" }), fieldId: "kc-vendor", isRequired: true, children: _jsx(Controller, { name: "config.vendor[0]", defaultValue: "ad", control: form.control, render: ({ field }) => (_jsxs(KeycloakSelect, { isDisabled: !!vendorEdit, toggleId: "kc-vendor", onToggle: () => setIsVendorDropdownOpen(!isVendorDropdownOpen), isOpen: isVendorDropdownOpen, onSelect: (value) => { field.onChange(value); setIsVendorDropdownOpen(false); setVendorDefaultValues(); }, selections: field.value, variant: SelectVariant.single, "aria-label": t("selectVendor"), children: [_jsx(SelectOption, { value: "ad", children: "Active Directory" }, 0), _jsx(SelectOption, { value: "rhds", children: "Red Hat Directory Server" }, 1), _jsx(SelectOption, { value: "tivoli", children: "Tivoli" }, 2), _jsx(SelectOption, { value: "edirectory", children: "Novell eDirectory" }, 3), _jsx(SelectOption, { value: "other", children: "Other" }, 4)] })) }) })] })] })); }; //# sourceMappingURL=LdapSettingsGeneral.js.map