Merge pull request #609 from perry2of5/main
Close searchResults so LDAP context can close.
This commit is contained in:
@@ -22,6 +22,7 @@ import org.springframework.ldap.pool.DirContextType;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
@@ -165,9 +166,10 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
public boolean validateDirContext(DirContextType contextType, DirContext dirContext) {
|
||||
Assert.notNull(contextType, "contextType may not be null");
|
||||
Assert.notNull(dirContext, "dirContext may not be null");
|
||||
|
||||
|
||||
NamingEnumeration<SearchResult> searchResults = null;
|
||||
try {
|
||||
final NamingEnumeration<SearchResult> searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
|
||||
if (searchResults.hasMore()) {
|
||||
this.logger.debug("DirContext '{}' passed validation.", dirContext);
|
||||
@@ -179,6 +181,14 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, e);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
if (searchResults != null) {
|
||||
try {
|
||||
searchResults.close();
|
||||
} catch (NamingException namingException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug("DirContext '{}' failed validation.", dirContext);
|
||||
return false;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.ldap.pool2.DirContextType;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
@@ -166,12 +167,13 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
Assert.notNull(contextType, "contextType may not be null");
|
||||
Assert.notNull(dirContext, "dirContext may not be null");
|
||||
|
||||
NamingEnumeration<SearchResult> searchResults = null;
|
||||
try {
|
||||
final NamingEnumeration<SearchResult> searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
searchResults = dirContext.search(this.base, this.filter, this.searchControls);
|
||||
|
||||
if (searchResults.hasMore()) {
|
||||
this.logger.debug("DirContext '{}' passed validation.", dirContext);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -179,6 +181,14 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, e);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
if (searchResults != null) {
|
||||
try {
|
||||
searchResults.close();
|
||||
} catch (NamingException namingException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug("DirContext '{}' failed validation.", dirContext);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user