2023-01-26 09:31:07 +00:00
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2021-07-15 14:25:22 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
import { Controller, useForm, useWatch } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2023-11-14 11:04:55 +00:00
|
|
|
import { FormPanel, HelpItem } from "ui-shared";
|
2023-05-24 12:11:06 +00:00
|
|
|
import { FormAccess } from "../components/form/FormAccess";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { TimeSelector } from "../components/time-selector/TimeSelector";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { convertToFormValues } from "../util";
|
2021-07-15 14:25:22 +00:00
|
|
|
|
2022-02-16 11:39:08 +00:00
|
|
|
import "./realm-settings-section.css";
|
2021-07-15 14:25:22 +00:00
|
|
|
|
|
|
|
type RealmSettingsSessionsTabProps = {
|
2021-09-02 20:14:43 +00:00
|
|
|
realm: RealmRepresentation;
|
|
|
|
save: (realm: RealmRepresentation) => void;
|
2021-07-15 14:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const RealmSettingsSessionsTab = ({
|
2021-09-02 20:14:43 +00:00
|
|
|
realm,
|
|
|
|
save,
|
2021-07-15 14:25:22 +00:00
|
|
|
}: RealmSettingsSessionsTabProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2021-07-15 14:25:22 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const { setValue, control, handleSubmit, formState } =
|
2023-01-26 09:31:07 +00:00
|
|
|
useForm<RealmRepresentation>();
|
2021-07-15 14:25:22 +00:00
|
|
|
|
|
|
|
const offlineSessionMaxEnabled = useWatch({
|
|
|
|
control,
|
|
|
|
name: "offlineSessionMaxLifespanEnabled",
|
|
|
|
});
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const setupForm = () => {
|
|
|
|
convertToFormValues(realm, setValue);
|
2021-07-15 14:25:22 +00:00
|
|
|
};
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
useEffect(setupForm, []);
|
|
|
|
|
2021-07-15 14:25:22 +00:00
|
|
|
return (
|
2021-08-26 12:15:28 +00:00
|
|
|
<PageSection variant="light">
|
|
|
|
<FormPanel
|
|
|
|
title={t("SSOSessionSettings")}
|
|
|
|
className="kc-sso-session-template"
|
|
|
|
>
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
onSubmit={handleSubmit(save)}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("SSOSessionIdle")}
|
|
|
|
fieldId="SSOSessionIdle"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("ssoSessionIdle")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="SSOSessionIdle"
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<Controller
|
|
|
|
name="ssoSessionIdleTimeout"
|
2021-09-02 20:14:43 +00:00
|
|
|
defaultValue={realm.ssoSessionIdleTimeout}
|
2021-08-26 12:15:28 +00:00
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-sso-session-idle"
|
|
|
|
data-testid="sso-session-idle-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-07-15 14:25:22 +00:00
|
|
|
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("SSOSessionMax")}
|
|
|
|
fieldId="SSOSessionMax"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("ssoSessionMax")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="SSOSessionMax"
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="ssoSessionMaxLifespan"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-sso-session-max"
|
|
|
|
data-testid="sso-session-max-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
label={t("SSOSessionIdleRememberMe")}
|
|
|
|
fieldId="SSOSessionIdleRememberMe"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("ssoSessionIdleRememberMe")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="SSOSessionIdleRememberMe"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="ssoSessionIdleTimeoutRememberMe"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-sso-session-idle-remember-me"
|
|
|
|
data-testid="sso-session-idle-remember-me-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-07-15 14:25:22 +00:00
|
|
|
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("SSOSessionMaxRememberMe")}
|
|
|
|
fieldId="SSOSessionMaxRememberMe"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t("ssoSessionMaxRememberMe")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="SSOSessionMaxRememberMe"
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="ssoSessionMaxLifespanRememberMe"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-sso-session-max-remember-me"
|
|
|
|
data-testid="sso-session-max-remember-me-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</FormPanel>
|
|
|
|
<FormPanel
|
|
|
|
title={t("clientSessionSettings")}
|
|
|
|
className="kc-client-session-template"
|
|
|
|
>
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("clientSessionIdle")}
|
|
|
|
fieldId="clientSessionIdle"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("clientSessionIdleHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="clientSessionIdle"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="clientSessionIdleTimeout"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-client-session-idle"
|
|
|
|
data-testid="client-session-idle-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
label={t("clientSessionMax")}
|
|
|
|
fieldId="clientSessionMax"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("clientSessionMaxHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="clientSessionMax"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<Controller
|
|
|
|
name="clientSessionMaxLifespan"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-client-session-max"
|
|
|
|
data-testid="client-session-max-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</FormPanel>
|
|
|
|
<FormPanel
|
|
|
|
title={t("offlineSessionSettings")}
|
|
|
|
className="kc-offline-session-template"
|
|
|
|
>
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("offlineSessionIdle")}
|
|
|
|
fieldId="offlineSessionIdle"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("offlineSessionIdleHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="offlineSessionIdle"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="offlineSessionIdleTimeout"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-offline-session-idle"
|
|
|
|
data-testid="offline-session-idle-input"
|
|
|
|
aria-label="offline-session-idle-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("offlineSessionMaxLimited")}
|
|
|
|
fieldId="kc-offlineSessionMaxLimited"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("offlineSessionMaxLimitedHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="offlineSessionMaxLimited"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<Controller
|
|
|
|
name="offlineSessionMaxLifespanEnabled"
|
|
|
|
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-offline-session-max"
|
|
|
|
data-testid="offline-session-max-switch"
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("offlineSessionMaxLimited")}
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("enabled")}
|
|
|
|
labelOff={t("disabled")}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value}
|
|
|
|
onChange={field.onChange}
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
{offlineSessionMaxEnabled && (
|
2021-07-15 14:25:22 +00:00
|
|
|
<FormGroup
|
2021-08-26 12:15:28 +00:00
|
|
|
label={t("offlineSessionMax")}
|
|
|
|
fieldId="offlineSessionMax"
|
|
|
|
id="offline-session-max-label"
|
2021-07-15 14:25:22 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("offlineSessionMaxHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="offlineSessionMax"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
2021-08-26 12:15:28 +00:00
|
|
|
name="offlineSessionMaxLifespan"
|
2021-07-15 14:25:22 +00:00
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-07-15 14:25:22 +00:00
|
|
|
<TimeSelector
|
2021-08-26 12:15:28 +00:00
|
|
|
className="kc-offline-session-max"
|
|
|
|
data-testid="offline-session-max-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
</FormAccess>
|
|
|
|
</FormPanel>
|
|
|
|
<FormPanel
|
|
|
|
className="kc-login-settings-template"
|
|
|
|
title={t("loginSettings")}
|
|
|
|
>
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("loginTimeout")}
|
|
|
|
id="kc-login-timeout-label"
|
|
|
|
fieldId="offlineSessionIdle"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("loginTimeoutHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="loginTimeout"
|
2021-08-26 12:15:28 +00:00
|
|
|
/>
|
|
|
|
}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2021-08-26 12:15:28 +00:00
|
|
|
<Controller
|
|
|
|
name="accessCodeLifespanLogin"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-login-timeout"
|
|
|
|
data-testid="login-timeout-input"
|
|
|
|
aria-label="login-timeout-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("loginActionTimeout")}
|
|
|
|
fieldId="loginActionTimeout"
|
|
|
|
id="login-action-timeout-label"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("loginActionTimeoutHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="loginActionTimeout"
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="accessCodeLifespanUserAction"
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-08-26 12:15:28 +00:00
|
|
|
<TimeSelector
|
|
|
|
className="kc-login-action-timeout"
|
|
|
|
data-testid="login-action-timeout-input"
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value!}
|
|
|
|
onChange={field.onChange}
|
2022-03-07 13:49:38 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
2021-07-15 14:25:22 +00:00
|
|
|
/>
|
2021-08-26 12:15:28 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
type="submit"
|
|
|
|
data-testid="sessions-tab-save"
|
|
|
|
isDisabled={!formState.isDirty}
|
2021-07-15 14:25:22 +00:00
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("save")}
|
2021-08-26 12:15:28 +00:00
|
|
|
</Button>
|
2022-06-15 12:57:39 +00:00
|
|
|
<Button variant="link" onClick={setupForm}>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("revert")}
|
2021-08-26 12:15:28 +00:00
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</FormPanel>
|
|
|
|
</PageSection>
|
2021-07-15 14:25:22 +00:00
|
|
|
);
|
|
|
|
};
|