diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java index c4605e9c101d..daa054e944f0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java @@ -98,6 +98,7 @@ public ContextSource ldapContextSource() { source.setPassword(this.embeddedProperties.getCredential().getPassword()); } source.setUrls(this.properties.determineUrls(this.environment)); + source.setBase(this.properties.getBase()); return source; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java index 124e27e4ad0b..4908fc4f9dcf 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java @@ -131,6 +131,21 @@ public void testQueryEmbeddedLdap() throws LDAPException { assertThat(ldapTemplate.list("ou=company1,c=Sweden,dc=spring,dc=org")).hasSize(4); } + @Test + public void testQueryEmbeddedLdapWithBase() throws LDAPException { + TestPropertyValues.of("spring.ldap.embedded.base-dn:dc=spring,dc=org", + "spring.ldap.base:dc=spring,dc=org") + .applyTo(this.context); + this.context.register(EmbeddedLdapAutoConfiguration.class, + LdapAutoConfiguration.class, LdapDataAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertThat(this.context.getBeanNamesForType(LdapTemplate.class).length) + .isEqualTo(1); + LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class); + assertThat(ldapTemplate.list("ou=company1,c=Sweden")).hasSize(4); + } + @Test public void testDisableSchemaValidation() throws LDAPException { load("spring.ldap.embedded.validation.enabled:false",