Skip to content

Commit 686628d

Browse files
committed
Polish "Add support for configuring LDAP's referral property"
See gh-44850
1 parent 59705ed commit 686628d

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
package org.springframework.boot.autoconfigure.ldap;
1818

1919
import java.util.Collections;
20-
import java.util.Optional;
20+
import java.util.Locale;
2121

2222
import org.springframework.beans.factory.ObjectProvider;
2323
import org.springframework.boot.autoconfigure.AutoConfiguration;
2424
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
27-
import org.springframework.boot.autoconfigure.ldap.LdapProperties.Referral;
2827
import org.springframework.boot.autoconfigure.ldap.LdapProperties.Template;
2928
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3029
import org.springframework.boot.context.properties.PropertyMapper;
@@ -69,7 +68,9 @@ public LdapContextSource ldapContextSource(LdapConnectionDetails connectionDetai
6968
propertyMapper.from(connectionDetails.getUsername()).to(source::setUserDn);
7069
propertyMapper.from(connectionDetails.getPassword()).to(source::setPassword);
7170
propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
72-
Optional.ofNullable(properties.getReferral()).map(Referral::getMode).ifPresent(source::setReferral);
71+
propertyMapper.from(properties.getReferral())
72+
.as(((referral) -> referral.name().toLowerCase(Locale.ROOT)))
73+
.to(source::setReferral);
7374
propertyMapper.from(connectionDetails.getBase()).to(source::setBase);
7475
propertyMapper.from(connectionDetails.getUrls()).to(source::setUrls);
7576
propertyMapper.from(properties.getBaseEnvironment())

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

+9-18
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public class LdapProperties {
6464
private Boolean anonymousReadOnly;
6565

6666
/**
67-
* Set the method to handle referrals.
67+
* Specify how referrals encountered by the service provider are to be processed. If
68+
* not specified, the default is determined by the provider.
6869
*/
6970
private Referral referral;
7071

@@ -197,34 +198,24 @@ public void setIgnoreSizeLimitExceededException(Boolean ignoreSizeLimitExceededE
197198
}
198199

199200
/**
200-
* Enum to define how referrals encountered by the service provider are to be processed.
201+
* Define the methods to handle referrals.
201202
*/
202203
public enum Referral {
203204

204205
/**
205-
* follow referrals automatically
206+
* Follow referrals automatically.
206207
*/
207-
FOLLOW("follow"),
208+
FOLLOW,
208209

209210
/**
210-
* ignore referrals
211+
* Ignore referrals.
211212
*/
212-
IGNORE("ignore"),
213+
IGNORE,
213214

214215
/**
215-
* throw a {@link ReferralException} for each referral
216+
* Throw {@link ReferralException} when a referral is encountered.
216217
*/
217-
THROW("throw");
218-
219-
private final String mode;
220-
221-
Referral(String mode) {
222-
this.mode = mode;
223-
}
224-
225-
public String getMode() {
226-
return this.mode;
227-
}
218+
THROW
228219

229220
}
230221

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
4040
import static org.mockito.Mockito.mock;
41-
import static org.springframework.test.util.ReflectionTestUtils.getField;
4241

4342
/**
4443
* Tests for {@link LdapAutoConfiguration}.
@@ -93,7 +92,7 @@ void contextSourceWithUserDoesNotEnableAnonymousReadOnly() {
9392
void contextSourceWithReferral() {
9493
this.contextRunner.withPropertyValues("spring.ldap.referral:ignore").run((context) -> {
9594
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
96-
assertThat(getField(contextSource, "referral")).isEqualTo("ignore");
95+
assertThat(contextSource).hasFieldOrPropertyWithValue("referral", "ignore");
9796
});
9897
}
9998

0 commit comments

Comments
 (0)