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 db02437662cc..5dce6a99bd43 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,9 +56,10 @@ public class LdapProperties { private String password; /** - * Whether read-only operations should use an anonymous environment. + * Whether read-only operations should use an anonymous environment. Disabled by + * default unless a username is set. */ - private boolean anonymousReadOnly; + private Boolean anonymousReadOnly; /** * LDAP specification settings. @@ -97,11 +98,11 @@ public void setPassword(String password) { this.password = password; } - public boolean getAnonymousReadOnly() { + public Boolean getAnonymousReadOnly() { return this.anonymousReadOnly; } - public void setAnonymousReadOnly(boolean anonymousReadOnly) { + public void setAnonymousReadOnly(Boolean anonymousReadOnly) { this.anonymousReadOnly = anonymousReadOnly; } 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 d83f1a69f8b1..e25e9897bc12 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ public void contextSourceWithDefaultUrl() { LdapContextSource contextSource = context.getBean(LdapContextSource.class); String[] urls = getUrls(contextSource); assertThat(urls).containsExactly("ldap://localhost:389"); - assertThat(contextSource.isAnonymousReadOnly()).isFalse(); + assertThat(contextSource.isAnonymousReadOnly()).isTrue(); }); } @@ -73,6 +73,15 @@ public void contextSourceWithSeveralUrls() { }); } + @Test + public void contextSourceWithUserDoesNotEnableAnonymousReadOnly() { + this.contextRunner.withPropertyValues("spring.ldap.username:root").run((context) -> { + LdapContextSource contextSource = context.getBean(LdapContextSource.class); + assertThat(contextSource.getUserDn()).isEqualTo("root"); + assertThat(contextSource.isAnonymousReadOnly()).isFalse(); + }); + } + @Test public void contextSourceWithExtraCustomization() { this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:123", "spring.ldap.username:root", @@ -96,7 +105,7 @@ public void contextSourceWithNoCustomization() { LdapContextSource contextSource = context.getBean(LdapContextSource.class); assertThat(contextSource.getUserDn()).isEqualTo(""); assertThat(contextSource.getPassword()).isEqualTo(""); - assertThat(contextSource.isAnonymousReadOnly()).isFalse(); + assertThat(contextSource.isAnonymousReadOnly()).isTrue(); assertThat(contextSource.getBaseLdapPathAsString()).isEqualTo(""); }); } @@ -113,7 +122,7 @@ public void contextSourceWithUserProvidedPooledContextSource() { LdapContextSource contextSource = context.getBean(LdapContextSource.class); String[] urls = getUrls(contextSource); assertThat(urls).containsExactly("ldap://localhost:389"); - assertThat(contextSource.isAnonymousReadOnly()).isFalse(); + assertThat(contextSource.isAnonymousReadOnly()).isTrue(); }); } diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index c18230203570..f710863fa2a9 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -174,7 +174,7 @@ 0.25.2.RELEASE 5.1.10.RELEASE 2.2.13.RELEASE - 2.3.2.RELEASE + 2.3.3.RELEASE 1.2.0.RELEASE 2.0.4.RELEASE 1.2.5.RELEASE