From 263433cd8136c6cd48375eb747a970e3bb344a9d Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Fri, 7 Oct 2022 13:20:45 -0700 Subject: [PATCH] Populate base for embedded LDAPContextSource Fixes gh-23030 --- .../ldap/embedded/EmbeddedLdapAutoConfiguration.java | 1 + .../embedded/EmbeddedLdapAutoConfigurationTests.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java index b8c897123d..7f192fabbe 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java @@ -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()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java index dc3d02c6f9..efacb6f4ff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java @@ -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 {