commit
04b63cda8f
|
@ -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 {
|
|||
@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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue