Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
960989cf
Commit
960989cf
authored
Jan 24, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add support for anonymousReadOnly in LdapProperties"
Closes gh-11744
parent
af0bdc89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
31 deletions
+29
-31
LdapAutoConfiguration.java
...mework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
+1
-1
LdapProperties.java
...ringframework/boot/autoconfigure/ldap/LdapProperties.java
+8
-12
LdapAutoConfigurationTests.java
...k/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java
+16
-15
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+4
-3
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
View file @
960989cf
...
...
@@ -54,11 +54,11 @@ public class LdapAutoConfiguration {
LdapContextSource
source
=
new
LdapContextSource
();
source
.
setUserDn
(
this
.
properties
.
getUsername
());
source
.
setPassword
(
this
.
properties
.
getPassword
());
source
.
setAnonymousReadOnly
(
this
.
properties
.
getAnonymousReadOnly
());
source
.
setBase
(
this
.
properties
.
getBase
());
source
.
setUrls
(
this
.
properties
.
determineUrls
(
this
.
environment
));
source
.
setBaseEnvironmentProperties
(
Collections
.
unmodifiableMap
(
this
.
properties
.
getBaseEnvironment
()));
source
.
setAnonymousReadOnly
(
this
.
properties
.
getAnonymousReadOnly
());
return
source
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java
View file @
960989cf
...
...
@@ -56,14 +56,14 @@ public class LdapProperties {
private
String
password
;
/**
*
LDAP specification settings
.
*
Whether read-only operations should use an anonymous environment
.
*/
private
Map
<
String
,
String
>
baseEnvironment
=
new
HashMap
<>()
;
private
boolean
anonymousReadOnly
;
/**
*
Whether read-only operations should use an anonymous environment
.
*
LDAP specification settings
.
*/
private
boolean
anonymousReadOnly
;
private
final
Map
<
String
,
String
>
baseEnvironment
=
new
HashMap
<>()
;
public
String
[]
getUrls
()
{
return
this
.
urls
;
...
...
@@ -97,14 +97,6 @@ public class LdapProperties {
this
.
password
=
password
;
}
public
Map
<
String
,
String
>
getBaseEnvironment
()
{
return
this
.
baseEnvironment
;
}
public
void
setBaseEnvironment
(
Map
<
String
,
String
>
baseEnvironment
)
{
this
.
baseEnvironment
=
baseEnvironment
;
}
public
boolean
getAnonymousReadOnly
()
{
return
this
.
anonymousReadOnly
;
}
...
...
@@ -113,6 +105,10 @@ public class LdapProperties {
this
.
anonymousReadOnly
=
anonymousReadOnly
;
}
public
Map
<
String
,
String
>
getBaseEnvironment
()
{
return
this
.
baseEnvironment
;
}
public
String
[]
determineUrls
(
Environment
environment
)
{
if
(
ObjectUtils
.
isEmpty
(
this
.
urls
))
{
return
new
String
[]
{
"ldap://localhost:"
+
determinePort
(
environment
)
};
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java
View file @
960989cf
...
...
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link LdapAutoConfiguration}.
*
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
LdapAutoConfigurationTests
{
...
...
@@ -37,17 +38,18 @@ public class LdapAutoConfigurationTests {
.
withConfiguration
(
AutoConfigurations
.
of
(
LdapAutoConfiguration
.
class
));
@Test
public
void
test
DefaultUrl
()
{
public
void
contextSourceWith
DefaultUrl
()
{
this
.
contextRunner
.
run
(
context
->
{
ContextSource
contextSource
=
context
.
getBean
(
ContextSource
.
class
);
LdapContextSource
contextSource
=
context
.
getBean
(
Ldap
ContextSource
.
class
);
String
[]
urls
=
(
String
[])
ReflectionTestUtils
.
getField
(
contextSource
,
"urls"
);
assertThat
(
urls
).
containsExactly
(
"ldap://localhost:389"
);
assertThat
(
contextSource
.
isAnonymousReadOnly
()).
isFalse
();
});
}
@Test
public
void
testContextSourceSetOn
eUrl
()
{
public
void
contextSourceWithSingl
eUrl
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:123"
)
.
run
(
context
->
{
ContextSource
contextSource
=
context
.
getBean
(
ContextSource
.
class
);
...
...
@@ -58,7 +60,7 @@ public class LdapAutoConfigurationTests {
}
@Test
public
void
testContextSourceSetTwo
Urls
()
{
public
void
contextSourceWithSeveral
Urls
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:123,ldap://mycompany:123"
)
...
...
@@ -74,28 +76,27 @@ public class LdapAutoConfigurationTests {
}
@Test
public
void
testContextSourceWithMoreProperties
()
{
public
void
contextSourceWithExtraCustomization
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:123"
,
"spring.ldap.username:root"
,
"spring.ldap.password:root"
,
"spring.ldap.password:secret"
,
"spring.ldap.anonymous-read-only:true"
,
"spring.ldap.base:cn=SpringDevelopers"
,
"spring.ldap.baseEnvironment.java.naming.security.authentication:DIGEST-MD5"
)
.
run
(
context
->
{
LdapContextSource
contextSource
=
context
.
getBean
(
LdapContextSource
.
class
);
assertThat
(
contextSource
.
getUserDn
()).
isEqualTo
(
"root"
);
assertThat
(
contextSource
.
getPassword
()).
isEqualTo
(
"secret"
);
assertThat
(
contextSource
.
isAnonymousReadOnly
()).
isTrue
();
assertThat
(
contextSource
.
getBaseLdapPathAsString
()).
isEqualTo
(
"cn=SpringDevelopers"
);
LdapProperties
ldapProperties
=
context
.
getBean
(
LdapProperties
.
class
);
assertThat
(
ldapProperties
.
getBaseEnvironment
()).
containsEntry
(
"java.naming.security.authentication"
,
"DIGEST-MD5"
);
});
}
@Test
public
void
testContextSourceWithDefaultAnonymousReadOnly
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:123"
)
.
run
(
context
->
{
LdapContextSource
contextSource
=
context
.
getBean
(
LdapContextSource
.
class
);
assertThat
(
contextSource
.
isAnonymousReadOnly
()).
isFalse
();
});
}
}
spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
960989cf
...
...
@@ -362,11 +362,12 @@ content into your application. Rather, pick only the properties that you need.
spring.jersey.type=servlet # Jersey integration type.
# SPRING LDAP ({sc-spring-boot-autoconfigure}/ldap/LdapProperties.{sc-ext}[LdapProperties])
spring.ldap.
urls= # LDAP URLs of the server
.
spring.ldap.
anonymous-read-only=false # Whether read-only operations should use an anonymous environment
.
spring.ldap.base= # Base suffix from which all operations should originate.
spring.ldap.username= # Login username of the server.
spring.ldap.password= # Login password of the server.
spring.ldap.base-environment.*= # LDAP specification settings.
spring.ldap.password= # Login password of the server.
spring.ldap.urls= # LDAP URLs of the server.
spring.ldap.username= # Login username of the server.
# EMBEDDED LDAP ({sc-spring-boot-autoconfigure}/ldap/embedded/EmbeddedLdapProperties.{sc-ext}[EmbeddedLdapProperties])
spring.ldap.embedded.base-dn= # The base DN
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment