2021-09-02 20:14:43 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
AlertVariant,
|
|
|
|
ButtonVariant,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownSeparator,
|
|
|
|
PageSection,
|
|
|
|
Tab,
|
|
|
|
TabTitleText,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
|
|
|
|
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
2022-01-14 10:05:50 +00:00
|
|
|
import {
|
|
|
|
routableTab,
|
|
|
|
RoutableTabs,
|
|
|
|
} from "../components/routable-tabs/RoutableTabs";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2021-11-11 16:04:04 +00:00
|
|
|
import { useRealms } from "../context/RealmsContext";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import {
|
|
|
|
convertFormValuesToObject,
|
|
|
|
convertToFormValues,
|
|
|
|
toUpperCase,
|
|
|
|
} from "../util";
|
|
|
|
|
|
|
|
import { RealmSettingsEmailTab } from "./EmailTab";
|
|
|
|
import { EventsTab } from "./event-config/EventsTab";
|
|
|
|
import { RealmSettingsGeneralTab } from "./GeneralTab";
|
|
|
|
import { RealmSettingsLoginTab } from "./LoginTab";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { SecurityDefenses } from "./security-defences/SecurityDefenses";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { RealmSettingsSessionsTab } from "./SessionsTab";
|
|
|
|
import { RealmSettingsThemesTab } from "./ThemesTab";
|
|
|
|
import { RealmSettingsTokensTab } from "./TokensTab";
|
2021-10-29 16:11:06 +00:00
|
|
|
import ProfilesTab from "./ProfilesTab";
|
2021-09-09 10:45:19 +00:00
|
|
|
import { PoliciesTab } from "./PoliciesTab";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { PartialImportDialog } from "./PartialImport";
|
2021-10-29 02:50:25 +00:00
|
|
|
import { PartialExportDialog } from "./PartialExport";
|
2022-01-31 07:19:44 +00:00
|
|
|
import { RealmSettingsTab, toRealmSettings } from "./routes/RealmSettings";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { LocalizationTab } from "./LocalizationTab";
|
2021-09-09 10:45:19 +00:00
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
2021-11-16 11:10:10 +00:00
|
|
|
import { UserRegistration } from "./UserRegistration";
|
2021-11-11 16:04:04 +00:00
|
|
|
import { toDashboard } from "../dashboard/routes/Dashboard";
|
|
|
|
import environment from "../environment";
|
2021-12-21 15:32:53 +00:00
|
|
|
import helpUrls from "../help-urls";
|
2022-01-03 15:00:03 +00:00
|
|
|
import { UserProfileTab } from "./user-profile/UserProfileTab";
|
|
|
|
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
|
2022-01-31 07:19:44 +00:00
|
|
|
import { ClientPoliciesTab, toClientPolicies } from "./routes/ClientPolicies";
|
2022-02-28 15:22:00 +00:00
|
|
|
import { KeysTab } from "./keys/KeysTab";
|
2022-06-15 12:57:39 +00:00
|
|
|
import type { KeyValueType } from "../components/key-value-form/key-value-convert";
|
2021-09-02 20:14:43 +00:00
|
|
|
|
|
|
|
type RealmSettingsHeaderProps = {
|
|
|
|
onChange: (value: boolean) => void;
|
|
|
|
value: boolean;
|
|
|
|
save: () => void;
|
|
|
|
realmName: string;
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh: () => void;
|
2021-09-02 20:14:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const RealmSettingsHeader = ({
|
|
|
|
save,
|
|
|
|
onChange,
|
|
|
|
value,
|
|
|
|
realmName,
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh,
|
2021-09-02 20:14:43 +00:00
|
|
|
}: RealmSettingsHeaderProps) => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const adminClient = useAdminClient();
|
2021-11-11 16:04:04 +00:00
|
|
|
const { refresh: refreshRealms } = useRealms();
|
2021-09-02 20:14:43 +00:00
|
|
|
const { addAlert, addError } = useAlerts();
|
|
|
|
const history = useHistory();
|
|
|
|
const [partialImportOpen, setPartialImportOpen] = useState(false);
|
2021-10-29 02:50:25 +00:00
|
|
|
const [partialExportOpen, setPartialExportOpen] = useState(false);
|
2021-09-02 20:14:43 +00:00
|
|
|
|
|
|
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "realm-settings:disableConfirmTitle",
|
|
|
|
messageKey: "realm-settings:disableConfirm",
|
|
|
|
continueButtonLabel: "common:disable",
|
|
|
|
onConfirm: () => {
|
|
|
|
onChange(!value);
|
|
|
|
save();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "realm-settings:deleteConfirmTitle",
|
|
|
|
messageKey: "realm-settings:deleteConfirm",
|
|
|
|
continueButtonLabel: "common:delete",
|
|
|
|
continueButtonVariant: ButtonVariant.danger,
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
|
|
|
await adminClient.realms.del({ realm: realmName });
|
|
|
|
addAlert(t("deletedSuccess"), AlertVariant.success);
|
2021-11-11 16:04:04 +00:00
|
|
|
await refreshRealms();
|
|
|
|
history.push(toDashboard({ realm: environment.masterRealm }));
|
2021-09-02 20:14:43 +00:00
|
|
|
refresh();
|
|
|
|
} catch (error) {
|
|
|
|
addError("realm-settings:deleteError", error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DisableConfirm />
|
|
|
|
<DeleteConfirm />
|
|
|
|
<PartialImportDialog
|
|
|
|
open={partialImportOpen}
|
|
|
|
toggleDialog={() => setPartialImportOpen(!partialImportOpen)}
|
|
|
|
/>
|
2021-10-29 02:50:25 +00:00
|
|
|
<PartialExportDialog
|
|
|
|
isOpen={partialExportOpen}
|
|
|
|
onClose={() => setPartialExportOpen(false)}
|
|
|
|
/>
|
2021-09-02 20:14:43 +00:00
|
|
|
<ViewHeader
|
|
|
|
titleKey={toUpperCase(realmName)}
|
2021-12-21 15:32:53 +00:00
|
|
|
subKey="realm-settings:realmSettingsExplain"
|
|
|
|
helpUrl={helpUrls.realmSettingsUrl}
|
2021-09-02 20:14:43 +00:00
|
|
|
divider={false}
|
|
|
|
dropdownItems={[
|
|
|
|
<DropdownItem
|
|
|
|
key="import"
|
|
|
|
data-testid="openPartialImportModal"
|
|
|
|
onClick={() => {
|
|
|
|
setPartialImportOpen(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t("partialImport")}
|
|
|
|
</DropdownItem>,
|
2021-10-29 02:50:25 +00:00
|
|
|
<DropdownItem
|
|
|
|
key="export"
|
|
|
|
data-testid="openPartialExportModal"
|
|
|
|
onClick={() => setPartialExportOpen(true)}
|
|
|
|
>
|
|
|
|
{t("partialExport")}
|
|
|
|
</DropdownItem>,
|
2021-09-02 20:14:43 +00:00
|
|
|
<DropdownSeparator key="separator" />,
|
|
|
|
<DropdownItem key="delete" onClick={toggleDeleteDialog}>
|
|
|
|
{t("common:delete")}
|
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
isEnabled={value}
|
|
|
|
onToggle={(value) => {
|
|
|
|
if (!value) {
|
|
|
|
toggleDisableDialog();
|
|
|
|
} else {
|
|
|
|
onChange(value);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type RealmSettingsTabsProps = {
|
|
|
|
realm: RealmRepresentation;
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh: () => void;
|
2021-09-02 20:14:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsTabs = ({
|
|
|
|
realm,
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh,
|
2021-09-02 20:14:43 +00:00
|
|
|
}: RealmSettingsTabsProps) => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { addAlert, addError } = useAlerts();
|
2021-11-11 16:04:04 +00:00
|
|
|
const { realm: realmName } = useRealm();
|
|
|
|
const { refresh: refreshRealms } = useRealms();
|
2021-09-02 20:14:43 +00:00
|
|
|
const history = useHistory();
|
2022-01-03 15:00:03 +00:00
|
|
|
const isFeatureEnabled = useIsFeatureEnabled();
|
2021-09-02 20:14:43 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const { control, setValue, getValues } = useForm({
|
|
|
|
mode: "onChange",
|
|
|
|
shouldUnregister: false,
|
|
|
|
});
|
2021-09-02 20:14:43 +00:00
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
|
2021-09-27 17:15:36 +00:00
|
|
|
const refreshHeader = () => {
|
2022-06-15 12:57:39 +00:00
|
|
|
setKey(key + 1);
|
2021-09-02 20:14:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const setupForm = (r: RealmRepresentation = realm) => {
|
2021-12-08 15:08:42 +00:00
|
|
|
convertToFormValues(r, setValue);
|
2021-09-02 20:14:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
useEffect(setupForm, []);
|
2021-09-02 20:14:43 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const save = async (r: RealmRepresentation) => {
|
|
|
|
r = convertFormValuesToObject(r);
|
|
|
|
if (
|
|
|
|
r.attributes?.["acr.loa.map"] &&
|
|
|
|
typeof r.attributes["acr.loa.map"] !== "string"
|
|
|
|
) {
|
|
|
|
const map = JSON.stringify(
|
|
|
|
Object.fromEntries(
|
|
|
|
(r.attributes["acr.loa.map"] as KeyValueType[])
|
|
|
|
.filter(({ key }) => key !== "")
|
|
|
|
.map(({ key, value }) => [key, value])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
r.attributes["acr.loa.map"] = map !== "{}" ? map : "[]";
|
|
|
|
}
|
2021-09-27 17:15:36 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
try {
|
2021-09-02 20:14:43 +00:00
|
|
|
await adminClient.realms.update(
|
|
|
|
{ realm: realmName },
|
2021-09-27 17:15:36 +00:00
|
|
|
{
|
|
|
|
...realm,
|
2022-06-15 12:57:39 +00:00
|
|
|
...r,
|
|
|
|
id: r.realm,
|
2021-09-27 17:15:36 +00:00
|
|
|
}
|
2021-09-02 20:14:43 +00:00
|
|
|
);
|
|
|
|
addAlert(t("saveSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addError("realm-settings:saveError", error);
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const isRealmRenamed = realmName !== (r.realm || realm.realm);
|
|
|
|
if (isRealmRenamed) {
|
|
|
|
await refreshRealms();
|
|
|
|
history.push(toRealmSettings({ realm: r.realm!, tab: "general" }));
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
};
|
2022-01-03 15:00:03 +00:00
|
|
|
|
2022-01-31 07:19:44 +00:00
|
|
|
const route = (tab: RealmSettingsTab | undefined = "general") =>
|
|
|
|
routableTab({
|
|
|
|
to: toRealmSettings({ realm: realmName, tab }),
|
|
|
|
history,
|
|
|
|
});
|
|
|
|
|
|
|
|
const policiesRoute = (tab: ClientPoliciesTab) =>
|
|
|
|
routableTab({
|
|
|
|
to: toClientPolicies({
|
|
|
|
realm: realmName,
|
|
|
|
tab,
|
|
|
|
}),
|
|
|
|
history,
|
|
|
|
});
|
|
|
|
|
2021-09-02 20:14:43 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Controller
|
|
|
|
name="enabled"
|
|
|
|
defaultValue={true}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<RealmSettingsHeader
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
realmName={realmName}
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh={refreshHeader}
|
2021-09-02 20:14:43 +00:00
|
|
|
save={() => save(getValues())}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
2022-06-15 12:57:39 +00:00
|
|
|
<RoutableTabs
|
|
|
|
isBox
|
|
|
|
mountOnEnter
|
|
|
|
defaultLocation={toRealmSettings({
|
|
|
|
realm: realmName,
|
|
|
|
tab: "general",
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("general")}</TabTitleText>}
|
|
|
|
data-testid="rs-general-tab"
|
|
|
|
{...route()}
|
2022-01-31 07:19:44 +00:00
|
|
|
>
|
2022-06-15 12:57:39 +00:00
|
|
|
<RealmSettingsGeneralTab realm={realm} save={save} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("login")}</TabTitleText>}
|
|
|
|
data-testid="rs-login-tab"
|
|
|
|
{...route("login")}
|
|
|
|
>
|
|
|
|
<RealmSettingsLoginTab refresh={refresh} realm={realm} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("email")}</TabTitleText>}
|
|
|
|
data-testid="rs-email-tab"
|
|
|
|
{...route("email")}
|
|
|
|
>
|
|
|
|
<RealmSettingsEmailTab realm={realm} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("themes")}</TabTitleText>}
|
|
|
|
data-testid="rs-themes-tab"
|
|
|
|
{...route("themes")}
|
|
|
|
>
|
|
|
|
<RealmSettingsThemesTab realm={realm} save={save} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("realm-settings:keys")}</TabTitleText>}
|
|
|
|
data-testid="rs-keys-tab"
|
|
|
|
{...route("keys")}
|
|
|
|
>
|
|
|
|
<KeysTab />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("events")}</TabTitleText>}
|
|
|
|
data-testid="rs-realm-events-tab"
|
|
|
|
{...route("events")}
|
|
|
|
>
|
|
|
|
<EventsTab />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("localization")}</TabTitleText>}
|
|
|
|
data-testid="rs-localization-tab"
|
|
|
|
{...route("localization")}
|
|
|
|
>
|
|
|
|
<LocalizationTab
|
|
|
|
key={key}
|
|
|
|
refresh={refresh}
|
|
|
|
save={save}
|
|
|
|
realm={realm}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("securityDefences")}</TabTitleText>}
|
|
|
|
data-testid="rs-security-defenses-tab"
|
2022-06-22 11:35:10 +00:00
|
|
|
{...route("security-defenses")}
|
2022-06-15 12:57:39 +00:00
|
|
|
>
|
|
|
|
<SecurityDefenses realm={realm} save={save} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("realm-settings:sessions")}</TabTitleText>}
|
|
|
|
data-testid="rs-sessions-tab"
|
|
|
|
{...route("sessions")}
|
|
|
|
>
|
|
|
|
<RealmSettingsSessionsTab key={key} realm={realm} save={save} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("realm-settings:tokens")}</TabTitleText>}
|
|
|
|
data-testid="rs-tokens-tab"
|
|
|
|
{...route("tokens")}
|
|
|
|
>
|
|
|
|
<RealmSettingsTokensTab save={save} realm={realm} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
title={
|
|
|
|
<TabTitleText>{t("realm-settings:clientPolicies")}</TabTitleText>
|
|
|
|
}
|
|
|
|
data-testid="rs-clientPolicies-tab"
|
2022-06-22 11:35:10 +00:00
|
|
|
{...route("client-policies")}
|
2022-06-15 12:57:39 +00:00
|
|
|
>
|
|
|
|
<RoutableTabs
|
|
|
|
mountOnEnter
|
|
|
|
defaultLocation={toClientPolicies({
|
|
|
|
realm: realmName,
|
|
|
|
tab: "profiles",
|
|
|
|
})}
|
2021-09-09 10:45:19 +00:00
|
|
|
>
|
2022-06-15 12:57:39 +00:00
|
|
|
<Tab
|
|
|
|
data-testid="rs-policies-clientProfiles-tab"
|
|
|
|
aria-label={t("clientProfilesSubTab")}
|
|
|
|
title={
|
|
|
|
<TabTitleText>
|
|
|
|
{t("profiles")}
|
|
|
|
<span className="kc-help-text">
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings:clientPoliciesProfilesHelpText"
|
|
|
|
fieldLabelId="realm-settings:clientPoliciesProfiles"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</TabTitleText>
|
|
|
|
}
|
|
|
|
{...policiesRoute("profiles")}
|
2021-09-09 10:45:19 +00:00
|
|
|
>
|
2022-06-15 12:57:39 +00:00
|
|
|
<ProfilesTab />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="policies"
|
|
|
|
data-testid="rs-policies-clientPolicies-tab"
|
|
|
|
aria-label={t("clientPoliciesSubTab")}
|
|
|
|
{...policiesRoute("policies")}
|
|
|
|
title={
|
|
|
|
<TabTitleText>
|
|
|
|
{t("policies")}
|
|
|
|
<span className="kc-help-text">
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings:clientPoliciesPoliciesHelpText"
|
|
|
|
fieldLabelId="realm-settings:clientPoliciesPolicies"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</TabTitleText>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<PoliciesTab />
|
|
|
|
</Tab>
|
|
|
|
</RoutableTabs>
|
|
|
|
</Tab>
|
|
|
|
{isFeatureEnabled(Feature.DeclarativeUserProfile) &&
|
|
|
|
realm.attributes?.userProfileEnabled === "true" && (
|
|
|
|
<Tab
|
|
|
|
title={
|
|
|
|
<TabTitleText>{t("realm-settings:userProfile")}</TabTitleText>
|
|
|
|
}
|
|
|
|
data-testid="rs-user-profile-tab"
|
2022-06-22 11:35:10 +00:00
|
|
|
{...route("user-profile")}
|
2022-06-15 12:57:39 +00:00
|
|
|
>
|
|
|
|
<UserProfileTab />
|
|
|
|
</Tab>
|
|
|
|
)}
|
|
|
|
<Tab
|
|
|
|
title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
|
|
|
|
data-testid="rs-userRegistration-tab"
|
2022-06-22 11:35:10 +00:00
|
|
|
{...route("user-registration")}
|
2022-06-15 12:57:39 +00:00
|
|
|
>
|
|
|
|
<UserRegistration />
|
|
|
|
</Tab>
|
|
|
|
</RoutableTabs>
|
2021-09-02 20:14:43 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|