Added ability to query ldap capabilities (#2491)
This commit is contained in:
parent
58fd0ad76f
commit
7f197cf5ec
4 changed files with 46 additions and 3 deletions
|
@ -70,7 +70,7 @@ const AddLdapFormContent = ({
|
||||||
<LdapSettingsSynchronization form={form} />
|
<LdapSettingsSynchronization form={form} />
|
||||||
<LdapSettingsKerberosIntegration form={form} />
|
<LdapSettingsKerberosIntegration form={form} />
|
||||||
<SettingsCache form={form} />
|
<SettingsCache form={form} />
|
||||||
<LdapSettingsAdvanced form={form} />
|
<LdapSettingsAdvanced form={form} id={id} />
|
||||||
</ScrollForm>
|
</ScrollForm>
|
||||||
<Form onSubmit={form.handleSubmit(save)}>
|
<Form onSubmit={form.handleSubmit(save)}>
|
||||||
<ActionGroup className="keycloak__form_actions">
|
<ActionGroup className="keycloak__form_actions">
|
||||||
|
|
|
@ -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 { useTranslation } from "react-i18next";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
import { UseFormMethods, Controller } from "react-hook-form";
|
import { UseFormMethods, Controller } from "react-hook-form";
|
||||||
import { FormAccess } from "../../components/form-access/FormAccess";
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
||||||
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
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 = {
|
export type LdapSettingsAdvancedProps = {
|
||||||
|
id?: string;
|
||||||
form: UseFormMethods;
|
form: UseFormMethods;
|
||||||
showSectionHeading?: boolean;
|
showSectionHeading?: boolean;
|
||||||
showSectionDescription?: boolean;
|
showSectionDescription?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PASSWORD_MODIFY_OID = "1.3.6.1.4.1.4203.1.11.1";
|
||||||
|
|
||||||
export const LdapSettingsAdvanced = ({
|
export const LdapSettingsAdvanced = ({
|
||||||
|
id,
|
||||||
form,
|
form,
|
||||||
showSectionHeading = false,
|
showSectionHeading = false,
|
||||||
showSectionDescription = false,
|
showSectionDescription = false,
|
||||||
|
@ -20,6 +28,30 @@ export const LdapSettingsAdvanced = ({
|
||||||
const { t } = useTranslation("user-federation");
|
const { t } = useTranslation("user-federation");
|
||||||
const { t: helpText } = useTranslation("user-federation-help");
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{showSectionHeading && (
|
{showSectionHeading && (
|
||||||
|
@ -117,6 +149,16 @@ export const LdapSettingsAdvanced = ({
|
||||||
)}
|
)}
|
||||||
></Controller>
|
></Controller>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
<FormGroup fieldId="query-extensions">
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
id="query-extensions"
|
||||||
|
data-testid="query-extensions"
|
||||||
|
onClick={testLdap}
|
||||||
|
>
|
||||||
|
{t("queryExtensions")}
|
||||||
|
</Button>
|
||||||
|
</FormGroup>
|
||||||
</FormAccess>
|
</FormAccess>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -42,7 +42,7 @@ const testLdapProperties: Array<keyof TestLdapConnectionRepresentation> = [
|
||||||
|
|
||||||
type TestTypes = "testConnection" | "testAuthentication";
|
type TestTypes = "testConnection" | "testAuthentication";
|
||||||
|
|
||||||
const convertFormToSettings = (form: UseFormMethods) => {
|
export const convertFormToSettings = (form: UseFormMethods) => {
|
||||||
const settings: TestLdapConnectionRepresentation = {};
|
const settings: TestLdapConnectionRepresentation = {};
|
||||||
|
|
||||||
testLdapProperties.forEach((key) => {
|
testLdapProperties.forEach((key) => {
|
||||||
|
|
|
@ -90,6 +90,7 @@ export default {
|
||||||
saveError: "User federation provider could not be saved: {{error}}",
|
saveError: "User federation provider could not be saved: {{error}}",
|
||||||
createSuccess: "User federation provider successfully created",
|
createSuccess: "User federation provider successfully created",
|
||||||
createError: "User federation provider could not be created: {{error}}",
|
createError: "User federation provider could not be created: {{error}}",
|
||||||
|
queryExtensions: "Query Supported Extensions",
|
||||||
testAuthentication: "Test authentication",
|
testAuthentication: "Test authentication",
|
||||||
testSuccess: "Successfully connected to LDAP",
|
testSuccess: "Successfully connected to LDAP",
|
||||||
testError:
|
testError:
|
||||||
|
|
Loading…
Reference in a new issue