Added ability to query ldap capabilities (#2491)

This commit is contained in:
Erik Jan de Wit 2022-04-25 13:23:59 +02:00 committed by GitHub
parent 58fd0ad76f
commit 7f197cf5ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View file

@ -70,7 +70,7 @@ const AddLdapFormContent = ({
<LdapSettingsSynchronization form={form} />
<LdapSettingsKerberosIntegration form={form} />
<SettingsCache form={form} />
<LdapSettingsAdvanced form={form} />
<LdapSettingsAdvanced form={form} id={id} />
</ScrollForm>
<Form onSubmit={form.handleSubmit(save)}>
<ActionGroup className="keycloak__form_actions">

View file

@ -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 = ({
)}
></Controller>
</FormGroup>
<FormGroup fieldId="query-extensions">
<Button
variant="secondary"
id="query-extensions"
data-testid="query-extensions"
onClick={testLdap}
>
{t("queryExtensions")}
</Button>
</FormGroup>
</FormAccess>
</>
);

View file

@ -42,7 +42,7 @@ const testLdapProperties: Array<keyof TestLdapConnectionRepresentation> = [
type TestTypes = "testConnection" | "testAuthentication";
const convertFormToSettings = (form: UseFormMethods) => {
export const convertFormToSettings = (form: UseFormMethods) => {
const settings: TestLdapConnectionRepresentation = {};
testLdapProperties.forEach((key) => {

View file

@ -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: