2021-04-30 19:08:12 +00:00
|
|
|
import React, { useState } from "react";
|
2021-04-19 11:41:07 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-04-30 19:08:12 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
2021-04-19 11:41:07 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
ClipboardCopy,
|
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Stack,
|
|
|
|
StackItem,
|
|
|
|
Switch,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
2021-05-04 17:58:18 +00:00
|
|
|
import type RealmRepresentation from "keycloak-admin/lib/defs/realmRepresentation";
|
2021-04-19 11:41:07 +00:00
|
|
|
import { getBaseUrl } from "../util";
|
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";
|
|
|
|
|
2021-04-30 19:08:12 +00:00
|
|
|
type RealmSettingsGeneralTabProps = {
|
|
|
|
save: (realm: RealmRepresentation) => void;
|
|
|
|
reset: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsGeneralTab = ({
|
|
|
|
save,
|
|
|
|
reset,
|
|
|
|
}: RealmSettingsGeneralTabProps) => {
|
2021-04-19 11:41:07 +00:00
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { realm: realmName } = useRealm();
|
2021-07-09 14:23:49 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
control,
|
|
|
|
handleSubmit,
|
|
|
|
formState: { isDirty },
|
|
|
|
} = useFormContext();
|
2021-04-19 11:41:07 +00:00
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
const baseUrl = getBaseUrl(adminClient);
|
|
|
|
|
|
|
|
const requireSslTypes = ["all", "external", "none"];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<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>
|
|
|
|
<ClipboardCopy isReadOnly>{realmName}</ClipboardCopy>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup label={t("displayName")} fieldId="kc-display-name">
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-display-name"
|
|
|
|
name="displayName"
|
|
|
|
ref={register}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("htmlDisplayName")}
|
|
|
|
fieldId="kc-html-display-name"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
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"
|
|
|
|
forLabel={t("frontendUrl")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("frontendUrl") })}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-frontend-url"
|
|
|
|
name="attributes.frontendUrl"
|
|
|
|
ref={register}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("requireSsl")}
|
|
|
|
fieldId="kc-require-ssl"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:requireSsl"
|
|
|
|
forLabel={t("requireSsl")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("requireSsl") })}
|
2021-04-19 11:41:07 +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>
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("userManagedAccess")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:userManagedAccess"
|
|
|
|
forLabel={t("userManagedAccess")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("userManagedAccess") })}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-user-manged-access"
|
|
|
|
>
|
|
|
|
<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}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("endpoints")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:endpoints"
|
|
|
|
forLabel={t("endpoints")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("endpoints") })}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-endpoints"
|
|
|
|
>
|
|
|
|
<Stack>
|
|
|
|
<StackItem>
|
|
|
|
<FormattedLink
|
|
|
|
href={`${baseUrl}realms/${realmName}/.well-known/openid-configuration`}
|
2021-05-21 14:48:46 +00:00
|
|
|
title={t("openIDEndpointConfiguration")}
|
2021-04-19 11:41:07 +00:00
|
|
|
/>
|
|
|
|
</StackItem>
|
|
|
|
<StackItem>
|
|
|
|
<FormattedLink
|
|
|
|
href={`${baseUrl}realms/${realmName}/protocol/saml/descriptor`}
|
|
|
|
title={t("samlIdentityProviderMetadata")}
|
|
|
|
/>
|
|
|
|
</StackItem>
|
|
|
|
</Stack>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
type="submit"
|
|
|
|
data-testid="general-tab-save"
|
2021-07-09 14:23:49 +00:00
|
|
|
isDisabled={!isDirty}
|
2021-04-19 11:41:07 +00:00
|
|
|
>
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
2021-04-30 19:08:12 +00:00
|
|
|
<Button variant="link" onClick={reset}>
|
2021-04-19 11:41:07 +00:00
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|