Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close searchResults so LDAP context can close. #609

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Close searchResults so LDAP context can close.
Fixes #489
perry2of5 committed Jan 4, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 366c7c9d60522528737d2f9ebaca577d66bfff90
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
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 void setSearchControls(SearchControls searchControls) {
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 boolean validateDirContext(DirContextType contextType, DirContext dirCont
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;
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
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,19 +167,28 @@ public boolean validateDirContext(DirContextType contextType, DirContext dirCont
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;
}
}
catch (Exception e) {
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;