Populate base for embedded LDAPContextSource

Fixes gh-23030
This commit is contained in:
Madhura Bhave 2022-10-07 13:20:45 -07:00
parent 533f3017d4
commit 263433cd81
2 changed files with 10 additions and 0 deletions

View File

@ -205,6 +205,7 @@ public class EmbeddedLdapAutoConfiguration {
LdapContextSource ldapContextSource(Environment environment, LdapProperties properties,
EmbeddedLdapProperties embeddedProperties) {
LdapContextSource source = new LdapContextSource();
source.setBase(properties.getBase());
if (embeddedProperties.getCredential().isAvailable()) {
source.setUserDn(embeddedProperties.getCredential().getUsername());
source.setPassword(embeddedProperties.getCredential().getPassword());

View File

@ -178,6 +178,15 @@ class EmbeddedLdapAutoConfigurationTests {
});
}
@Test
void ldapContextIsCreatedWithBase() {
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org",
"spring.ldap.base:dc=spring,dc=org").run((context) -> {
LdapContextSource ldapContextSource = context.getBean(LdapContextSource.class);
assertThat(ldapContextSource.getBaseLdapPathAsString()).isEqualTo("dc=spring,dc=org");
});
}
@Configuration(proxyBeanMethods = false)
static class LdapClientConfiguration {