2021-09-02 20:14:43 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
import { Controller, FormProvider, useForm } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
AlertVariant,
|
|
|
|
ButtonVariant,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownSeparator,
|
|
|
|
PageSection,
|
|
|
|
Tab,
|
|
|
|
Tabs,
|
|
|
|
TabTitleText,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
|
|
|
import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
|
|
|
|
|
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
|
|
|
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
|
|
|
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 { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import {
|
|
|
|
convertFormValuesToObject,
|
|
|
|
convertToFormValues,
|
|
|
|
KEY_PROVIDER_TYPE,
|
|
|
|
toUpperCase,
|
|
|
|
} from "../util";
|
|
|
|
|
|
|
|
import { RealmSettingsEmailTab } from "./EmailTab";
|
|
|
|
import { EventsTab } from "./event-config/EventsTab";
|
|
|
|
import { RealmSettingsGeneralTab } from "./GeneralTab";
|
|
|
|
import { KeysListTab } from "./KeysListTab";
|
|
|
|
import { KeysProvidersTab } from "./KeysProvidersTab";
|
|
|
|
import { RealmSettingsLoginTab } from "./LoginTab";
|
|
|
|
import { SecurityDefences } from "./security-defences/SecurityDefences";
|
|
|
|
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";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { toRealmSettings } from "./routes/RealmSettings";
|
|
|
|
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-11-12 15:04:05 +00:00
|
|
|
import { UserProfileTab } from "./UserProfileTab";
|
2021-12-21 15:32:53 +00:00
|
|
|
import helpUrls from "../help-urls";
|
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
|
|
|
realmComponents: ComponentRepresentation[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsTabs = ({
|
|
|
|
realm,
|
|
|
|
realmComponents,
|
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();
|
|
|
|
|
|
|
|
const kpComponentTypes =
|
|
|
|
useServerInfo().componentTypes?.[KEY_PROVIDER_TYPE] ?? [];
|
|
|
|
|
2021-11-03 19:47:42 +00:00
|
|
|
const form = useForm({ mode: "onChange", shouldUnregister: false });
|
2021-09-02 20:14:43 +00:00
|
|
|
const { control, getValues, setValue, reset: resetForm } = form;
|
|
|
|
|
|
|
|
const [activeTab, setActiveTab] = useState(0);
|
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
|
2021-09-27 17:15:36 +00:00
|
|
|
const refreshHeader = () => {
|
2021-09-02 20:14:43 +00:00
|
|
|
setKey(new Date().getTime());
|
|
|
|
};
|
|
|
|
|
|
|
|
const setupForm = (r: RealmRepresentation = realm) => {
|
2021-12-08 15:08:42 +00:00
|
|
|
convertToFormValues(r, setValue);
|
2021-09-02 20:14:43 +00:00
|
|
|
resetForm(getValues());
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setupForm();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const save = async (realm: RealmRepresentation) => {
|
|
|
|
try {
|
2021-12-08 15:08:42 +00:00
|
|
|
realm = convertFormValuesToObject(realm);
|
2021-09-27 17:15:36 +00:00
|
|
|
|
2021-09-02 20:14:43 +00:00
|
|
|
await adminClient.realms.update(
|
|
|
|
{ realm: realmName },
|
2021-09-27 17:15:36 +00:00
|
|
|
{
|
|
|
|
...realm,
|
|
|
|
id: realmName,
|
|
|
|
}
|
2021-09-02 20:14:43 +00:00
|
|
|
);
|
|
|
|
setupForm(realm);
|
|
|
|
const isRealmRenamed = realmName !== realm.realm;
|
|
|
|
if (isRealmRenamed) {
|
2021-11-11 16:04:04 +00:00
|
|
|
await refreshRealms();
|
2021-09-02 20:14:43 +00:00
|
|
|
history.push(toRealmSettings({ realm: realm.realm! }));
|
|
|
|
}
|
|
|
|
addAlert(t("saveSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addError("realm-settings:saveError", error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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">
|
|
|
|
<FormProvider {...form}>
|
|
|
|
<KeycloakTabs isBox>
|
|
|
|
<Tab
|
|
|
|
eventKey="general"
|
|
|
|
title={<TabTitleText>{t("general")}</TabTitleText>}
|
|
|
|
data-testid="rs-general-tab"
|
|
|
|
aria-label="general-tab"
|
|
|
|
>
|
|
|
|
<RealmSettingsGeneralTab
|
|
|
|
save={save}
|
|
|
|
reset={() => resetForm(realm)}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
eventKey="login"
|
|
|
|
title={<TabTitleText>{t("login")}</TabTitleText>}
|
|
|
|
data-testid="rs-login-tab"
|
|
|
|
aria-label="login-tab"
|
|
|
|
>
|
2021-09-27 17:15:36 +00:00
|
|
|
<RealmSettingsLoginTab
|
|
|
|
refresh={refresh}
|
|
|
|
save={save}
|
|
|
|
realm={realm}
|
|
|
|
/>
|
2021-09-02 20:14:43 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
eventKey="email"
|
|
|
|
title={<TabTitleText>{t("email")}</TabTitleText>}
|
|
|
|
data-testid="rs-email-tab"
|
|
|
|
aria-label="email-tab"
|
|
|
|
>
|
2021-10-14 21:08:42 +00:00
|
|
|
<RealmSettingsEmailTab realm={realm} />
|
2021-09-02 20:14:43 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
eventKey="themes"
|
|
|
|
title={<TabTitleText>{t("themes")}</TabTitleText>}
|
|
|
|
data-testid="rs-themes-tab"
|
|
|
|
aria-label="themes-tab"
|
|
|
|
>
|
|
|
|
<RealmSettingsThemesTab
|
|
|
|
save={save}
|
|
|
|
reset={() => resetForm(realm)}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
eventKey="keys"
|
|
|
|
title={<TabTitleText>{t("realm-settings:keys")}</TabTitleText>}
|
|
|
|
data-testid="rs-keys-tab"
|
|
|
|
aria-label="keys-tab"
|
|
|
|
>
|
|
|
|
<Tabs
|
|
|
|
activeKey={activeTab}
|
|
|
|
onSelect={(_, key) => setActiveTab(Number(key))}
|
|
|
|
>
|
|
|
|
<Tab
|
|
|
|
id="keysList"
|
|
|
|
eventKey={0}
|
|
|
|
data-testid="rs-keys-list-tab"
|
|
|
|
aria-label="keys-list-subtab"
|
|
|
|
title={<TabTitleText>{t("keysList")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<KeysListTab realmComponents={realmComponents} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="providers"
|
|
|
|
data-testid="rs-providers-tab"
|
|
|
|
aria-label="rs-providers-tab"
|
|
|
|
eventKey={1}
|
|
|
|
title={<TabTitleText>{t("providers")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<KeysProvidersTab
|
|
|
|
realmComponents={realmComponents}
|
|
|
|
keyProviderComponentTypes={kpComponentTypes}
|
|
|
|
refresh={refresh}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
eventKey="events"
|
|
|
|
title={<TabTitleText>{t("events")}</TabTitleText>}
|
|
|
|
data-testid="rs-realm-events-tab"
|
|
|
|
aria-label="realm-events-tab"
|
|
|
|
>
|
|
|
|
<EventsTab />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="localization"
|
|
|
|
eventKey="localization"
|
|
|
|
data-testid="rs-localization-tab"
|
|
|
|
title={<TabTitleText>{t("localization")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<LocalizationTab
|
|
|
|
key={key}
|
|
|
|
refresh={refresh}
|
|
|
|
save={save}
|
|
|
|
reset={() => resetForm(realm)}
|
|
|
|
realm={realm}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="securityDefences"
|
|
|
|
eventKey="securityDefences"
|
|
|
|
title={<TabTitleText>{t("securityDefences")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<SecurityDefences save={save} reset={() => resetForm(realm)} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="sessions"
|
|
|
|
eventKey="sessions"
|
|
|
|
data-testid="rs-sessions-tab"
|
|
|
|
aria-label="sessions-tab"
|
|
|
|
title={
|
|
|
|
<TabTitleText>{t("realm-settings:sessions")}</TabTitleText>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<RealmSettingsSessionsTab key={key} realm={realm} save={save} />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="tokens"
|
|
|
|
eventKey="tokens"
|
|
|
|
data-testid="rs-tokens-tab"
|
|
|
|
aria-label="tokens-tab"
|
|
|
|
title={<TabTitleText>{t("realm-settings:tokens")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<RealmSettingsTokensTab
|
|
|
|
save={save}
|
|
|
|
realm={realm}
|
|
|
|
reset={() => resetForm(realm)}
|
|
|
|
/>
|
|
|
|
</Tab>
|
2021-09-09 10:45:19 +00:00
|
|
|
<Tab
|
|
|
|
eventKey="clientPolicies"
|
|
|
|
title={
|
|
|
|
<TabTitleText>
|
|
|
|
{t("realm-settings:clientPolicies")}
|
|
|
|
</TabTitleText>
|
|
|
|
}
|
|
|
|
data-testid="rs-clientPolicies-tab"
|
|
|
|
aria-label={t("clientPoliciesTab")}
|
|
|
|
>
|
|
|
|
<Tabs
|
|
|
|
activeKey={activeTab}
|
|
|
|
onSelect={(_, key) => setActiveTab(Number(key))}
|
|
|
|
>
|
|
|
|
<Tab
|
|
|
|
id="profiles"
|
|
|
|
eventKey={0}
|
2021-10-12 15:03:56 +00:00
|
|
|
data-testid="rs-policies-clientProfiles-tab"
|
2021-09-09 10:45:19 +00:00
|
|
|
aria-label={t("clientProfilesSubTab")}
|
|
|
|
title={
|
|
|
|
<TabTitleText>
|
|
|
|
{t("profiles")}
|
|
|
|
<span className="kc-help-text">
|
|
|
|
<HelpItem
|
2021-12-14 14:56:36 +00:00
|
|
|
helpText="realm-settings:clientPoliciesProfilesHelpText"
|
|
|
|
fieldLabelId="realm-settings:clientPoliciesProfiles"
|
2021-09-09 10:45:19 +00:00
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</TabTitleText>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ProfilesTab />
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="policies"
|
|
|
|
data-testid="rs-policies-clientPolicies-tab"
|
|
|
|
aria-label={t("clientPoliciesSubTab")}
|
|
|
|
eventKey={1}
|
|
|
|
title={
|
|
|
|
<TabTitleText>
|
|
|
|
{t("policies")}
|
|
|
|
<span className="kc-help-text">
|
|
|
|
<HelpItem
|
2021-12-14 14:56:36 +00:00
|
|
|
helpText="realm-settings:clientPoliciesPoliciesHelpText"
|
|
|
|
fieldLabelId="realm-settings:clientPoliciesPolicies"
|
2021-09-09 10:45:19 +00:00
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</TabTitleText>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<PoliciesTab />
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</Tab>
|
2021-11-12 15:04:05 +00:00
|
|
|
<Tab
|
|
|
|
eventKey="userProfile"
|
|
|
|
data-testid="rs-user-profile-tab"
|
|
|
|
title={
|
|
|
|
<TabTitleText>{t("realm-settings:userProfile")}</TabTitleText>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<UserProfileTab />
|
|
|
|
</Tab>
|
2021-11-16 11:10:10 +00:00
|
|
|
<Tab
|
|
|
|
eventKey="userRegistration"
|
|
|
|
title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
|
|
|
|
data-testid="rs-userRegistration-tab"
|
|
|
|
aria-label={t("userRegistrationTab")}
|
|
|
|
>
|
|
|
|
<UserRegistration />
|
|
|
|
</Tab>
|
2021-09-02 20:14:43 +00:00
|
|
|
</KeycloakTabs>
|
|
|
|
</FormProvider>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|