added test ldap button
This commit is contained in:
parent
ac664a2f54
commit
8c1a1fade8
3 changed files with 49 additions and 6 deletions
|
@ -167,7 +167,7 @@ const LdapSettingsHeader = ({
|
||||||
|
|
||||||
export const UserFederationLdapSettings = () => {
|
export const UserFederationLdapSettings = () => {
|
||||||
const { t } = useTranslation("user-federation");
|
const { t } = useTranslation("user-federation");
|
||||||
const form = useForm<ComponentRepresentation>();
|
const form = useForm<ComponentRepresentation>({ mode: "onChange" });
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
AlertVariant,
|
||||||
Button,
|
Button,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
Select,
|
Select,
|
||||||
|
@ -10,11 +11,16 @@ import {
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import TestLdapConnectionRepresentation from "keycloak-admin/lib/defs/testLdapConnection";
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
import { Controller, UseFormMethods, useWatch } from "react-hook-form";
|
import { Controller, UseFormMethods, useWatch } 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 { PasswordInput } from "../../components/password-input/PasswordInput";
|
import { PasswordInput } from "../../components/password-input/PasswordInput";
|
||||||
|
import { useAdminClient } from "../../context/auth/AdminClient";
|
||||||
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
||||||
|
import { useAlerts } from "../../components/alert/Alerts";
|
||||||
|
|
||||||
export type LdapSettingsConnectionProps = {
|
export type LdapSettingsConnectionProps = {
|
||||||
form: UseFormMethods;
|
form: UseFormMethods;
|
||||||
|
@ -22,13 +28,45 @@ export type LdapSettingsConnectionProps = {
|
||||||
showSectionDescription?: boolean;
|
showSectionDescription?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const testLdapProperties: Array<keyof TestLdapConnectionRepresentation> = [
|
||||||
|
"connectionUrl",
|
||||||
|
"bindDn",
|
||||||
|
"bindCredential",
|
||||||
|
"useTruststoreSpi",
|
||||||
|
"connectionTimeout",
|
||||||
|
"startTls",
|
||||||
|
"authType",
|
||||||
|
];
|
||||||
|
|
||||||
export const LdapSettingsConnection = ({
|
export const LdapSettingsConnection = ({
|
||||||
form,
|
form,
|
||||||
showSectionHeading = false,
|
showSectionHeading = false,
|
||||||
showSectionDescription = false,
|
showSectionDescription = false,
|
||||||
}: LdapSettingsConnectionProps) => {
|
}: LdapSettingsConnectionProps) => {
|
||||||
const { t } = useTranslation("user-federation");
|
const { t } = useTranslation("user-federation");
|
||||||
const helpText = useTranslation("user-federation-help").t;
|
const { t: helpText } = useTranslation("user-federation-help");
|
||||||
|
const adminClient = useAdminClient();
|
||||||
|
const { realm } = useRealm();
|
||||||
|
const { addAlert } = useAlerts();
|
||||||
|
|
||||||
|
const testLdap = async () => {
|
||||||
|
try {
|
||||||
|
const settings: TestLdapConnectionRepresentation = {};
|
||||||
|
|
||||||
|
testLdapProperties.forEach((key) => {
|
||||||
|
const value = _.get(form.getValues(), `config.${key}`);
|
||||||
|
settings[key] = _.isArray(value) ? value[0] : "";
|
||||||
|
});
|
||||||
|
await adminClient.realms.testLDAPConnection(
|
||||||
|
{ realm },
|
||||||
|
{ ...settings, action: "testConnection" }
|
||||||
|
);
|
||||||
|
addAlert(t("testSuccess"), AlertVariant.success);
|
||||||
|
} catch (error) {
|
||||||
|
addAlert(t("testError"), AlertVariant.danger);
|
||||||
|
console.error(error.response?.data?.errorMessage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const [
|
const [
|
||||||
isTruststoreSpiDropdownOpen,
|
isTruststoreSpiDropdownOpen,
|
||||||
|
@ -219,7 +257,7 @@ export const LdapSettingsConnection = ({
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name="config.authType[0]"
|
name="config.authType[0]"
|
||||||
defaultValue=""
|
defaultValue="none"
|
||||||
control={form.control}
|
control={form.control}
|
||||||
render={({ onChange, value }) => (
|
render={({ onChange, value }) => (
|
||||||
<Select
|
<Select
|
||||||
|
@ -311,9 +349,12 @@ export const LdapSettingsConnection = ({
|
||||||
)}
|
)}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup fieldId="kc-test-button">
|
<FormGroup fieldId="kc-test-button">
|
||||||
{" "}
|
<Button
|
||||||
{/* TODO: whatever this button is supposed to do */}
|
isDisabled={!form.formState.isValid}
|
||||||
<Button variant="secondary" id="kc-test-button">
|
variant="secondary"
|
||||||
|
id="kc-test-button"
|
||||||
|
onClick={() => testLdap()}
|
||||||
|
>
|
||||||
{t("common:test")}
|
{t("common:test")}
|
||||||
</Button>
|
</Button>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
|
@ -84,6 +84,8 @@
|
||||||
"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}",
|
||||||
|
"testSuccess": "Successfully connected to LDAP",
|
||||||
|
"testError": "Error when trying to connect to LDAP. See server.log for details.",
|
||||||
|
|
||||||
"learnMore": "Learn more",
|
"learnMore": "Learn more",
|
||||||
"addNewProvider": "Add new provider",
|
"addNewProvider": "Add new provider",
|
||||||
|
|
Loading…
Reference in a new issue