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
8c341df7
Commit
8c341df7
authored
Jul 01, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add properties to control exceptions ignored by LdapTemplate"
See gh-21289
parent
68533206
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
51 deletions
+68
-51
LdapAutoConfiguration.java
...mework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
+6
-5
LdapProperties.java
...ringframework/boot/autoconfigure/ldap/LdapProperties.java
+53
-37
LdapAutoConfigurationTests.java
...k/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java
+4
-3
LdapPropertiesTests.java
...ramework/boot/autoconfigure/ldap/LdapPropertiesTests.java
+5
-6
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
View file @
8c341df7
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.ObjectProvider;
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.Template
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -65,13 +66,13 @@ public class LdapAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
LdapOperations
.
class
)
public
LdapTemplate
ldapTemplate
(
LdapProperties
properties
,
ContextSource
contextSource
)
{
Template
template
=
properties
.
getTemplate
();
PropertyMapper
propertyMapper
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
LdapTemplate
ldapTemplate
=
new
LdapTemplate
(
contextSource
);
propertyMapper
.
from
(
properties
.
isIgnorePartialResultException
())
propertyMapper
.
from
(
template
.
isIgnorePartialResultException
())
.
to
(
ldapTemplate:
:
setIgnorePartialResultException
);
propertyMapper
.
from
(
properties
.
isIgnoreNameNotFoundException
())
.
to
(
ldapTemplate:
:
setIgnoreNameNotFoundException
);
propertyMapper
.
from
(
properties
.
isIgnoreSizeLimitExceededException
())
propertyMapper
.
from
(
template
.
isIgnoreNameNotFoundException
()).
to
(
ldapTemplate:
:
setIgnoreNameNotFoundException
);
propertyMapper
.
from
(
template
.
isIgnoreSizeLimitExceededException
())
.
to
(
ldapTemplate:
:
setIgnoreSizeLimitExceededException
);
return
ldapTemplate
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java
View file @
8c341df7
...
...
@@ -21,6 +21,7 @@ import java.util.Map;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.core.env.Environment
;
import
org.springframework.ldap.core.LdapTemplate
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -66,21 +67,7 @@ public class LdapProperties {
*/
private
final
Map
<
String
,
String
>
baseEnvironment
=
new
HashMap
<>();
/**
* Whether PartialResultException should be ignored in searches via the LdapTemplate.
*/
private
boolean
ignorePartialResultException
=
false
;
/**
* Whether NameNotFoundException should be ignored in searches via the LdapTemplate.
*/
private
boolean
ignoreNameNotFoundException
=
false
;
/**
* Whether SizeLimitExceededException should be ignored in searches via the
* LdapTemplate.
*/
private
boolean
ignoreSizeLimitExceededException
=
true
;
private
Template
template
=
new
Template
();
public
String
[]
getUrls
()
{
return
this
.
urls
;
...
...
@@ -126,28 +113,8 @@ public class LdapProperties {
return
this
.
baseEnvironment
;
}
public
boolean
isIgnorePartialResultException
()
{
return
this
.
ignorePartialResultException
;
}
public
void
setIgnorePartialResultException
(
boolean
ignorePartialResultException
)
{
this
.
ignorePartialResultException
=
ignorePartialResultException
;
}
public
boolean
isIgnoreNameNotFoundException
()
{
return
this
.
ignoreNameNotFoundException
;
}
public
void
setIgnoreNameNotFoundException
(
boolean
ignoreNameNotFoundException
)
{
this
.
ignoreNameNotFoundException
=
ignoreNameNotFoundException
;
}
public
boolean
isIgnoreSizeLimitExceededException
()
{
return
this
.
ignoreSizeLimitExceededException
;
}
public
void
setIgnoreSizeLimitExceededException
(
Boolean
ignoreSizeLimitExceededException
)
{
this
.
ignoreSizeLimitExceededException
=
ignoreSizeLimitExceededException
;
public
Template
getTemplate
()
{
return
this
.
template
;
}
public
String
[]
determineUrls
(
Environment
environment
)
{
...
...
@@ -166,4 +133,53 @@ public class LdapProperties {
return
DEFAULT_PORT
;
}
/**
* {@link LdapTemplate settings}.
*/
public
static
class
Template
{
/**
* Whether PartialResultException should be ignored in searches via the
* LdapTemplate.
*/
private
boolean
ignorePartialResultException
=
false
;
/**
* Whether NameNotFoundException should be ignored in searches via the
* LdapTemplate.
*/
private
boolean
ignoreNameNotFoundException
=
false
;
/**
* Whether SizeLimitExceededException should be ignored in searches via the
* LdapTemplate.
*/
private
boolean
ignoreSizeLimitExceededException
=
true
;
public
boolean
isIgnorePartialResultException
()
{
return
this
.
ignorePartialResultException
;
}
public
void
setIgnorePartialResultException
(
boolean
ignorePartialResultException
)
{
this
.
ignorePartialResultException
=
ignorePartialResultException
;
}
public
boolean
isIgnoreNameNotFoundException
()
{
return
this
.
ignoreNameNotFoundException
;
}
public
void
setIgnoreNameNotFoundException
(
boolean
ignoreNameNotFoundException
)
{
this
.
ignoreNameNotFoundException
=
ignoreNameNotFoundException
;
}
public
boolean
isIgnoreSizeLimitExceededException
()
{
return
this
.
ignoreSizeLimitExceededException
;
}
public
void
setIgnoreSizeLimitExceededException
(
Boolean
ignoreSizeLimitExceededException
)
{
this
.
ignoreSizeLimitExceededException
=
ignoreSizeLimitExceededException
;
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java
View file @
8c341df7
...
...
@@ -122,10 +122,11 @@ class LdapAutoConfigurationTests {
}
@Test
void
template
WithCustomConfigurationExists
()
{
void
template
ConfigurationCanBeCustomized
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:389"
,
"spring.ldap.ignorePartialResultException=true"
,
"spring.ldap.ignoreNameNotFoundException=true"
,
"spring.ldap.ignoreSizeLimitExceededException=false"
).
run
((
context
)
->
{
"spring.ldap.template.ignorePartialResultException=true"
,
"spring.ldap.template.ignoreNameNotFoundException=true"
,
"spring.ldap.template.ignoreSizeLimitExceededException=false"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LdapTemplate
.
class
);
LdapTemplate
ldapTemplate
=
context
.
getBean
(
LdapTemplate
.
class
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignorePartialResultException"
,
true
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapPropertiesTests.java
View file @
8c341df7
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.ldap;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.ldap.LdapProperties.Template
;
import
org.springframework.ldap.core.LdapTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -29,18 +30,16 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class
LdapPropertiesTests
{
private
final
LdapProperties
properties
=
new
LdapProperties
();
@Test
void
ldapTemplatePropertiesUseConsistentLdapTemplateDefaultValues
()
{
Template
templateProperties
=
new
LdapProperties
().
getTemplate
();
LdapTemplate
ldapTemplate
=
new
LdapTemplate
();
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignorePartialResultException"
,
t
his
.
p
roperties
.
isIgnorePartialResultException
());
t
emplateP
roperties
.
isIgnorePartialResultException
());
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreNameNotFoundException"
,
t
his
.
p
roperties
.
isIgnoreNameNotFoundException
());
t
emplateP
roperties
.
isIgnoreNameNotFoundException
());
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreSizeLimitExceededException"
,
t
his
.
p
roperties
.
isIgnoreSizeLimitExceededException
());
t
emplateP
roperties
.
isIgnoreSizeLimitExceededException
());
}
}
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