2021-02-08 20:50:03 +00:00
|
|
|
import React, { useEffect } from "react";
|
2021-01-26 01:41:14 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
AlertVariant,
|
|
|
|
Button,
|
2021-02-08 20:50:03 +00:00
|
|
|
ButtonVariant,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownSeparator,
|
2021-01-26 01:41:14 +00:00
|
|
|
Form,
|
|
|
|
PageSection,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
2020-12-16 07:02:41 +00:00
|
|
|
import { LdapSettingsAdvanced } from "./ldap/LdapSettingsAdvanced";
|
|
|
|
import { LdapSettingsKerberosIntegration } from "./ldap/LdapSettingsKerberosIntegration";
|
2021-02-11 20:51:51 +00:00
|
|
|
import { SettingsCache } from "./shared/SettingsCache";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { LdapSettingsSynchronization } from "./ldap/LdapSettingsSynchronization";
|
|
|
|
import { LdapSettingsGeneral } from "./ldap/LdapSettingsGeneral";
|
|
|
|
import { LdapSettingsConnection } from "./ldap/LdapSettingsConnection";
|
|
|
|
import { LdapSettingsSearching } from "./ldap/LdapSettingsSearching";
|
2021-01-26 01:41:14 +00:00
|
|
|
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
|
|
|
import { convertToFormValues } from "../util";
|
|
|
|
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
|
|
|
|
2021-02-08 20:50:03 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
|
|
|
import { useHistory, useParams } from "react-router-dom";
|
|
|
|
import { ScrollForm } from "../components/scroll-form/ScrollForm";
|
|
|
|
|
|
|
|
type LdapSettingsHeaderProps = {
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
value: string;
|
|
|
|
save: () => void;
|
|
|
|
toggleDeleteDialog: () => void;
|
|
|
|
toggleRemoveUsersDialog: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const LdapSettingsHeader = ({
|
|
|
|
onChange,
|
|
|
|
value,
|
|
|
|
save,
|
|
|
|
toggleDeleteDialog,
|
|
|
|
toggleRemoveUsersDialog,
|
|
|
|
}: LdapSettingsHeaderProps) => {
|
|
|
|
const { t } = useTranslation("user-federation");
|
2021-02-19 23:13:07 +00:00
|
|
|
const { id } = useParams<{ id: string }>();
|
2021-02-08 20:50:03 +00:00
|
|
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "user-federation:userFedDisableConfirmTitle",
|
|
|
|
messageKey: "user-federation:userFedDisableConfirm",
|
|
|
|
continueButtonLabel: "common:disable",
|
|
|
|
onConfirm: () => {
|
|
|
|
onChange("false");
|
|
|
|
save();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DisableConfirm />
|
2021-02-19 23:13:07 +00:00
|
|
|
{id === "new" ? (
|
|
|
|
<ViewHeader titleKey="LDAP" subKey="" />
|
|
|
|
) : (
|
|
|
|
<ViewHeader
|
|
|
|
titleKey="LDAP"
|
|
|
|
subKey=""
|
|
|
|
dropdownItems={[
|
|
|
|
<DropdownItem
|
|
|
|
key="sync"
|
|
|
|
onClick={() => console.log("Sync users TBD")}
|
|
|
|
>
|
|
|
|
{t("syncChangedUsers")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem
|
|
|
|
key="syncall"
|
|
|
|
onClick={() => console.log("Sync all users TBD")}
|
|
|
|
>
|
|
|
|
{t("syncAllUsers")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem
|
|
|
|
key="unlink"
|
|
|
|
onClick={() => console.log("Unlink users TBD")}
|
|
|
|
>
|
|
|
|
{t("unlinkUsers")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem
|
|
|
|
key="remove"
|
|
|
|
onClick={() => toggleRemoveUsersDialog()}
|
|
|
|
>
|
|
|
|
{t("removeImported")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownSeparator key="separator" />,
|
|
|
|
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
|
|
|
|
{t("deleteProvider")}
|
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
isEnabled={value === "true"}
|
|
|
|
onToggle={(value) => {
|
|
|
|
if (!value) {
|
|
|
|
toggleDisableDialog();
|
|
|
|
} else {
|
|
|
|
onChange("" + value);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2021-02-08 20:50:03 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2020-12-16 07:02:41 +00:00
|
|
|
export const UserFederationLdapSettings = () => {
|
2020-10-30 20:15:37 +00:00
|
|
|
const { t } = useTranslation("user-federation");
|
2021-01-26 01:41:14 +00:00
|
|
|
const form = useForm<ComponentRepresentation>();
|
|
|
|
const history = useHistory();
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { realm } = useRealm();
|
|
|
|
|
|
|
|
const { id } = useParams<{ id: string }>();
|
|
|
|
const { addAlert } = useAlerts();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
2021-02-22 14:52:49 +00:00
|
|
|
if (id !== "new") {
|
|
|
|
const fetchedComponent = await adminClient.components.findOne({ id });
|
|
|
|
if (fetchedComponent) {
|
|
|
|
setupForm(fetchedComponent);
|
|
|
|
}
|
2021-01-26 01:41:14 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const setupForm = (component: ComponentRepresentation) => {
|
|
|
|
Object.entries(component).map((entry) => {
|
|
|
|
if (entry[0] === "config") {
|
|
|
|
convertToFormValues(entry[1], "config", form.setValue);
|
|
|
|
} else {
|
|
|
|
form.setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const save = async (component: ComponentRepresentation) => {
|
|
|
|
try {
|
2021-02-19 23:13:07 +00:00
|
|
|
if (id) {
|
|
|
|
if (id === "new") {
|
|
|
|
await adminClient.components.create(component);
|
|
|
|
} else {
|
|
|
|
await adminClient.components.update({ id }, component);
|
|
|
|
}
|
|
|
|
}
|
2021-01-26 01:41:14 +00:00
|
|
|
setupForm(component as ComponentRepresentation);
|
2021-02-19 23:13:07 +00:00
|
|
|
addAlert(
|
|
|
|
t(id === "new" ? "createSuccess" : "saveSuccess"),
|
|
|
|
AlertVariant.success
|
|
|
|
);
|
2021-01-26 01:41:14 +00:00
|
|
|
} catch (error) {
|
2021-02-19 23:13:07 +00:00
|
|
|
addAlert(
|
|
|
|
`${t(id === "new" ? "createError" : "saveError")} '${error}'`,
|
|
|
|
AlertVariant.danger
|
|
|
|
);
|
2021-01-26 01:41:14 +00:00
|
|
|
}
|
|
|
|
};
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2021-02-08 20:50:03 +00:00
|
|
|
const [toggleRemoveUsersDialog, RemoveUsersConfirm] = useConfirmDialog({
|
|
|
|
titleKey: t("removeImportedUsers"),
|
|
|
|
messageKey: t("removeImportedUsersMessage"),
|
|
|
|
continueButtonLabel: "common:remove",
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
|
|
|
console.log("Remove imported TBD");
|
|
|
|
// TODO await remove imported users command
|
|
|
|
addAlert(t("removeImportedUsersSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(t("removeImportedUsersError", { error }), AlertVariant.danger);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "user-federation:userFedDeleteConfirmTitle",
|
|
|
|
messageKey: "user-federation:userFedDeleteConfirm",
|
|
|
|
continueButtonLabel: "common:delete",
|
|
|
|
continueButtonVariant: ButtonVariant.danger,
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
|
|
|
await adminClient.components.del({ id });
|
|
|
|
addAlert(t("userFedDeletedSuccess"), AlertVariant.success);
|
|
|
|
history.replace(`/${realm}/user-federation`);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(`${t("userFedDeleteError")} ${error}`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-02-08 20:50:03 +00:00
|
|
|
<DeleteConfirm />
|
|
|
|
<RemoveUsersConfirm />
|
|
|
|
<Controller
|
|
|
|
name="config.enabled[0]"
|
2021-02-19 23:13:07 +00:00
|
|
|
defaultValue={["true"][0]}
|
2021-02-08 20:50:03 +00:00
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<LdapSettingsHeader
|
|
|
|
value={value}
|
|
|
|
save={() => save(form.getValues())}
|
|
|
|
onChange={onChange}
|
|
|
|
toggleDeleteDialog={toggleDeleteDialog}
|
|
|
|
toggleRemoveUsersDialog={toggleRemoveUsersDialog}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
<PageSection variant="light" isFilled>
|
|
|
|
<ScrollForm
|
|
|
|
sections={[
|
|
|
|
t("generalOptions"),
|
|
|
|
t("connectionAndAuthenticationSettings"),
|
|
|
|
t("ldapSearchingAndUpdatingSettings"),
|
|
|
|
t("synchronizationSettings"),
|
|
|
|
t("kerberosIntegration"),
|
|
|
|
t("cacheSettings"),
|
|
|
|
t("advancedSettings"),
|
|
|
|
]}
|
|
|
|
>
|
2021-01-26 01:41:14 +00:00
|
|
|
<LdapSettingsGeneral form={form} />
|
|
|
|
<LdapSettingsConnection form={form} />
|
|
|
|
<LdapSettingsSearching form={form} />
|
|
|
|
<LdapSettingsSynchronization form={form} />
|
|
|
|
<LdapSettingsKerberosIntegration form={form} />
|
2021-02-11 20:51:51 +00:00
|
|
|
<SettingsCache form={form} />
|
2021-01-26 01:41:14 +00:00
|
|
|
<LdapSettingsAdvanced form={form} />
|
2020-10-30 20:15:37 +00:00
|
|
|
</ScrollForm>
|
2021-01-26 01:41:14 +00:00
|
|
|
<Form onSubmit={form.handleSubmit(save)}>
|
|
|
|
<ActionGroup>
|
|
|
|
<Button variant="primary" type="submit">
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
onClick={() => history.push(`/${realm}/user-federation`)}
|
|
|
|
>
|
|
|
|
{t("common:cancel")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</Form>
|
2020-10-30 20:15:37 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|