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