2023-01-26 09:31:07 +00:00
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2021-04-19 11:41:07 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
ClipboardCopy,
|
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Stack,
|
|
|
|
StackItem,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { Controller, FormProvider, useForm } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2023-05-03 13:51:02 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2021-04-19 11:41:07 +00:00
|
|
|
|
2023-05-03 13:51:02 +00:00
|
|
|
import { adminClient } from "../admin-client";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { FormattedLink } from "../components/external-link/FormattedLink";
|
2023-05-24 12:11:06 +00:00
|
|
|
import { FormAccess } from "../components/form/FormAccess";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { KeyValueInput } from "../components/key-value-form/KeyValueInput";
|
|
|
|
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
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";
|
2023-11-24 21:31:26 +00:00
|
|
|
import {
|
|
|
|
UnmanagedAttributePolicy,
|
|
|
|
UserProfileConfig,
|
|
|
|
} from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
|
|
|
|
import { useFetch } from "../utils/useFetch";
|
|
|
|
import { UIRealmRepresentation } from "./RealmSettingsTabs";
|
2021-04-19 11:41:07 +00:00
|
|
|
|
2021-04-30 19:08:12 +00:00
|
|
|
type RealmSettingsGeneralTabProps = {
|
2023-11-24 21:31:26 +00:00
|
|
|
realm: UIRealmRepresentation;
|
|
|
|
save: (realm: UIRealmRepresentation) => void;
|
2021-04-30 19:08:12 +00:00
|
|
|
};
|
|
|
|
|
2023-06-19 15:53:14 +00:00
|
|
|
type FormFields = Omit<RealmRepresentation, "groups">;
|
|
|
|
|
2021-04-30 19:08:12 +00:00
|
|
|
export const RealmSettingsGeneralTab = ({
|
2022-06-15 12:57:39 +00:00
|
|
|
realm,
|
2021-04-30 19:08:12 +00:00
|
|
|
save,
|
|
|
|
}: RealmSettingsGeneralTabProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2021-04-19 11:41:07 +00:00
|
|
|
const { realm: realmName } = useRealm();
|
2023-06-19 15:53:14 +00:00
|
|
|
const form = useForm<FormFields>();
|
2021-07-09 14:23:49 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
control,
|
|
|
|
handleSubmit,
|
2022-06-15 12:57:39 +00:00
|
|
|
setValue,
|
2023-01-27 16:10:09 +00:00
|
|
|
formState: { isDirty, errors },
|
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"];
|
|
|
|
|
2023-11-24 21:31:26 +00:00
|
|
|
const [userProfileConfig, setUserProfileConfig] =
|
|
|
|
useState<UserProfileConfig>();
|
|
|
|
const unmanagedAttributePolicies = [
|
|
|
|
UnmanagedAttributePolicy.Disabled,
|
|
|
|
UnmanagedAttributePolicy.Enabled,
|
|
|
|
UnmanagedAttributePolicy.AdminView,
|
|
|
|
UnmanagedAttributePolicy.AdminEdit,
|
|
|
|
];
|
|
|
|
const [isUnmanagedAttributeOpen, setIsUnmanagedAttributeOpen] =
|
|
|
|
useState(false);
|
|
|
|
const [isUserProfileEnabled, setUserProfileEnabled] = useState(false);
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const setupForm = () => {
|
|
|
|
convertToFormValues(realm, setValue);
|
|
|
|
if (realm.attributes?.["acr.loa.map"]) {
|
|
|
|
const result = Object.entries(
|
2023-07-11 14:03:21 +00:00
|
|
|
JSON.parse(realm.attributes["acr.loa.map"]),
|
2022-06-15 12:57:39 +00:00
|
|
|
).flatMap(([key, value]) => ({ key, value }));
|
|
|
|
result.concat({ key: "", value: "" });
|
2023-01-26 09:31:07 +00:00
|
|
|
setValue(
|
|
|
|
convertAttributeNameToForm("attributes.acr.loa.map") as any,
|
2023-07-11 14:03:21 +00:00
|
|
|
result,
|
2023-01-26 09:31:07 +00:00
|
|
|
);
|
2022-06-15 12:57:39 +00:00
|
|
|
}
|
2023-11-24 21:31:26 +00:00
|
|
|
setUserProfileEnabled(realm.attributes?.["userProfileEnabled"] === "true");
|
2022-06-15 12:57:39 +00:00
|
|
|
};
|
|
|
|
|
2023-11-24 21:31:26 +00:00
|
|
|
useFetch(
|
|
|
|
() => adminClient.users.getProfile({ realm: realmName }),
|
|
|
|
(config) => setUserProfileConfig(config),
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
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"
|
2023-11-24 21:31:26 +00:00
|
|
|
onSubmit={handleSubmit((data) => {
|
|
|
|
if (
|
|
|
|
UnmanagedAttributePolicy.Disabled ===
|
|
|
|
userProfileConfig?.unmanagedAttributePolicy
|
|
|
|
) {
|
|
|
|
userProfileConfig.unmanagedAttributePolicy = undefined;
|
|
|
|
}
|
|
|
|
save({ ...data, upConfig: userProfileConfig });
|
|
|
|
})}
|
2021-08-26 12:15:28 +00:00
|
|
|
>
|
2023-01-27 16:10:09 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("realmId")}
|
|
|
|
fieldId="kc-realm-id"
|
|
|
|
isRequired
|
|
|
|
validated={errors.realm ? "error" : "default"}
|
|
|
|
helperTextInvalid={errors.realm?.message}
|
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<Controller
|
|
|
|
name="realm"
|
|
|
|
control={control}
|
2023-01-27 16:10:09 +00:00
|
|
|
rules={{
|
2023-09-14 09:01:15 +00:00
|
|
|
required: { value: true, message: t("required") },
|
2023-01-27 16:10:09 +00:00
|
|
|
pattern: {
|
|
|
|
value: /^[a-zA-Z0-9-_]+$/,
|
2023-11-02 16:03:47 +00:00
|
|
|
message: t("invalidRealmName"),
|
2023-01-27 16:10:09 +00:00
|
|
|
},
|
|
|
|
}}
|
2021-08-26 12:15:28 +00:00
|
|
|
defaultValue=""
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
|
|
|
<ClipboardCopy data-testid="realmName" onChange={field.onChange}>
|
|
|
|
{field.value}
|
2022-04-05 19:34:21 +00:00
|
|
|
</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
|
|
|
id="kc-display-name"
|
2023-01-26 09:31:07 +00:00
|
|
|
{...register("displayName")}
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
</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
|
|
|
id="kc-html-display-name"
|
2023-01-26 09:31:07 +00:00
|
|
|
{...register("displayNameHtml")}
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("frontendUrl")}
|
|
|
|
fieldId="kc-frontend-url"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("frontendUrlHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="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
|
2022-12-07 09:04:37 +00:00
|
|
|
type="url"
|
2021-08-26 12:15:28 +00:00
|
|
|
id="kc-frontend-url"
|
2023-01-26 09:31:07 +00:00
|
|
|
{...register(convertAttributeNameToForm("attributes.frontendUrl"))}
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("requireSsl")}
|
|
|
|
fieldId="kc-require-ssl"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("requireSslHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="requireSsl"
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="sslRequired"
|
|
|
|
defaultValue="none"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-require-ssl"
|
|
|
|
onToggle={() => setOpen(!open)}
|
|
|
|
onSelect={(_, value) => {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value as string);
|
2021-08-26 12:15:28 +00:00
|
|
|
setOpen(false);
|
|
|
|
}}
|
2023-01-26 09:31:07 +00:00
|
|
|
selections={field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("requireSsl")}
|
|
|
|
isOpen={open}
|
|
|
|
>
|
|
|
|
{requireSslTypes.map((sslType) => (
|
|
|
|
<SelectOption
|
2023-01-26 09:31:07 +00:00
|
|
|
selected={sslType === field.value}
|
2021-08-26 12:15:28 +00:00
|
|
|
key={sslType}
|
|
|
|
value={sslType}
|
|
|
|
>
|
|
|
|
{t(`sslType.${sslType}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-06-15 12:57:39 +00:00
|
|
|
<FormGroup
|
2023-09-13 14:05:17 +00:00
|
|
|
label={t("acrToLoAMapping")}
|
2022-06-15 12:57:39 +00:00
|
|
|
fieldId="acrToLoAMapping"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("acrToLoAMappingHelp")}
|
2023-09-13 14:05:17 +00:00
|
|
|
fieldLabelId="acrToLoAMapping"
|
2022-06-15 12:57:39 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<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
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("userManagedAccessHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="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}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Switch
|
|
|
|
id="kc-user-managed-access"
|
|
|
|
data-testid="user-managed-access-switch"
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value}
|
|
|
|
onChange={field.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
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("userProfileEnabledHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="userProfileEnabled"
|
2022-01-03 15:00:03 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-user-profile-enabled"
|
|
|
|
>
|
|
|
|
<Controller
|
2023-01-26 09:31:07 +00:00
|
|
|
name={
|
|
|
|
convertAttributeNameToForm(
|
2023-07-11 14:03:21 +00:00
|
|
|
"attributes.userProfileEnabled",
|
2023-01-26 09:31:07 +00:00
|
|
|
) as any
|
|
|
|
}
|
2022-01-03 15:00:03 +00:00
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
defaultValue="false"
|
|
|
|
render={({ field }) => (
|
2022-01-03 15:00:03 +00:00
|
|
|
<Switch
|
|
|
|
id="kc-user-profile-enabled"
|
|
|
|
data-testid="user-profile-enabled-switch"
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value === "true"}
|
2023-11-24 21:31:26 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
field.onChange(value.toString());
|
|
|
|
setUserProfileEnabled(value);
|
|
|
|
}}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("userProfileEnabled")}
|
2022-01-03 15:00:03 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2023-11-24 21:31:26 +00:00
|
|
|
{isUserProfileEnabled && (
|
|
|
|
<FormGroup
|
|
|
|
label={t("unmanagedAttributes")}
|
|
|
|
fieldId="kc-user-profile-unmanaged-attribute-policy"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={t("unmanagedAttributesHelpText")}
|
|
|
|
fieldLabelId="unmanagedAttributes"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Select
|
|
|
|
toggleId="kc-user-profile-unmanaged-attribute-policy"
|
|
|
|
onToggle={() =>
|
|
|
|
setIsUnmanagedAttributeOpen(!isUnmanagedAttributeOpen)
|
|
|
|
}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
if (userProfileConfig) {
|
|
|
|
userProfileConfig.unmanagedAttributePolicy =
|
|
|
|
value as UnmanagedAttributePolicy;
|
|
|
|
setUserProfileConfig(userProfileConfig);
|
|
|
|
}
|
|
|
|
setIsUnmanagedAttributeOpen(false);
|
|
|
|
}}
|
|
|
|
selections={userProfileConfig?.unmanagedAttributePolicy}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
isOpen={isUnmanagedAttributeOpen}
|
|
|
|
>
|
|
|
|
{unmanagedAttributePolicies.map((policy) => (
|
|
|
|
<SelectOption key={policy} value={policy}>
|
|
|
|
{t(`unmanagedAttributePolicy.${policy}`)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("endpoints")}
|
|
|
|
labelIcon={
|
2023-09-25 07:06:56 +00:00
|
|
|
<HelpItem helpText={t("endpointsHelp")} fieldLabelId="endpoints" />
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
fieldId="kc-endpoints"
|
|
|
|
>
|
|
|
|
<Stack>
|
|
|
|
<StackItem>
|
|
|
|
<FormattedLink
|
2022-07-14 13:02:28 +00:00
|
|
|
href={`${addTrailingSlash(
|
2023-07-11 14:03:21 +00:00
|
|
|
adminClient.baseUrl,
|
2022-07-14 13:02:28 +00:00
|
|
|
)}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(
|
2023-07-11 14:03:21 +00:00
|
|
|
adminClient.baseUrl,
|
2022-07-14 13:02:28 +00:00
|
|
|
)}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}
|
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("save")}
|
2021-08-26 12:15:28 +00:00
|
|
|
</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
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("revert")}
|
2021-08-26 12:15:28 +00:00
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</PageSection>
|
2021-04-19 11:41:07 +00:00
|
|
|
);
|
|
|
|
};
|