2020-10-30 20:15:37 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
FormGroup,
|
|
|
|
InputGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
2020-11-25 14:50:40 +00:00
|
|
|
SelectVariant,
|
2020-10-30 20:15:37 +00:00
|
|
|
Switch,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-12-16 07:02:41 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2020-11-25 14:50:40 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { convertToFormValues } from "../../util";
|
2020-11-25 14:50:40 +00:00
|
|
|
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
2020-10-30 20:15:37 +00:00
|
|
|
import { EyeIcon } from "@patternfly/react-icons";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2021-01-05 13:39:27 +00:00
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
|
|
|
export const LdapSettingsConnection = () => {
|
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
const helpText = useTranslation("user-federation-help").t;
|
2020-12-16 07:02:41 +00:00
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { register, control, setValue } = useForm<ComponentRepresentation>();
|
|
|
|
const { id } = useParams<{ id: string }>();
|
|
|
|
|
|
|
|
const convertTruststoreSpiValues = (truststoreValue: string) => {
|
|
|
|
switch (truststoreValue) {
|
|
|
|
case "always":
|
|
|
|
return `${t("always")}`;
|
|
|
|
case "never":
|
|
|
|
return `${t("never")}`;
|
|
|
|
case "ldapsOnly":
|
|
|
|
default:
|
|
|
|
return `${t("onlyLdaps")}`;
|
|
|
|
}
|
|
|
|
};
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2020-11-25 14:50:40 +00:00
|
|
|
const [
|
|
|
|
isTruststoreSpiDropdownOpen,
|
|
|
|
setIsTruststoreSpiDropdownOpen,
|
|
|
|
] = useState(false);
|
2020-11-25 16:17:50 +00:00
|
|
|
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isBindTypeDropdownOpen, setIsBindTypeDropdownOpen] = useState(false);
|
2020-11-25 16:17:50 +00:00
|
|
|
|
2020-12-16 07:02:41 +00:00
|
|
|
const setupForm = (component: ComponentRepresentation) => {
|
|
|
|
Object.entries(component).map((entry) => {
|
|
|
|
if (entry[0] === "config") {
|
|
|
|
convertToFormValues(entry[1], "config", setValue);
|
|
|
|
if (entry[1].useTruststoreSpi) {
|
|
|
|
setValue(
|
|
|
|
"config.useTruststoreSpi",
|
|
|
|
convertTruststoreSpiValues(entry[1].useTruststoreSpi[0])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-01-05 13:39:27 +00:00
|
|
|
return useFetch(
|
|
|
|
() => adminClient.components.findOne({ id }),
|
|
|
|
(fetchedComponent) => setupForm(fetchedComponent)
|
|
|
|
);
|
2020-12-16 07:02:41 +00:00
|
|
|
}, []);
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("connectionURL")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("consoleDisplayConnectionUrlHelp")}
|
|
|
|
forLabel={t("connectionURL")}
|
2020-11-25 14:50:40 +00:00
|
|
|
forID="kc-console-connection-url"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2020-11-25 14:50:40 +00:00
|
|
|
fieldId="kc-console-connection-url"
|
2020-10-30 20:15:37 +00:00
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
2020-11-25 14:50:40 +00:00
|
|
|
id="kc-console-connection-url"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.connectionUrl"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
2020-11-25 14:50:40 +00:00
|
|
|
label={t("enableStartTls")}
|
2020-10-30 20:15:37 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2020-11-25 14:50:40 +00:00
|
|
|
helpText={helpText("enableStartTlsHelp")}
|
|
|
|
forLabel={t("enableStartTls")}
|
2020-10-30 20:15:37 +00:00
|
|
|
forID="kc-enable-start-tls"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-enable-start-tls"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.startTls"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id={"kc-enable-start-tls"}
|
2020-12-16 07:02:41 +00:00
|
|
|
isChecked={value[0] === "true"}
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
|
|
|
onChange={onChange}
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup
|
|
|
|
label={t("useTruststoreSpi")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("useTruststoreSpiHelp")}
|
|
|
|
forLabel={t("useTruststoreSpi")}
|
|
|
|
forID="kc-use-truststore-spi"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-use-truststore-spi"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.useTruststoreSpi"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-use-truststore-spi"
|
|
|
|
onToggle={() =>
|
|
|
|
setIsTruststoreSpiDropdownOpen(!isTruststoreSpiDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isTruststoreSpiDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsTruststoreSpiDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<SelectOption key={0} value={t("always")} />
|
|
|
|
<SelectOption key={1} value={t("onlyLdaps")} />
|
|
|
|
<SelectOption key={2} value={t("never")} />
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("connectionPooling")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("connectionPoolingHelp")}
|
|
|
|
forLabel={t("connectionPooling")}
|
|
|
|
forID="kc-connection-pooling"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-connection-pooling"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.connectionPooling"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id={"kc-connection-pooling"}
|
|
|
|
isDisabled={false}
|
|
|
|
onChange={onChange}
|
2020-12-16 07:02:41 +00:00
|
|
|
isChecked={value[0] === "true"}
|
2020-11-25 14:50:40 +00:00
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("connectionTimeout")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("connectionTimeoutHelp")}
|
|
|
|
forLabel={t("connectionTimeout")}
|
2020-11-25 14:50:40 +00:00
|
|
|
forID="kc-console-connection-timeout"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2020-11-25 14:50:40 +00:00
|
|
|
fieldId="kc-console-connection-timeout"
|
2020-10-30 20:15:37 +00:00
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
2020-11-25 14:50:40 +00:00
|
|
|
id="kc-console-connection-timeout"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.connectionTimeout"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("bindType")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("bindTypeHelp")}
|
|
|
|
forLabel={t("bindType")}
|
|
|
|
forID="kc-bind-type"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-bind-type"
|
|
|
|
isRequired
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.authType"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-bind-type"
|
|
|
|
required
|
|
|
|
onToggle={() =>
|
|
|
|
setIsBindTypeDropdownOpen(!isBindTypeDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isBindTypeDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsBindTypeDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<SelectOption key={3} value="simple" />
|
|
|
|
<SelectOption key={4} value="none" />
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("bindDn")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("bindDnHelp")}
|
|
|
|
forLabel={t("bindDn")}
|
2020-11-25 14:50:40 +00:00
|
|
|
forID="kc-console-bind-dn"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2020-11-25 14:50:40 +00:00
|
|
|
fieldId="kc-console-bind-dn"
|
2020-10-30 20:15:37 +00:00
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
2020-11-25 14:50:40 +00:00
|
|
|
id="kc-console-bind-dn"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.bindDn"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("bindCredentials")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("bindCredentialsHelp")}
|
|
|
|
forLabel={t("bindCredentials")}
|
2020-11-25 14:50:40 +00:00
|
|
|
forID="kc-console-bind-credentials"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2020-11-25 14:50:40 +00:00
|
|
|
fieldId="kc-console-bind-credentials"
|
2020-10-30 20:15:37 +00:00
|
|
|
isRequired
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
{/* TODO: MF The input group below throws a 'React does not recognize the `isDisabled` prop on a DOM element' error */}
|
2020-10-30 20:15:37 +00:00
|
|
|
<InputGroup>
|
2020-11-25 16:17:50 +00:00
|
|
|
<TextInput // TODO: Make password field switch to type=text with button
|
2020-10-30 20:15:37 +00:00
|
|
|
isRequired
|
2020-11-25 16:17:50 +00:00
|
|
|
type="password"
|
2020-11-25 14:50:40 +00:00
|
|
|
id="kc-console-bind-credentials"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.bindCredential"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
variant="control"
|
|
|
|
aria-label="show password button for bind credentials"
|
|
|
|
>
|
|
|
|
<EyeIcon />
|
|
|
|
</Button>
|
|
|
|
</InputGroup>
|
|
|
|
</FormGroup>
|
2020-11-25 14:50:40 +00:00
|
|
|
<FormGroup fieldId="kc-test-button">
|
2020-11-25 16:17:50 +00:00
|
|
|
{" "}
|
|
|
|
{/* TODO: whatever this button is supposed to do */}
|
2020-11-25 14:50:40 +00:00
|
|
|
<Button variant="secondary" id="kc-test-button">
|
|
|
|
Test
|
|
|
|
</Button>
|
|
|
|
</FormGroup>
|
2020-11-25 16:17:50 +00:00
|
|
|
</FormAccess>
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|