2020-11-25 14:50:40 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
2020-10-30 20:15:37 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-01-26 01:41:14 +00:00
|
|
|
import React, { useState } from "react";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2021-01-26 01:41:14 +00:00
|
|
|
import { UseFormMethods, Controller } from "react-hook-form";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2021-02-19 23:13:07 +00:00
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
|
|
|
|
2021-01-04 21:33:18 +00:00
|
|
|
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
2021-08-24 10:39:16 +00:00
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2021-01-04 21:33:18 +00:00
|
|
|
export type LdapSettingsGeneralProps = {
|
2021-01-26 01:41:14 +00:00
|
|
|
form: UseFormMethods;
|
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-08-24 10:39:16 +00:00
|
|
|
|
|
|
|
const adminClient = useAdminClient();
|
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
|
|
|
|
label={t("consoleDisplayName")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-02-17 14:43:52 +00:00
|
|
|
helpText="user-federation-help:consoleDisplayNameHelp"
|
|
|
|
fieldLabelId="user-federation:consoleDisplayName"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-console-display-name"
|
|
|
|
isRequired
|
2022-03-29 07:49:43 +00:00
|
|
|
validated={form.errors.name ? "error" : "default"}
|
|
|
|
helperTextInvalid={form.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-02-17 14:43:52 +00:00
|
|
|
<TextInput hidden type="text" id="kc-console-id" name="id" />
|
2021-01-26 01:41:14 +00:00
|
|
|
<TextInput
|
|
|
|
hidden
|
|
|
|
type="text"
|
|
|
|
id="kc-console-provider-id"
|
|
|
|
name="providerId"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue="ldap"
|
2021-01-26 01:41:14 +00:00
|
|
|
ref={form.register}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
hidden
|
|
|
|
type="text"
|
|
|
|
id="kc-console-provider-type"
|
|
|
|
name="providerType"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue="org.keycloak.storage.UserStorageProvider"
|
2021-01-26 01:41:14 +00:00
|
|
|
ref={form.register}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
hidden
|
|
|
|
type="text"
|
|
|
|
id="kc-console-parentId"
|
|
|
|
name="parentId"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue={realm}
|
2021-01-26 01:41:14 +00:00
|
|
|
ref={form.register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
2021-02-19 23:13:07 +00:00
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-console-display-name"
|
|
|
|
name="name"
|
2021-05-06 07:23:51 +00:00
|
|
|
defaultValue="ldap"
|
2021-02-19 23:13:07 +00:00
|
|
|
ref={form.register({
|
|
|
|
required: {
|
|
|
|
value: true,
|
|
|
|
message: `${t("validateName")}`,
|
|
|
|
},
|
|
|
|
})}
|
2021-02-23 20:49:57 +00:00
|
|
|
data-testid="ldap-name"
|
2022-03-29 07:49:43 +00:00
|
|
|
validated={form.errors.name ? "error" : "default"}
|
2021-02-19 23:13:07 +00:00
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("vendor")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-02-17 14:43:52 +00:00
|
|
|
helpText="user-federation-help:vendorHelp"
|
|
|
|
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}
|
2020-11-25 14:50:40 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<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) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsVendorDropdownOpen(false);
|
2021-05-14 18:12:27 +00:00
|
|
|
setVendorDefaultValues();
|
2020-11-25 14:50:40 +00:00
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
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
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|