Commit 04b63cda authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.1.x'

Closes gh-17889
parents 76dfe1aa 3a20b1d9
...@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
...@@ -46,12 +47,14 @@ public class LdapAutoConfiguration { ...@@ -46,12 +47,14 @@ public class LdapAutoConfiguration {
@ConditionalOnMissingBean @ConditionalOnMissingBean
public LdapContextSource ldapContextSource(LdapProperties properties, Environment environment) { public LdapContextSource ldapContextSource(LdapProperties properties, Environment environment) {
LdapContextSource source = new LdapContextSource(); LdapContextSource source = new LdapContextSource();
source.setUserDn(properties.getUsername()); PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
source.setPassword(properties.getPassword()); propertyMapper.from(properties.getUsername()).to(source::setUserDn);
source.setAnonymousReadOnly(properties.getAnonymousReadOnly()); propertyMapper.from(properties.getPassword()).to(source::setPassword);
source.setBase(properties.getBase()); propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
source.setUrls(properties.determineUrls(environment)); propertyMapper.from(properties.getBase()).to(source::setBase);
source.setBaseEnvironmentProperties(Collections.unmodifiableMap(properties.getBaseEnvironment())); propertyMapper.from(properties.determineUrls(environment)).to(source::setUrls);
propertyMapper.from(properties.getBaseEnvironment()).to(
(baseEnvironment) -> source.setBaseEnvironmentProperties(Collections.unmodifiableMap(baseEnvironment)));
return source; return source;
} }
......
...@@ -87,6 +87,17 @@ class LdapAutoConfigurationTests { ...@@ -87,6 +87,17 @@ class LdapAutoConfigurationTests {
}); });
} }
@Test
void contextSourceWithNoCustomization() {
this.contextRunner.run((context) -> {
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
assertThat(contextSource.getUserDn()).isEqualTo("");
assertThat(contextSource.getPassword()).isEqualTo("");
assertThat(contextSource.isAnonymousReadOnly()).isFalse();
assertThat(contextSource.getBaseLdapPathAsString()).isEqualTo("");
});
}
@Test @Test
void templateExists() { void templateExists() {
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:389") this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:389")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment