|
22 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
23 | 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
24 | 24 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 25 | +import org.springframework.boot.context.properties.PropertyMapper; |
25 | 26 | import org.springframework.context.annotation.Bean; |
26 | 27 | import org.springframework.context.annotation.Configuration; |
27 | 28 | import org.springframework.core.env.Environment; |
@@ -55,12 +56,14 @@ public LdapAutoConfiguration(LdapProperties properties, Environment environment) |
55 | 56 | @ConditionalOnMissingBean |
56 | 57 | public LdapContextSource ldapContextSource() { |
57 | 58 | LdapContextSource source = new LdapContextSource(); |
58 | | - source.setUserDn(this.properties.getUsername()); |
59 | | - source.setPassword(this.properties.getPassword()); |
60 | | - source.setAnonymousReadOnly(this.properties.getAnonymousReadOnly()); |
61 | | - source.setBase(this.properties.getBase()); |
62 | | - source.setUrls(this.properties.determineUrls(this.environment)); |
63 | | - source.setBaseEnvironmentProperties(Collections.unmodifiableMap(this.properties.getBaseEnvironment())); |
| 59 | + PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); |
| 60 | + propertyMapper.from(this.properties.getUsername()).to(source::setUserDn); |
| 61 | + propertyMapper.from(this.properties.getPassword()).to(source::setPassword); |
| 62 | + propertyMapper.from(this.properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly); |
| 63 | + propertyMapper.from(this.properties.getBase()).to(source::setBase); |
| 64 | + propertyMapper.from(this.properties.determineUrls(this.environment)).to(source::setUrls); |
| 65 | + propertyMapper.from(this.properties.getBaseEnvironment()).to( |
| 66 | + (baseEnvironment) -> source.setBaseEnvironmentProperties(Collections.unmodifiableMap(baseEnvironment))); |
64 | 67 | return source; |
65 | 68 | } |
66 | 69 |
|
|
0 commit comments