Skip to content

Commit 7821cb8

Browse files
committed
Merge pull request #44850 from dobrosi
* pr/44850: Polish "Add support for configuring LDAP's referral property" Add support for configuring LDAP's referral property Closes gh-44850
2 parents f8047ff + 686628d commit 7821cb8

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

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

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

1919
import java.util.Collections;
20+
import java.util.Locale;
2021

2122
import org.springframework.beans.factory.ObjectProvider;
2223
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -67,6 +68,9 @@ public LdapContextSource ldapContextSource(LdapConnectionDetails connectionDetai
6768
propertyMapper.from(connectionDetails.getUsername()).to(source::setUserDn);
6869
propertyMapper.from(connectionDetails.getPassword()).to(source::setPassword);
6970
propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
71+
propertyMapper.from(properties.getReferral())
72+
.as(((referral) -> referral.name().toLowerCase(Locale.ROOT)))
73+
.to(source::setReferral);
7074
propertyMapper.from(connectionDetails.getBase()).to(source::setBase);
7175
propertyMapper.from(connectionDetails.getUrls()).to(source::setUrls);
7276
propertyMapper.from(properties.getBaseEnvironment())

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

+37
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.boot.context.properties.ConfigurationProperties;
2323
import org.springframework.core.env.Environment;
24+
import org.springframework.ldap.ReferralException;
2425
import org.springframework.ldap.core.LdapTemplate;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.ObjectUtils;
@@ -62,6 +63,12 @@ public class LdapProperties {
6263
*/
6364
private Boolean anonymousReadOnly;
6465

66+
/**
67+
* Specify how referrals encountered by the service provider are to be processed. If
68+
* not specified, the default is determined by the provider.
69+
*/
70+
private Referral referral;
71+
6572
/**
6673
* LDAP specification settings.
6774
*/
@@ -109,6 +116,14 @@ public void setAnonymousReadOnly(Boolean anonymousReadOnly) {
109116
this.anonymousReadOnly = anonymousReadOnly;
110117
}
111118

119+
public Referral getReferral() {
120+
return this.referral;
121+
}
122+
123+
public void setReferral(Referral referral) {
124+
this.referral = referral;
125+
}
126+
112127
public Map<String, String> getBaseEnvironment() {
113128
return this.baseEnvironment;
114129
}
@@ -182,4 +197,26 @@ public void setIgnoreSizeLimitExceededException(Boolean ignoreSizeLimitExceededE
182197

183198
}
184199

200+
/**
201+
* Define the methods to handle referrals.
202+
*/
203+
public enum Referral {
204+
205+
/**
206+
* Follow referrals automatically.
207+
*/
208+
FOLLOW,
209+
210+
/**
211+
* Ignore referrals.
212+
*/
213+
IGNORE,
214+
215+
/**
216+
* Throw {@link ReferralException} when a referral is encountered.
217+
*/
218+
THROW
219+
220+
}
221+
185222
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ void contextSourceWithUserDoesNotEnableAnonymousReadOnly() {
8888
});
8989
}
9090

91+
@Test
92+
void contextSourceWithReferral() {
93+
this.contextRunner.withPropertyValues("spring.ldap.referral:ignore").run((context) -> {
94+
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
95+
assertThat(contextSource).hasFieldOrPropertyWithValue("referral", "ignore");
96+
});
97+
}
98+
9199
@Test
92100
void contextSourceWithExtraCustomization() {
93101
this.contextRunner

0 commit comments

Comments
 (0)