2022-08-03 12:12:07 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2021-04-19 11:41:07 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { Controller, FormProvider, useForm } from "react-hook-form";
|
2021-04-19 11:41:07 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
ClipboardCopy,
|
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Stack,
|
|
|
|
StackItem,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
2021-08-26 08:39:35 +00:00
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2022-08-09 08:32:16 +00:00
|
|
|
import {
|
|
|
|
addTrailingSlash,
|
|
|
|
convertAttributeNameToForm,
|
|
|
|
convertToFormValues,
|
|
|
|
} from "../util";
|
2022-01-03 15:00:03 +00:00
|
|
|
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
|
2021-04-30 19:08:12 +00:00
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
2021-04-19 11:41:07 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
|
|
|
import { FormattedLink } from "../components/external-link/FormattedLink";
|
2022-04-21 15:03:26 +00:00
|
|
|
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { KeyValueInput } from "../components/key-value-form/KeyValueInput";
|
2021-04-19 11:41:07 +00:00
|
|
|
|
2021-04-30 19:08:12 +00:00
|
|
|
type RealmSettingsGeneralTabProps = {
|
2022-06-15 12:57:39 +00:00
|
|
|
realm: RealmRepresentation;
|
2021-04-30 19:08:12 +00:00
|
|
|
save: (realm: RealmRepresentation) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsGeneralTab = ({
|
2022-06-15 12:57:39 +00:00
|
|
|
realm,
|
2021-04-30 19:08:12 +00:00
|
|
|
save,
|
|
|
|
}: RealmSettingsGeneralTabProps) => {
|
2021-04-19 11:41:07 +00:00
|
|
|
const { t } = useTranslation("realm-settings");
|
2022-07-14 13:02:28 +00:00
|
|
|
const { adminClient } = useAdminClient();
|
2021-04-19 11:41:07 +00:00
|
|
|
const { realm: realmName } = useRealm();
|
2022-06-15 12:57:39 +00:00
|
|
|
const form = useForm<RealmRepresentation>({ shouldUnregister: false });
|
2021-07-09 14:23:49 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
control,
|
|
|
|
handleSubmit,
|
2022-06-15 12:57:39 +00:00
|
|
|
setValue,
|
2021-07-09 14:23:49 +00:00
|
|
|
formState: { isDirty },
|
2022-06-15 12:57:39 +00:00
|
|
|
} = form;
|
2022-01-03 15:00:03 +00:00
|
|
|
const isFeatureEnabled = useIsFeatureEnabled();
|
2021-04-19 11:41:07 +00:00
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
const requireSslTypes = ["all", "external", "none"];
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const setupForm = () => {
|
|
|
|
convertToFormValues(realm, setValue);
|
|
|
|
if (realm.attributes?.["acr.loa.map"]) {
|
|
|
|
const result = Object.entries(
|
|
|
|
JSON.parse(realm.attributes["acr.loa.map"])
|
|
|
|
).flatMap(([key, value]) => ({ key, value }));
|
|
|
|
result.concat({ key: "", value: "" });
|
2022-08-09 08:32:16 +00:00
|
|
|
setValue(convertAttributeNameToForm("attributes.acr.loa.map"), result);
|
2022-06-15 12:57:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(setupForm, []);
|
|
|
|
|
2021-04-19 11:41:07 +00:00
|
|
|
return (
|
2021-08-26 12:15:28 +00:00
|
|
|
<PageSection variant="light">
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
|
|
|
>
|
|
|
|
<FormGroup label={t("realmId")} fieldId="kc-realm-id" isRequired>
|
|
|
|
<Controller
|
|
|
|
name="realm"
|
|
|
|
control={control}
|
|
|
|
defaultValue=""
|
|
|
|
render={({ onChange, value }) => (
|
2022-04-05 19:34:21 +00:00
|
|
|
<ClipboardCopy data-testid="realmName" onChange={onChange}>
|
|
|
|
{value}
|
|
|
|
</ClipboardCopy>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup label={t("displayName")} fieldId="kc-display-name">
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-08-26 12:15:28 +00:00
|
|
|
type="text"
|
|
|
|
id="kc-display-name"
|
|
|
|
name="displayName"
|
|
|
|
ref={register}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup label={t("htmlDisplayName")} fieldId="kc-html-display-name">
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-08-26 12:15:28 +00:00
|
|
|
type="text"
|
|
|
|
id="kc-html-display-name"
|
|
|
|
name="displayNameHtml"
|
|
|
|
ref={register}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("frontendUrl")}
|
|
|
|
fieldId="kc-frontend-url"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:frontendUrl"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:frontendUrl"
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-08-26 12:15:28 +00:00
|
|
|
type="text"
|
|
|
|
id="kc-frontend-url"
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.frontendUrl")}
|
2021-08-26 12:15:28 +00:00
|
|
|
ref={register}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("requireSsl")}
|
|
|
|
fieldId="kc-require-ssl"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:requireSsl"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:requireSsl"
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="sslRequired"
|
|
|
|
defaultValue="none"
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-require-ssl"
|
|
|
|
onToggle={() => setOpen(!open)}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("requireSsl")}
|
|
|
|
isOpen={open}
|
|
|
|
>
|
|
|
|
{requireSslTypes.map((sslType) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={sslType === value}
|
|
|
|
key={sslType}
|
|
|
|
value={sslType}
|
|
|
|
>
|
|
|
|
{t(`sslType.${sslType}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-06-15 12:57:39 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("clients:acrToLoAMapping")}
|
|
|
|
fieldId="acrToLoAMapping"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:acrToLoAMapping"
|
|
|
|
fieldLabelId="clients:acrToLoAMapping"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<FormProvider {...form}>
|
2022-08-09 08:32:16 +00:00
|
|
|
<KeyValueInput
|
|
|
|
name={convertAttributeNameToForm("attributes.acr.loa.map")}
|
|
|
|
/>
|
2022-06-15 12:57:39 +00:00
|
|
|
</FormProvider>
|
|
|
|
</FormGroup>
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("userManagedAccess")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:userManagedAccess"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:userManagedAccess"
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
2022-03-28 15:34:07 +00:00
|
|
|
fieldId="kc-user-managed-access"
|
2021-08-26 12:15:28 +00:00
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="userManagedAccessAllowed"
|
|
|
|
control={control}
|
|
|
|
defaultValue={false}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-user-managed-access"
|
|
|
|
data-testid="user-managed-access-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("userManagedAccess")}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-01-03 15:00:03 +00:00
|
|
|
{isFeatureEnabled(Feature.DeclarativeUserProfile) && (
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("userProfileEnabled")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:userProfileEnabled"
|
|
|
|
fieldLabelId="realm-settings:userProfileEnabled"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-user-profile-enabled"
|
|
|
|
>
|
|
|
|
<Controller
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm("attributes.userProfileEnabled")}
|
2022-01-03 15:00:03 +00:00
|
|
|
control={control}
|
|
|
|
defaultValue={false}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-user-profile-enabled"
|
|
|
|
data-testid="user-profile-enabled-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange(value.toString())}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("userProfileEnabled")}
|
2022-01-03 15:00:03 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("endpoints")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:endpoints"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:endpoints"
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
fieldId="kc-endpoints"
|
|
|
|
>
|
|
|
|
<Stack>
|
|
|
|
<StackItem>
|
|
|
|
<FormattedLink
|
2022-07-14 13:02:28 +00:00
|
|
|
href={`${addTrailingSlash(
|
|
|
|
adminClient.baseUrl
|
|
|
|
)}realms/${realmName}/.well-known/openid-configuration`}
|
2021-08-26 12:15:28 +00:00
|
|
|
title={t("openIDEndpointConfiguration")}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
</StackItem>
|
|
|
|
<StackItem>
|
|
|
|
<FormattedLink
|
2022-07-14 13:02:28 +00:00
|
|
|
href={`${addTrailingSlash(
|
|
|
|
adminClient.baseUrl
|
|
|
|
)}realms/${realmName}/protocol/saml/descriptor`}
|
2021-08-26 12:15:28 +00:00
|
|
|
title={t("samlIdentityProviderMetadata")}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
</StackItem>
|
|
|
|
</Stack>
|
|
|
|
</FormGroup>
|
2021-04-19 11:41:07 +00:00
|
|
|
|
2021-08-26 12:15:28 +00:00
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
type="submit"
|
|
|
|
data-testid="general-tab-save"
|
|
|
|
isDisabled={!isDirty}
|
|
|
|
>
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
2022-04-05 19:34:21 +00:00
|
|
|
<Button
|
|
|
|
data-testid="general-tab-revert"
|
|
|
|
variant="link"
|
2022-06-15 12:57:39 +00:00
|
|
|
onClick={setupForm}
|
2022-04-05 19:34:21 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</PageSection>
|
2021-04-19 11:41:07 +00:00
|
|
|
);
|
|
|
|
};
|