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
68533206
Commit
68533206
authored
May 01, 2020
by
Filip Hrisafov
Committed by
Andy Wilkinson
Jul 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add properties to control exceptions ignored by LdapTemplate
See gh-21289
parent
1710118f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
4 deletions
+116
-4
LdapAutoConfiguration.java
...mework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
+10
-2
LdapProperties.java
...ringframework/boot/autoconfigure/ldap/LdapProperties.java
+40
-0
LdapAutoConfigurationTests.java
...k/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java
+20
-2
LdapPropertiesTests.java
...ramework/boot/autoconfigure/ldap/LdapPropertiesTests.java
+46
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java
View file @
68533206
...
...
@@ -64,8 +64,16 @@ public class LdapAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
LdapOperations
.
class
)
public
LdapTemplate
ldapTemplate
(
ContextSource
contextSource
)
{
return
new
LdapTemplate
(
contextSource
);
public
LdapTemplate
ldapTemplate
(
LdapProperties
properties
,
ContextSource
contextSource
)
{
PropertyMapper
propertyMapper
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
LdapTemplate
ldapTemplate
=
new
LdapTemplate
(
contextSource
);
propertyMapper
.
from
(
properties
.
isIgnorePartialResultException
())
.
to
(
ldapTemplate:
:
setIgnorePartialResultException
);
propertyMapper
.
from
(
properties
.
isIgnoreNameNotFoundException
())
.
to
(
ldapTemplate:
:
setIgnoreNameNotFoundException
);
propertyMapper
.
from
(
properties
.
isIgnoreSizeLimitExceededException
())
.
to
(
ldapTemplate:
:
setIgnoreSizeLimitExceededException
);
return
ldapTemplate
;
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java
View file @
68533206
...
...
@@ -66,6 +66,22 @@ 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
;
public
String
[]
getUrls
()
{
return
this
.
urls
;
}
...
...
@@ -110,6 +126,30 @@ 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
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 @
68533206
...
...
@@ -112,8 +112,26 @@ class LdapAutoConfigurationTests {
@Test
void
templateExists
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:389"
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
LdapTemplate
.
class
));
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:389"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LdapTemplate
.
class
);
LdapTemplate
ldapTemplate
=
context
.
getBean
(
LdapTemplate
.
class
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignorePartialResultException"
,
false
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreNameNotFoundException"
,
false
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreSizeLimitExceededException"
,
true
);
});
}
@Test
void
templateWithCustomConfigurationExists
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.ldap.urls:ldap://localhost:389"
,
"spring.ldap.ignorePartialResultException=true"
,
"spring.ldap.ignoreNameNotFoundException=true"
,
"spring.ldap.ignoreSizeLimitExceededException=false"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LdapTemplate
.
class
);
LdapTemplate
ldapTemplate
=
context
.
getBean
(
LdapTemplate
.
class
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignorePartialResultException"
,
true
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreNameNotFoundException"
,
true
);
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreSizeLimitExceededException"
,
false
);
});
}
@Test
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapPropertiesTests.java
0 → 100644
View file @
68533206
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
ldap
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.ldap.core.LdapTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LdapProperties}
*
* @author Filip Hrisafov
*/
class
LdapPropertiesTests
{
private
final
LdapProperties
properties
=
new
LdapProperties
();
@Test
void
ldapTemplatePropertiesUseConsistentLdapTemplateDefaultValues
()
{
LdapTemplate
ldapTemplate
=
new
LdapTemplate
();
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignorePartialResultException"
,
this
.
properties
.
isIgnorePartialResultException
());
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreNameNotFoundException"
,
this
.
properties
.
isIgnoreNameNotFoundException
());
assertThat
(
ldapTemplate
).
hasFieldOrPropertyWithValue
(
"ignoreSizeLimitExceededException"
,
this
.
properties
.
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