2023-02-13 07:18:16 +00:00
|
|
|
import ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
|
2020-11-25 14:50:40 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
} from "@patternfly/react-core";
|
2022-08-03 12:12:07 +00:00
|
|
|
import { useState } from "react";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, UseFormReturn } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2023-05-03 13:51:02 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2021-02-19 23:13:07 +00:00
|
|
|
|
2023-05-03 13:51:02 +00:00
|
|
|
import { adminClient } from "../../admin-client";
|
2023-05-24 12:11:06 +00:00
|
|
|
import { FormAccess } from "../../components/form/FormAccess";
|
2022-04-21 15:03:26 +00:00
|
|
|
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
2023-05-03 15:40:27 +00:00
|
|
|
import { useFetch } from "../../utils/useFetch";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2021-01-04 21:33:18 +00:00
|
|
|
export type LdapSettingsGeneralProps = {
|
2023-02-13 07:18:16 +00:00
|
|
|
form: UseFormReturn<ComponentRepresentation>;
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading?: boolean;
|
|
|
|
showSectionDescription?: boolean;
|
2021-11-01 18:44:23 +00:00
|
|
|
vendorEdit?: boolean;
|
2021-01-04 21:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const LdapSettingsGeneral = ({
|
2021-01-26 01:41:14 +00:00
|
|
|
form,
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading = false,
|
|
|
|
showSectionDescription = false,
|
2021-11-01 18:44:23 +00:00
|
|
|
vendorEdit = false,
|
2021-01-04 21:33:18 +00:00
|
|
|
}: LdapSettingsGeneralProps) => {
|
2020-10-30 20:15:37 +00:00
|
|
|
const { t } = useTranslation("user-federation");
|
2021-12-14 14:56:36 +00:00
|
|
|
const { t: helpText } = useTranslation("user-federation-help");
|
2021-02-19 23:13:07 +00:00
|
|
|
const { realm } = useRealm();
|
2020-12-16 07:02:41 +00:00
|
|
|
|
2021-08-24 10:39:16 +00:00
|
|
|
useFetch(
|
|
|
|
() => adminClient.realms.findOne({ realm }),
|
2021-09-30 08:58:48 +00:00
|
|
|
(result) => form.setValue("parentId", result!.id),
|
2021-08-24 10:39:16 +00:00
|
|
|
[]
|
|
|
|
);
|
2021-01-26 01:41:14 +00:00
|
|
|
const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false);
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2021-05-14 18:12:27 +00:00
|
|
|
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.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.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.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.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.userObjectClasses[0]",
|
|
|
|
"inetOrgPerson, organizationalPerson"
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-01-04 21:33:18 +00:00
|
|
|
{showSectionHeading && (
|
|
|
|
<WizardSectionHeader
|
|
|
|
title={t("generalOptions")}
|
|
|
|
description={helpText("ldapGeneralOptionsSettingsDescription")}
|
|
|
|
showDescription={showSectionDescription}
|
|
|
|
/>
|
|
|
|
)}
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
2022-12-07 15:28:28 +00:00
|
|
|
label={t("uiDisplayName")}
|
2020-10-30 20:15:37 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("user-federation-help:uiDisplayNameHelp")}
|
2022-12-07 15:28:28 +00:00
|
|
|
fieldLabelId="user-federation:uiDisplayName"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2022-12-07 15:28:28 +00:00
|
|
|
fieldId="kc-ui-display-name"
|
2020-10-30 20:15:37 +00:00
|
|
|
isRequired
|
2023-01-26 09:31:07 +00:00
|
|
|
validated={form.formState.errors.name ? "error" : "default"}
|
|
|
|
helperTextInvalid={form.formState.errors.name?.message}
|
2020-10-30 20:15:37 +00:00
|
|
|
>
|
2021-01-26 01:41:14 +00:00
|
|
|
{/* These hidden fields are required so data object written back matches data retrieved */}
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-01-26 01:41:14 +00:00
|
|
|
hidden
|
2022-12-07 15:28:28 +00:00
|
|
|
id="kc-ui-provider-id"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue="ldap"
|
2023-01-26 09:31:07 +00:00
|
|
|
{...form.register("providerId")}
|
2021-01-26 01:41:14 +00:00
|
|
|
/>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-01-26 01:41:14 +00:00
|
|
|
hidden
|
2022-12-07 15:28:28 +00:00
|
|
|
id="kc-ui-provider-type"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue="org.keycloak.storage.UserStorageProvider"
|
2023-01-26 09:31:07 +00:00
|
|
|
{...form.register("providerType")}
|
2021-01-26 01:41:14 +00:00
|
|
|
/>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-01-26 01:41:14 +00:00
|
|
|
hidden
|
2022-12-07 15:28:28 +00:00
|
|
|
id="kc-ui-parentId"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue={realm}
|
2023-01-26 09:31:07 +00:00
|
|
|
{...form.register("parentId")}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-02-19 23:13:07 +00:00
|
|
|
isRequired
|
2022-12-07 15:28:28 +00:00
|
|
|
id="kc-ui-display-name"
|
2021-05-06 07:23:51 +00:00
|
|
|
defaultValue="ldap"
|
2023-01-26 09:31:07 +00:00
|
|
|
data-testid="ldap-name"
|
|
|
|
validated={form.formState.errors.name ? "error" : "default"}
|
|
|
|
{...form.register("name", {
|
2021-02-19 23:13:07 +00:00
|
|
|
required: {
|
|
|
|
value: true,
|
|
|
|
message: `${t("validateName")}`,
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("vendor")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-03-07 09:29:40 +00:00
|
|
|
helpText={t("user-federation-help:vendorHelp")}
|
2022-02-17 14:43:52 +00:00
|
|
|
fieldLabelId="user-federation:vendor"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-vendor"
|
|
|
|
isRequired
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2021-01-26 01:41:14 +00:00
|
|
|
name="config.vendor[0]"
|
2021-05-14 18:12:27 +00:00
|
|
|
defaultValue="ad"
|
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
|
|
|
<Select
|
2021-11-01 18:44:23 +00:00
|
|
|
isDisabled={!!vendorEdit}
|
2020-11-25 14:50:40 +00:00
|
|
|
toggleId="kc-vendor"
|
|
|
|
required
|
|
|
|
onToggle={() => setIsVendorDropdownOpen(!isVendorDropdownOpen)}
|
|
|
|
isOpen={isVendorDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2020-11-25 14:50:40 +00:00
|
|
|
setIsVendorDropdownOpen(false);
|
2021-05-14 18:12:27 +00:00
|
|
|
setVendorDefaultValues();
|
2020-11-25 14:50:40 +00:00
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2020-11-25 14:50:40 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2021-01-26 01:41:14 +00:00
|
|
|
<SelectOption key={0} value="ad" isPlaceholder>
|
|
|
|
Active Directory
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={1} value="rhds">
|
|
|
|
Red Hat Directory Server
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={2} value="tivoli">
|
|
|
|
Tivoli
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={3} value="edirectory">
|
|
|
|
Novell eDirectory
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={4} value="other">
|
|
|
|
Other
|
|
|
|
</SelectOption>
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
2020-11-25 16:17:50 +00:00
|
|
|
</FormAccess>
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|