2020-10-30 20:15:37 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
2020-11-25 14:50:40 +00:00
|
|
|
SelectVariant,
|
2020-10-30 20:15:37 +00:00
|
|
|
Switch,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-12-16 07:02:41 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2020-11-25 14:50:40 +00:00
|
|
|
import { useForm, Controller } from "react-hook-form";
|
|
|
|
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2021-01-05 13:39:27 +00:00
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { convertToFormValues } from "../../util";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
|
|
|
export const LdapSettingsSearching = () => {
|
|
|
|
const { t } = useTranslation("user-federation");
|
2020-12-16 07:02:41 +00:00
|
|
|
const adminClient = useAdminClient();
|
2020-10-30 20:15:37 +00:00
|
|
|
const helpText = useTranslation("user-federation-help").t;
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isEditModeDropdownOpen, setIsEditModeDropdownOpen] = useState(false);
|
2020-12-16 07:02:41 +00:00
|
|
|
const { id } = useParams<{ id: string }>();
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isSearchScopeDropdownOpen, setIsSearchScopeDropdownOpen] = useState(
|
|
|
|
false
|
|
|
|
);
|
2020-12-16 07:02:41 +00:00
|
|
|
const { register, control, setValue } = useForm<ComponentRepresentation>();
|
|
|
|
|
|
|
|
const convertSearchScopes = (scope: string) => {
|
|
|
|
switch (scope) {
|
|
|
|
case "1":
|
|
|
|
default:
|
|
|
|
return `${t("oneLevel")}`;
|
|
|
|
case "2":
|
|
|
|
return `${t("subtree")}`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const setupForm = (component: ComponentRepresentation) => {
|
|
|
|
Object.entries(component).map((entry) => {
|
|
|
|
if (entry[0] === "config") {
|
|
|
|
convertToFormValues(entry[1], "config", setValue);
|
|
|
|
if (entry[1].searchScope) {
|
|
|
|
setValue(
|
|
|
|
"config.searchScope",
|
|
|
|
convertSearchScopes(entry[1].searchScope[0])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2020-12-16 07:02:41 +00:00
|
|
|
useEffect(() => {
|
2021-01-05 13:39:27 +00:00
|
|
|
return useFetch(
|
|
|
|
() => adminClient.components.findOne({ id }),
|
|
|
|
(fetchedComponent) => setupForm(fetchedComponent)
|
|
|
|
);
|
2020-12-16 07:02:41 +00:00
|
|
|
}, []);
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("editMode")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2020-11-24 13:56:31 +00:00
|
|
|
helpText={helpText("editModeLdapHelp")}
|
2020-10-30 20:15:37 +00:00
|
|
|
forLabel={t("editMode")}
|
|
|
|
forID="kc-edit-mode"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-edit-mode"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.editMode"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-edit-mode"
|
|
|
|
required
|
|
|
|
onToggle={() =>
|
|
|
|
setIsEditModeDropdownOpen(!isEditModeDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isEditModeDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsEditModeDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<SelectOption
|
|
|
|
key={0}
|
|
|
|
value={t("common:choose")}
|
|
|
|
isPlaceholder
|
|
|
|
/>
|
2020-11-25 14:50:40 +00:00
|
|
|
<SelectOption key={1} value="RACT_ONLY" />
|
|
|
|
<SelectOption key={2} value="WRITABLE" />
|
|
|
|
<SelectOption key={3} value="UNSYNCED" />
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("usersDN")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("usersDNHelp")}
|
|
|
|
forLabel={t("usersDN")}
|
|
|
|
forID="kc-console-users-dn"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-console-users-dn"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-console-users-dn"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.usersDn"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("usernameLdapAttribute")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("usernameLdapAttributeHelp")}
|
|
|
|
forLabel={t("usernameLdapAttribute")}
|
|
|
|
forID="kc-username-ldap-attribute"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-username-ldap-attribute"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-username-ldap-attribute"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.usernameLDAPAttribute"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("rdnLdapAttribute")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("rdnLdapAttributeHelp")}
|
|
|
|
forLabel={t("rdnLdapAttribute")}
|
|
|
|
forID="kc-rdn-ldap-attribute"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-rdn-ldap-attribute"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-rdn-ldap-attribute"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.rdnLDAPAttribute"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("uuidLdapAttribute")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("uuidLdapAttributeHelp")}
|
|
|
|
forLabel={t("uuidLdapAttribute")}
|
|
|
|
forID="kc-uuid-ldap-attribute"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-uuid-ldap-attribute"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-uuid-ldap-attribute"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.uuidLDAPAttribute"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("userObjectClasses")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("userObjectClassesHelp")}
|
|
|
|
forLabel={t("userObjectClasses")}
|
|
|
|
forID="kc-user-object-classes"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-user-object-classes"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-user-object-classes"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.userObjectClasses"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("userLdapFilter")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("userLdapFilterHelp")}
|
|
|
|
forLabel={t("userLdapFilter")}
|
|
|
|
forID="kc-user-ldap-filter"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-user-ldap-filter"
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-user-ldap-filter"
|
|
|
|
name="config.customUserSearchFilter"
|
|
|
|
ref={register}
|
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("searchScope")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("searchScopeHelp")}
|
|
|
|
forLabel={t("searchScope")}
|
|
|
|
forID="kc-search-scope"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-search-scope"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.searchScope"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-search-scope"
|
|
|
|
required
|
|
|
|
onToggle={() =>
|
|
|
|
setIsSearchScopeDropdownOpen(!isSearchScopeDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isSearchScopeDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsSearchScopeDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<SelectOption
|
|
|
|
key={0}
|
|
|
|
value={t("common:choose")}
|
|
|
|
isPlaceholder
|
|
|
|
/>
|
|
|
|
<SelectOption key={1} value={t("oneLevel")} />
|
|
|
|
<SelectOption key={2} value={t("subtree")} />
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("readTimeout")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("readTimeoutHelp")}
|
|
|
|
forLabel={t("readTimeout")}
|
|
|
|
forID="kc-read-timeout"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-read-timeout"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-read-timeout"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.readTimeout"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("pagination")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("paginationHelp")}
|
|
|
|
forLabel={t("pagination")}
|
|
|
|
forID="kc-console-pagination"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-console-pagination"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.pagination"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id={"kc-console-pagination"}
|
2020-12-16 07:02:41 +00:00
|
|
|
isChecked={value[0] === "true"}
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
|
|
|
onChange={onChange}
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></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
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|