2023-01-05 11:38:16 +00:00
|
|
|
import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
|
2023-05-24 12:11:06 +00:00
|
|
|
import { Button, Form } from "@patternfly/react-core";
|
2023-01-05 11:38:16 +00:00
|
|
|
import { useFormContext } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2023-01-18 12:09:49 +00:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2023-11-14 11:04:55 +00:00
|
|
|
import { ScrollForm } from "ui-shared";
|
2023-01-05 11:38:16 +00:00
|
|
|
|
2023-11-14 11:04:55 +00:00
|
|
|
import { FixedButtonsGroup } from "../components/form/FixedButtonGroup";
|
2023-01-05 11:38:16 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2023-04-18 16:50:46 +00:00
|
|
|
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
|
2023-01-05 11:38:16 +00:00
|
|
|
import { LdapSettingsAdvanced } from "./ldap/LdapSettingsAdvanced";
|
|
|
|
import { LdapSettingsConnection } from "./ldap/LdapSettingsConnection";
|
|
|
|
import { LdapSettingsGeneral } from "./ldap/LdapSettingsGeneral";
|
|
|
|
import { LdapSettingsKerberosIntegration } from "./ldap/LdapSettingsKerberosIntegration";
|
|
|
|
import { LdapSettingsSearching } from "./ldap/LdapSettingsSearching";
|
|
|
|
import { LdapSettingsSynchronization } from "./ldap/LdapSettingsSynchronization";
|
|
|
|
import { toUserFederation } from "./routes/UserFederation";
|
|
|
|
import { SettingsCache } from "./shared/SettingsCache";
|
|
|
|
|
|
|
|
export type LdapComponentRepresentation = ComponentRepresentation & {
|
|
|
|
config?: {
|
|
|
|
periodicChangedUsersSync?: boolean;
|
|
|
|
periodicFullSync?: boolean;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UserFederationLdapFormProps = {
|
|
|
|
id?: string;
|
|
|
|
onSubmit: (formData: LdapComponentRepresentation) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const UserFederationLdapForm = ({
|
|
|
|
id,
|
|
|
|
onSubmit,
|
|
|
|
}: UserFederationLdapFormProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2023-01-05 11:38:16 +00:00
|
|
|
const form = useFormContext<LdapComponentRepresentation>();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const { realm } = useRealm();
|
2023-04-18 16:50:46 +00:00
|
|
|
const isFeatureEnabled = useIsFeatureEnabled();
|
2023-01-05 11:38:16 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ScrollForm
|
2023-11-14 11:04:55 +00:00
|
|
|
label={t("jumpToSection")}
|
2023-01-05 11:38:16 +00:00
|
|
|
sections={[
|
|
|
|
{
|
|
|
|
title: t("generalOptions"),
|
|
|
|
panel: <LdapSettingsGeneral form={form} vendorEdit={!!id} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("connectionAndAuthenticationSettings"),
|
|
|
|
panel: <LdapSettingsConnection form={form} id={id} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("ldapSearchingAndUpdatingSettings"),
|
|
|
|
panel: <LdapSettingsSearching form={form} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("synchronizationSettings"),
|
|
|
|
panel: <LdapSettingsSynchronization form={form} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("kerberosIntegration"),
|
|
|
|
panel: <LdapSettingsKerberosIntegration form={form} />,
|
2023-04-18 16:50:46 +00:00
|
|
|
isHidden: !isFeatureEnabled(Feature.Kerberos),
|
2023-01-05 11:38:16 +00:00
|
|
|
},
|
|
|
|
{ title: t("cacheSettings"), panel: <SettingsCache form={form} /> },
|
|
|
|
{
|
|
|
|
title: t("advancedSettings"),
|
|
|
|
panel: <LdapSettingsAdvanced form={form} id={id} />,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Form onSubmit={form.handleSubmit(onSubmit)}>
|
2023-05-24 12:11:06 +00:00
|
|
|
<FixedButtonsGroup
|
|
|
|
name="ldap"
|
|
|
|
isActive={form.formState.isDirty}
|
|
|
|
isSubmit
|
|
|
|
>
|
2023-01-05 11:38:16 +00:00
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
onClick={() => navigate(toUserFederation({ realm }))}
|
|
|
|
data-testid="ldap-cancel"
|
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("cancel")}
|
2023-01-05 11:38:16 +00:00
|
|
|
</Button>
|
2023-05-24 12:11:06 +00:00
|
|
|
</FixedButtonsGroup>
|
2023-01-05 11:38:16 +00:00
|
|
|
</Form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export function serializeFormData(
|
2023-07-11 14:03:21 +00:00
|
|
|
formData: LdapComponentRepresentation,
|
2023-01-05 11:38:16 +00:00
|
|
|
): LdapComponentRepresentation {
|
|
|
|
const { config } = formData;
|
|
|
|
|
|
|
|
if (config?.periodicChangedUsersSync !== undefined) {
|
|
|
|
if (config.periodicChangedUsersSync === false) {
|
|
|
|
config.changedSyncPeriod = ["-1"];
|
|
|
|
}
|
|
|
|
delete config.periodicChangedUsersSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config?.periodicFullSync !== undefined) {
|
|
|
|
if (config.periodicFullSync === false) {
|
|
|
|
config.fullSyncPeriod = ["-1"];
|
|
|
|
}
|
|
|
|
delete config.periodicFullSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
return formData;
|
|
|
|
}
|