diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index 3f35d89225..16ecd3db11 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -70,7 +70,7 @@ const AddLdapFormContent = ({ - +
diff --git a/src/user-federation/ldap/LdapSettingsAdvanced.tsx b/src/user-federation/ldap/LdapSettingsAdvanced.tsx index 40066b82d7..2f92947db8 100644 --- a/src/user-federation/ldap/LdapSettingsAdvanced.tsx +++ b/src/user-federation/ldap/LdapSettingsAdvanced.tsx @@ -1,18 +1,26 @@ -import { FormGroup, Switch } from "@patternfly/react-core"; +import { Button, FormGroup, Switch } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import React from "react"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { UseFormMethods, Controller } from "react-hook-form"; import { FormAccess } from "../../components/form-access/FormAccess"; import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader"; +import { convertFormToSettings } from "./LdapSettingsConnection"; +import { useAdminClient } from "../../context/auth/AdminClient"; +import { useRealm } from "../../context/realm-context/RealmContext"; +import { useAlerts } from "../../components/alert/Alerts"; export type LdapSettingsAdvancedProps = { + id?: string; form: UseFormMethods; showSectionHeading?: boolean; showSectionDescription?: boolean; }; +const PASSWORD_MODIFY_OID = "1.3.6.1.4.1.4203.1.11.1"; + export const LdapSettingsAdvanced = ({ + id, form, showSectionHeading = false, showSectionDescription = false, @@ -20,6 +28,30 @@ export const LdapSettingsAdvanced = ({ const { t } = useTranslation("user-federation"); const { t: helpText } = useTranslation("user-federation-help"); + const adminClient = useAdminClient(); + const { realm } = useRealm(); + const { addAlert, addError } = useAlerts(); + + const testLdap = async () => { + if (!(await form.trigger())) return; + try { + const settings = convertFormToSettings(form); + const ldapOids = await adminClient.realms.ldapServerCapabilities( + { realm }, + { ...settings, componentId: id } + ); + addAlert(t("testSuccess")); + const passwordModifyOid = ldapOids.filter( + (id: { oid: string }) => id.oid === PASSWORD_MODIFY_OID + ); + form.setValue("config.usePasswordModifyExtendedOp", [ + (passwordModifyOid.length > 0).toString(), + ]); + } catch (error) { + addError("user-federation:testError", error); + } + }; + return ( <> {showSectionHeading && ( @@ -117,6 +149,16 @@ export const LdapSettingsAdvanced = ({ )} > + + + ); diff --git a/src/user-federation/ldap/LdapSettingsConnection.tsx b/src/user-federation/ldap/LdapSettingsConnection.tsx index d0e5412c83..fc80d9535f 100644 --- a/src/user-federation/ldap/LdapSettingsConnection.tsx +++ b/src/user-federation/ldap/LdapSettingsConnection.tsx @@ -42,7 +42,7 @@ const testLdapProperties: Array = [ type TestTypes = "testConnection" | "testAuthentication"; -const convertFormToSettings = (form: UseFormMethods) => { +export const convertFormToSettings = (form: UseFormMethods) => { const settings: TestLdapConnectionRepresentation = {}; testLdapProperties.forEach((key) => { diff --git a/src/user-federation/messages.ts b/src/user-federation/messages.ts index 4978a0bc09..38796a2dc3 100644 --- a/src/user-federation/messages.ts +++ b/src/user-federation/messages.ts @@ -90,6 +90,7 @@ export default { saveError: "User federation provider could not be saved: {{error}}", createSuccess: "User federation provider successfully created", createError: "User federation provider could not be created: {{error}}", + queryExtensions: "Query Supported Extensions", testAuthentication: "Test authentication", testSuccess: "Successfully connected to LDAP", testError: