mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
SEC-1520: Close NamingEnumeration in LDAP compare implementation.
This commit is contained in:
parent
36e0fb6d91
commit
118af45b8e
@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
|
import javax.naming.NamingEnumeration;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -60,6 +61,16 @@ public final class LdapUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void closeEnumeration(NamingEnumeration ne) {
|
||||||
|
try {
|
||||||
|
if (ne != null) {
|
||||||
|
ne.close();
|
||||||
|
}
|
||||||
|
} catch (NamingException e) {
|
||||||
|
logger.error("Failed to close enumeration.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the part of a DN relative to a supplied base context.
|
* Obtains the part of a DN relative to a supplied base context.
|
||||||
* <p>If the DN is "cn=bob,ou=people,dc=springframework,dc=org" and the base context name is
|
* <p>If the DN is "cn=bob,ou=people,dc=springframework,dc=org" and the base context name is
|
||||||
|
@ -92,7 +92,10 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
|||||||
|
|
||||||
NamingEnumeration<SearchResult> results = ctx.search(dn, comparisonFilter, new Object[] {value}, ctls);
|
NamingEnumeration<SearchResult> results = ctx.search(dn, comparisonFilter, new Object[] {value}, ctls);
|
||||||
|
|
||||||
return Boolean.valueOf(results.hasMore());
|
Boolean match = Boolean.valueOf(results.hasMore());
|
||||||
|
LdapUtils.closeEnumeration(results);
|
||||||
|
|
||||||
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +218,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
|||||||
results.add(new DirContextAdapter(searchResult.getAttributes(), dn, ctxBaseDn));
|
results.add(new DirContextAdapter(searchResult.getAttributes(), dn, ctxBaseDn));
|
||||||
}
|
}
|
||||||
} catch (PartialResultException e) {
|
} catch (PartialResultException e) {
|
||||||
|
LdapUtils.closeEnumeration(resultsEnum);
|
||||||
logger.info("Ignoring PartialResultException");
|
logger.info("Ignoring PartialResultException");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user