Browse Source

Merge branch '2.1.x'

Closes gh-17889
pull/17893/head
Stephane Nicoll 7 years ago
parent
commit
04b63cda8f
  1. 15
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
  2. 11
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java

15
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java

@ -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.ConditionalOnMissingBean;
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.Configuration;
import org.springframework.core.env.Environment;
@ -46,12 +47,14 @@ public class LdapAutoConfiguration { @@ -46,12 +47,14 @@ public class LdapAutoConfiguration {
@ConditionalOnMissingBean
public LdapContextSource ldapContextSource(LdapProperties properties, Environment environment) {
LdapContextSource source = new LdapContextSource();
source.setUserDn(properties.getUsername());
source.setPassword(properties.getPassword());
source.setAnonymousReadOnly(properties.getAnonymousReadOnly());
source.setBase(properties.getBase());
source.setUrls(properties.determineUrls(environment));
source.setBaseEnvironmentProperties(Collections.unmodifiableMap(properties.getBaseEnvironment()));
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
propertyMapper.from(properties.getUsername()).to(source::setUserDn);
propertyMapper.from(properties.getPassword()).to(source::setPassword);
propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
propertyMapper.from(properties.getBase()).to(source::setBase);
propertyMapper.from(properties.determineUrls(environment)).to(source::setUrls);
propertyMapper.from(properties.getBaseEnvironment()).to(
(baseEnvironment) -> source.setBaseEnvironmentProperties(Collections.unmodifiableMap(baseEnvironment)));
return source;
}

11
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java

@ -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
void templateExists() {
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:389")

Loading…
Cancel
Save