From 6c63a8d4dc8448aa6c027891c1e555add43c287e Mon Sep 17 00:00:00 2001 From: mfrances Date: Tue, 9 Feb 2021 13:01:23 -0500 Subject: [PATCH 1/8] preliminary work --- src/route-config.ts | 12 ++++++++++++ .../UserFederationKerberosSettings.tsx | 4 ++++ src/user-federation/UserFederationSection.tsx | 9 +++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/route-config.ts b/src/route-config.ts index 2c72f8b288..54c58c2f11 100644 --- a/src/route-config.ts +++ b/src/route-config.ts @@ -220,12 +220,24 @@ export const routes: RoutesFn = (t: TFunction) => [ breadcrumb: t("common:settings"), access: "view-realm", }, + { + path: "/:realm/user-federation/kerberos/new", + component: UserFederationKerberosSettings, + breadcrumb: t("common:settings"), + access: "view-realm", + }, { path: "/:realm/user-federation/ldap/:id", component: UserFederationLdapSettings, breadcrumb: t("common:settings"), access: "view-realm", }, + { + path: "/:realm/user-federation/ldap/new", + component: UserFederationLdapSettings, + breadcrumb: t("common:settings"), + access: "view-realm", + }, { path: "/:realm/", component: DashboardSection, diff --git a/src/user-federation/UserFederationKerberosSettings.tsx b/src/user-federation/UserFederationKerberosSettings.tsx index ffa9a6e197..410c30f471 100644 --- a/src/user-federation/UserFederationKerberosSettings.tsx +++ b/src/user-federation/UserFederationKerberosSettings.tsx @@ -92,6 +92,8 @@ export const UserFederationKerberosSettings = () => { }, []); const setupForm = (component: ComponentRepresentation) => { + console.log("READING as:"); + console.log(component); Object.entries(component).map((entry) => { form.setValue( "config.allowPasswordAuthentication", @@ -105,6 +107,8 @@ export const UserFederationKerberosSettings = () => { }; const save = async (component: ComponentRepresentation) => { + console.log("SAVING as:"); + console.log(component); try { await adminClient.components.update({ id }, component); setupForm(component as ComponentRepresentation); diff --git a/src/user-federation/UserFederationSection.tsx b/src/user-federation/UserFederationSection.tsx index fe316dbb18..13715a789e 100644 --- a/src/user-federation/UserFederationSection.tsx +++ b/src/user-federation/UserFederationSection.tsx @@ -26,6 +26,8 @@ import { useAdminClient, asyncStateFetch } from "../context/auth/AdminClient"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import "./user-federation.css"; +import { useHistory, useRouteMatch } from "react-router-dom"; + export const UserFederationSection = () => { const [userFederations, setUserFederations] = useState< ComponentRepresentation[] @@ -37,6 +39,9 @@ export const UserFederationSection = () => { const [key, setKey] = useState(0); const refresh = () => setKey(new Date().getTime()); + const { url } = useRouteMatch(); + const history = useHistory(); + useEffect(() => { return asyncStateFetch( () => { @@ -53,8 +58,8 @@ export const UserFederationSection = () => { }, [key]); const ufAddProviderDropdownItems = [ - LDAP, - Kerberos, + history.push(`${url}/ldap/new`)}>LDAP, + history.push(`${url}/kerberos/new`)}>Kerberos, ]; const learnMoreLinkProps = { From 70f1629be0653860d1826b551ec9415c86ad34dc Mon Sep 17 00:00:00 2001 From: mfrances Date: Tue, 9 Feb 2021 16:12:50 -0500 Subject: [PATCH 2/8] small update - id is an issue --- src/user-federation/UserFederationKerberosSettings.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/user-federation/UserFederationKerberosSettings.tsx b/src/user-federation/UserFederationKerberosSettings.tsx index 410c30f471..5c5009182e 100644 --- a/src/user-federation/UserFederationKerberosSettings.tsx +++ b/src/user-federation/UserFederationKerberosSettings.tsx @@ -110,7 +110,11 @@ export const UserFederationKerberosSettings = () => { console.log("SAVING as:"); console.log(component); try { - await adminClient.components.update({ id }, component); + if (id) { + await adminClient.components.update({ id }, component); + } else { + await adminClient.components.create(component); + } setupForm(component as ComponentRepresentation); addAlert(t("saveSuccess"), AlertVariant.success); } catch (error) { From 1a78540c8fec0c54d2fc79c30b79f1cd7cc6c240 Mon Sep 17 00:00:00 2001 From: mfrances Date: Wed, 10 Feb 2021 16:54:21 -0500 Subject: [PATCH 3/8] kerberos save logic --- .../UserFederationKerberosSettings.tsx | 65 +++++++++++-------- src/user-federation/UserFederationSection.tsx | 14 +++- .../kerberos/KerberosSettingsRequired.tsx | 15 +++-- src/user-federation/messages.json | 6 +- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/user-federation/UserFederationKerberosSettings.tsx b/src/user-federation/UserFederationKerberosSettings.tsx index 5c5009182e..d84d2d7f75 100644 --- a/src/user-federation/UserFederationKerberosSettings.tsx +++ b/src/user-federation/UserFederationKerberosSettings.tsx @@ -37,6 +37,7 @@ const KerberosSettingsHeader = ({ toggleDeleteDialog, }: KerberosSettingsHeaderProps) => { const { t } = useTranslation("user-federation"); + const { id } = useParams<{ id: string }>(); const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ titleKey: "user-federation:userFedDisableConfirmTitle", messageKey: "user-federation:userFedDisableConfirm", @@ -49,24 +50,28 @@ const KerberosSettingsHeader = ({ return ( <> - toggleDeleteDialog()}> - {t("deleteProvider")} - , - ]} - isEnabled={value === "true"} - onToggle={(value) => { - if (!value) { - toggleDisableDialog(); - } else { - onChange("" + value); - save(); - } - }} - /> + {id === "new" ? ( + + ) : ( + toggleDeleteDialog()}> + {t("deleteProvider")} + , + ]} + isEnabled={value === "true"} + onToggle={(value) => { + if (!value) { + toggleDisableDialog(); + } else { + onChange("" + value); + save(); + } + }} + /> + )} ); }; @@ -92,8 +97,6 @@ export const UserFederationKerberosSettings = () => { }, []); const setupForm = (component: ComponentRepresentation) => { - console.log("READING as:"); - console.log(component); Object.entries(component).map((entry) => { form.setValue( "config.allowPasswordAuthentication", @@ -107,18 +110,24 @@ export const UserFederationKerberosSettings = () => { }; const save = async (component: ComponentRepresentation) => { - console.log("SAVING as:"); - console.log(component); try { if (id) { - await adminClient.components.update({ id }, component); - } else { - await adminClient.components.create(component); + if (id === "new") { + await adminClient.components.create(component); + } else { + await adminClient.components.update({ id }, component); + } } setupForm(component as ComponentRepresentation); - addAlert(t("saveSuccess"), AlertVariant.success); + addAlert( + t(id === "new" ? "createSuccess" : "saveSuccess"), + AlertVariant.success + ); } catch (error) { - addAlert(`${t("saveError")} '${error}'`, AlertVariant.danger); + addAlert( + `${t(id === "new" ? "createError" : "saveError")} '${error}'`, + AlertVariant.danger + ); } }; @@ -143,7 +152,7 @@ export const UserFederationKerberosSettings = () => { ( { }, [key]); const ufAddProviderDropdownItems = [ - history.push(`${url}/ldap/new`)}>LDAP, - history.push(`${url}/kerberos/new`)}>Kerberos, + history.push(`${url}/ldap/new`)} + > + LDAP + , + history.push(`${url}/kerberos/new`)} + > + Kerberos + , ]; const learnMoreLinkProps = { diff --git a/src/user-federation/kerberos/KerberosSettingsRequired.tsx b/src/user-federation/kerberos/KerberosSettingsRequired.tsx index 9b8eb579e9..6d85aa923e 100644 --- a/src/user-federation/kerberos/KerberosSettingsRequired.tsx +++ b/src/user-federation/kerberos/KerberosSettingsRequired.tsx @@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next"; import { UseFormMethods, Controller, useWatch } from "react-hook-form"; import { FormAccess } from "../../components/form-access/FormAccess"; +import { useRealm } from "../../context/realm-context/RealmContext"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import _ from "lodash"; @@ -29,6 +30,7 @@ export const KerberosSettingsRequired = ({ }: KerberosSettingsRequiredProps) => { const { t } = useTranslation("user-federation"); const helpText = useTranslation("user-federation-help").t; + const { realm } = useRealm(); const [isEditModeDropdownOpen, setIsEditModeDropdownOpen] = useState(false); @@ -62,18 +64,19 @@ export const KerberosSettingsRequired = ({ isRequired > {/* These hidden fields are required so data object written back matches data retrieved */} -