Commit 0dfb3e88 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Explicity close NamingEnumerations for better protection against leaking resources.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5376 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3eb4af5a
......@@ -66,7 +66,7 @@ public class LdapAuthorizationProvider extends AbstractAuthorizationProvider imp
* Returns a String Collection of principals that are authorized to use
* the named user.
*
* @param username The username.
* @param username the username.
* @return A String Collection of principals that are authorized.
*/
public Collection<String> getAuthorized(String username) {
......
......@@ -96,6 +96,8 @@ public class LdapGroupProvider implements GroupProvider {
NamingEnumeration<SearchResult> answer = ctx.search("", filter, searchControls);
Collection<Group> groups = populateGroups(answer);
// Close the enumeration.
answer.close();
if (groups.size() > 1) {
// If multiple groups found, throw exception.
throw new GroupNotFoundException("Too many groups with name " + groupName + " were found.");
......@@ -173,6 +175,8 @@ public class LdapGroupProvider implements GroupProvider {
answer.next();
count++;
}
// Close the enumeration.
answer.close();
}
catch (Exception e) {
Log.error(e);
......@@ -221,6 +225,8 @@ public class LdapGroupProvider implements GroupProvider {
// Escape group name and add to results.
groupNames.add(JID.escapeNode(groupName));
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
Collections.sort(groupNames);
......@@ -288,6 +294,8 @@ public class LdapGroupProvider implements GroupProvider {
break;
}
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
Collections.sort(groupNames);
......@@ -430,6 +438,8 @@ public class LdapGroupProvider implements GroupProvider {
// Escape group name and add to results.
groupNames.add(JID.escapeNode(groupName));
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
Collections.sort(groupNames);
......@@ -507,6 +517,8 @@ public class LdapGroupProvider implements GroupProvider {
break;
}
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
Collections.sort(groupNames);
......@@ -613,6 +625,8 @@ public class LdapGroupProvider implements GroupProvider {
.getAttributes().get(
manager.getUsernameField()).get();
}
// Close the enumeration.
usrAnswer.close();
}
}
catch (Exception e) {
......@@ -655,6 +669,8 @@ public class LdapGroupProvider implements GroupProvider {
}
}
}
// Close the enumeration.
ne.close();
}
if (manager.isDebugEnabled()) {
Log.debug("Adding group \"" + name + "\" with " + members.size() +
......
......@@ -491,9 +491,11 @@ public class LdapManager {
throw new UserNotFoundException("LDAP username lookup for " + username +
" matched multiple entries.");
}
//All other methods assume that userDN is not a full LDAP string.
//However if a referal was followed this is not the case. The
//following code converts a referral back to a "partial" LDAP string.
// Close the enumeration.
answer.close();
// All other methods assume that userDN is not a full LDAP string.
// However if a referal was followed this is not the case. The
// following code converts a referral back to a "partial" LDAP string.
if (userDN.startsWith("ldap://")) {
userDN = userDN.replace("," + baseDN, "");
userDN = userDN.substring(userDN.lastIndexOf("/") + 1);
......
......@@ -152,6 +152,8 @@ public class LdapUserProvider implements UserProvider {
count++;
answer.nextElement();
}
// Close the enumeration.
answer.close();
}
catch (Exception e) {
Log.error(e);
......@@ -206,6 +208,8 @@ public class LdapUserProvider implements UserProvider {
// Escape username and add to results.
usernames.add(JID.escapeNode(username));
}
// Close the enumeration.
answer.close();
}
catch (Exception e) {
Log.error(e);
......@@ -293,6 +297,8 @@ public class LdapUserProvider implements UserProvider {
}
}
}
// Close the enumeration.
answer.close();
}
catch (Exception e) {
Log.error(e);
......@@ -384,6 +390,8 @@ public class LdapUserProvider implements UserProvider {
// Escape username and add to results.
usernames.add(JID.escapeNode(username));
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
Collections.sort(usernames);
......@@ -469,6 +477,8 @@ public class LdapUserProvider implements UserProvider {
break;
}
}
// Close the enumeration.
answer.close();
// If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty("ldap.clientSideSorting"))) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment