diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java index bad5dc1950..07d43eb9d3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java @@ -17,14 +17,13 @@ package org.springframework.boot.autoconfigure.ldap; import java.util.Collections; -import java.util.Optional; +import java.util.Locale; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.ldap.LdapProperties.Referral; import org.springframework.boot.autoconfigure.ldap.LdapProperties.Template; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.PropertyMapper; @@ -69,7 +68,9 @@ public class LdapAutoConfiguration { propertyMapper.from(connectionDetails.getUsername()).to(source::setUserDn); propertyMapper.from(connectionDetails.getPassword()).to(source::setPassword); propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly); - Optional.ofNullable(properties.getReferral()).map(Referral::getMode).ifPresent(source::setReferral); + propertyMapper.from(properties.getReferral()) + .as(((referral) -> referral.name().toLowerCase(Locale.ROOT))) + .to(source::setReferral); propertyMapper.from(connectionDetails.getBase()).to(source::setBase); propertyMapper.from(connectionDetails.getUrls()).to(source::setUrls); propertyMapper.from(properties.getBaseEnvironment()) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java index cbb7edbdc2..8ca76d59ab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java @@ -64,7 +64,8 @@ public class LdapProperties { private Boolean anonymousReadOnly; /** - * Set the method to handle referrals. + * Specify how referrals encountered by the service provider are to be processed. If + * not specified, the default is determined by the provider. */ private Referral referral; @@ -197,34 +198,24 @@ public class LdapProperties { } /** - * Enum to define how referrals encountered by the service provider are to be processed. + * Define the methods to handle referrals. */ public enum Referral { /** - * follow referrals automatically + * Follow referrals automatically. */ - FOLLOW("follow"), + FOLLOW, /** - * ignore referrals + * Ignore referrals. */ - IGNORE("ignore"), + IGNORE, /** - * throw a {@link ReferralException} for each referral + * Throw {@link ReferralException} when a referral is encountered. */ - THROW("throw"); - - private final String mode; - - Referral(String mode) { - this.mode = mode; - } - - public String getMode() { - return this.mode; - } + THROW } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java index 7c2adb243b..d36350b1f6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java @@ -38,7 +38,6 @@ import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.springframework.test.util.ReflectionTestUtils.getField; /** * Tests for {@link LdapAutoConfiguration}. @@ -93,7 +92,7 @@ class LdapAutoConfigurationTests { void contextSourceWithReferral() { this.contextRunner.withPropertyValues("spring.ldap.referral:ignore").run((context) -> { LdapContextSource contextSource = context.getBean(LdapContextSource.class); - assertThat(getField(contextSource, "referral")).isEqualTo("ignore"); + assertThat(contextSource).hasFieldOrPropertyWithValue("referral", "ignore"); }); }