mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SSO LDAP: Fix search base dns parsing (#93179)
* Fix parse of * Add i18n files * Add default value * Replace input field with multiselect * rename delete form function * Use Controller for MultiSelect
This commit is contained in:
parent
1ea873950b
commit
fb0d3b944a
@ -1,6 +1,6 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { Dispatch, SetStateAction, useEffect, useId, useState } from 'react';
|
import { Dispatch, SetStateAction, useEffect, useId, useState } from 'react';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { Controller, useFormContext } from 'react-hook-form';
|
||||||
|
|
||||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
@ -49,7 +49,7 @@ export const LdapDrawerComponent = ({
|
|||||||
const [encryptionProvider, setEncryptionProvider] = useState(EncryptionProvider.Base64);
|
const [encryptionProvider, setEncryptionProvider] = useState(EncryptionProvider.Base64);
|
||||||
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const { getValues, register, setValue, watch } = useFormContext<LdapPayload>();
|
const { control, getValues, register, setValue, watch } = useFormContext<LdapPayload>();
|
||||||
|
|
||||||
const nameId = useId();
|
const nameId = useId();
|
||||||
const surnameId = useId();
|
const surnameId = useId();
|
||||||
@ -335,19 +335,17 @@ export const LdapDrawerComponent = ({
|
|||||||
'Root CA certificate content'
|
'Root CA certificate content'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<MultiSelect
|
<Controller
|
||||||
id="root-ca-cert"
|
name={`${serverConfig}.root_ca_cert_value`}
|
||||||
allowCustomValue
|
control={control}
|
||||||
onChange={(v) => {
|
render={({ field: { onChange, value, ...field } }) => (
|
||||||
setValue(
|
<MultiSelect
|
||||||
`${serverConfig}.root_ca_cert_value`,
|
{...field}
|
||||||
v.filter(({ v }) => typeof v === 'string')?.map(({ v }) => v)
|
allowCustomValue
|
||||||
);
|
onChange={(v) => onChange(v.map(({ value }) => String(value)))}
|
||||||
}}
|
value={value?.map((v) => ({ label: renderMultiSelectLabel(v), value: v }))}
|
||||||
value={watch(`${serverConfig}.root_ca_cert_value`)?.map((v) => ({
|
/>
|
||||||
label: renderMultiSelectLabel(v),
|
)}
|
||||||
value: v,
|
|
||||||
}))}
|
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field
|
<Field
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { FormProvider, useForm } from 'react-hook-form';
|
import { Controller, FormProvider, useForm } from 'react-hook-form';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { AppEvents, GrafanaTheme2, NavModelItem } from '@grafana/data';
|
import { AppEvents, GrafanaTheme2, NavModelItem } from '@grafana/data';
|
||||||
@ -19,6 +19,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
TextLink,
|
TextLink,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
|
MultiSelect,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
import { Page } from 'app/core/components/Page/Page';
|
import { Page } from 'app/core/components/Page/Page';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
@ -44,6 +45,8 @@ const pageNav: NavModelItem = {
|
|||||||
id: 'LDAP',
|
id: 'LDAP',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const serverConfig = 'settings.config.servers.0';
|
||||||
|
|
||||||
const emptySettings: LdapPayload = {
|
const emptySettings: LdapPayload = {
|
||||||
id: '',
|
id: '',
|
||||||
provider: '',
|
provider: '',
|
||||||
@ -104,7 +107,7 @@ export const LdapSettingsPage = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const methods = useForm<LdapPayload>({ defaultValues: emptySettings });
|
const methods = useForm<LdapPayload>({ defaultValues: emptySettings });
|
||||||
const { getValues, handleSubmit, register, reset, watch } = methods;
|
const { control, getValues, handleSubmit, register, reset, watch } = methods;
|
||||||
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
@ -207,7 +210,7 @@ export const LdapSettingsPage = () => {
|
|||||||
const saveForm = () => {
|
const saveForm = () => {
|
||||||
putPayload(getValues());
|
putPayload(getValues());
|
||||||
};
|
};
|
||||||
const discardForm = async () => {
|
const deleteLDAPConfig = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await getBackendSrv().delete('/api/v1/sso-settings/ldap');
|
await getBackendSrv().delete('/api/v1/sso-settings/ldap');
|
||||||
@ -273,7 +276,7 @@ export const LdapSettingsPage = () => {
|
|||||||
id="host"
|
id="host"
|
||||||
placeholder={t('ldap-settings-page.host.placeholder', 'example: 127.0.0.1')}
|
placeholder={t('ldap-settings-page.host.placeholder', 'example: 127.0.0.1')}
|
||||||
type="text"
|
type="text"
|
||||||
{...register('settings.config.servers.0.host', { required: true })}
|
{...register(`${serverConfig}.host`, { required: true })}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field
|
<Field
|
||||||
@ -287,14 +290,14 @@ export const LdapSettingsPage = () => {
|
|||||||
id="bind-dn"
|
id="bind-dn"
|
||||||
placeholder={t('ldap-settings-page.bind-dn.placeholder', 'example: cn=admin,dc=grafana,dc=org')}
|
placeholder={t('ldap-settings-page.bind-dn.placeholder', 'example: cn=admin,dc=grafana,dc=org')}
|
||||||
type="text"
|
type="text"
|
||||||
{...register('settings.config.servers.0.bind_dn')}
|
{...register(`${serverConfig}.bind_dn`)}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field label={t('ldap-settings-page.bind-password.label', 'Bind password')}>
|
<Field label={t('ldap-settings-page.bind-password.label', 'Bind password')}>
|
||||||
<Input
|
<Input
|
||||||
id="bind-password"
|
id="bind-password"
|
||||||
type="text"
|
type="text"
|
||||||
{...register('settings.config.servers.0.bind_password', { required: false })}
|
{...register(`${serverConfig}.bind_password`, { required: false })}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field
|
<Field
|
||||||
@ -308,22 +311,27 @@ export const LdapSettingsPage = () => {
|
|||||||
id="search_filter"
|
id="search_filter"
|
||||||
placeholder={t('ldap-settings-page.search_filter.placeholder', 'example: cn=%s')}
|
placeholder={t('ldap-settings-page.search_filter.placeholder', 'example: cn=%s')}
|
||||||
type="text"
|
type="text"
|
||||||
{...register('settings.config.servers.0.search_filter', { required: true })}
|
{...register(`${serverConfig}.search_filter`, { required: true })}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field
|
<Field
|
||||||
label={t('ldap-settings-page.search-base-dns.label', 'Search base DNS *')}
|
label={t('ldap-settings-page.search-base-dns.label', 'Search base DNS *')}
|
||||||
description={t(
|
description={t(
|
||||||
'ldap-settings-page.search-base-dns.description',
|
'ldap-settings-page.search-base-dns.description',
|
||||||
'An array of base dns to search through; separate by commas or spaces.'
|
'An array of base dns to search through.'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Input
|
<Controller
|
||||||
id="search-base-dns"
|
name={`${serverConfig}.search_base_dns`}
|
||||||
placeholder={t('ldap-settings-page.search-base-dns.placeholder', 'example: "dc=grafana.dc=org"')}
|
control={control}
|
||||||
type="text"
|
render={({ field: { onChange, ...field } }) => (
|
||||||
{...register('settings.config.servers.0.search_base_dns', { required: true })}
|
<MultiSelect
|
||||||
/>
|
{...field}
|
||||||
|
allowCustomValue
|
||||||
|
onChange={(v) => onChange(v.map(({ value }) => String(value)))}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
></Controller>
|
||||||
</Field>
|
</Field>
|
||||||
<Box borderColor="strong" borderStyle="solid" padding={2} width={68}>
|
<Box borderColor="strong" borderStyle="solid" padding={2} width={68}>
|
||||||
<Stack alignItems={'center'} direction={'row'} gap={2} justifyContent={'space-between'}>
|
<Stack alignItems={'center'} direction={'row'} gap={2} justifyContent={'space-between'}>
|
||||||
@ -356,7 +364,7 @@ export const LdapSettingsPage = () => {
|
|||||||
<Dropdown
|
<Dropdown
|
||||||
overlay={
|
overlay={
|
||||||
<Menu>
|
<Menu>
|
||||||
<Menu.Item label="Reset to default values" icon="history-alt" onClick={discardForm} />
|
<Menu.Item label="Reset to default values" icon="history-alt" onClick={deleteLDAPConfig} />
|
||||||
</Menu>
|
</Menu>
|
||||||
}
|
}
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
|
@ -1178,9 +1178,8 @@
|
|||||||
"placeholder": "example: cn=%s"
|
"placeholder": "example: cn=%s"
|
||||||
},
|
},
|
||||||
"search-base-dns": {
|
"search-base-dns": {
|
||||||
"description": "An array of base dns to search through; separate by commas or spaces.",
|
"description": "An array of base dns to search through.",
|
||||||
"label": "Search base DNS *",
|
"label": "Search base DNS *"
|
||||||
"placeholder": "example: \"dc=grafana.dc=org\""
|
|
||||||
},
|
},
|
||||||
"subtitle": "The LDAP integration in Grafana allows your Grafana users to log in with their LDAP credentials. Find out more in our <2><0>documentation</0></2>.",
|
"subtitle": "The LDAP integration in Grafana allows your Grafana users to log in with their LDAP credentials. Find out more in our <2><0>documentation</0></2>.",
|
||||||
"title": "Basic Settings"
|
"title": "Basic Settings"
|
||||||
|
@ -1178,9 +1178,8 @@
|
|||||||
"placeholder": "ęχämpľę: čʼn=%ş"
|
"placeholder": "ęχämpľę: čʼn=%ş"
|
||||||
},
|
},
|
||||||
"search-base-dns": {
|
"search-base-dns": {
|
||||||
"description": "Åʼn äřřäy őƒ þäşę đʼnş ŧő şęäřčĥ ŧĥřőūģĥ; şępäřäŧę þy čőmmäş őř şpäčęş.",
|
"description": "Åʼn äřřäy őƒ þäşę đʼnş ŧő şęäřčĥ ŧĥřőūģĥ.",
|
||||||
"label": "Ŝęäřčĥ þäşę ĐŃŜ *",
|
"label": "Ŝęäřčĥ þäşę ĐŃŜ *"
|
||||||
"placeholder": "ęχämpľę: \"đč=ģřäƒäʼnä.đč=őřģ\""
|
|
||||||
},
|
},
|
||||||
"subtitle": "Ŧĥę ĿĐÅP įʼnŧęģřäŧįőʼn įʼn Ğřäƒäʼnä äľľőŵş yőūř Ğřäƒäʼnä ūşęřş ŧő ľőģ įʼn ŵįŧĥ ŧĥęįř ĿĐÅP čřęđęʼnŧįäľş. Fįʼnđ őūŧ mőřę įʼn őūř <2><0>đőčūmęʼnŧäŧįőʼn</0></2>.",
|
"subtitle": "Ŧĥę ĿĐÅP įʼnŧęģřäŧįőʼn įʼn Ğřäƒäʼnä äľľőŵş yőūř Ğřäƒäʼnä ūşęřş ŧő ľőģ įʼn ŵįŧĥ ŧĥęįř ĿĐÅP čřęđęʼnŧįäľş. Fįʼnđ őūŧ mőřę įʼn őūř <2><0>đőčūmęʼnŧäŧįőʼn</0></2>.",
|
||||||
"title": "ßäşįč Ŝęŧŧįʼnģş"
|
"title": "ßäşįč Ŝęŧŧįʼnģş"
|
||||||
|
Loading…
Reference in New Issue
Block a user