Commit 8c60bb63 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Missing LDAP close connection in one location, improved close logic in another location. JM-596

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3566 b35dd754-fafc-0310-a699-88a17e54d16e
parent 07830d33
......@@ -11,14 +11,14 @@
package org.jivesoftware.wildfire.ldap;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupProvider;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.jivesoftware.wildfire.group.GroupProvider;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import javax.naming.NamingEnumeration;
......@@ -82,7 +82,8 @@ public class LdapGroupProvider implements GroupProvider {
String filter = MessageFormat.format(manager.getGroupSearchFilter(), "*");
String searchFilter = "(&" + filter + "(" +
manager.getGroupNameField() + "=" + group + "))";
Collection<Group> groups = populateGroups(searchForGroups(searchFilter, standardAttributes));
Collection<Group> groups =
populateGroups(searchForGroups(searchFilter, standardAttributes));
if (groups.size() > 1) {
// If multiple groups found, throw exception.
throw new GroupNotFoundException("Too many groups with name " + group + " were found.");
......@@ -115,7 +116,8 @@ public class LdapGroupProvider implements GroupProvider {
* @param description the group description.
* @throws UnsupportedOperationException when called.
*/
public void setDescription(String name, String description) throws UnsupportedOperationException {
public void setDescription(String name, String description)
throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
......@@ -201,8 +203,7 @@ public class LdapGroupProvider implements GroupProvider {
* @throws UnsupportedOperationException when called.
*/
public void addMember(String groupName, JID user, boolean administrator)
throws UnsupportedOperationException
{
throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
......@@ -216,8 +217,7 @@ public class LdapGroupProvider implements GroupProvider {
* @throws UnsupportedOperationException when called.
*/
public void updateMember(String groupName, JID user, boolean administrator)
throws UnsupportedOperationException
{
throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
......@@ -254,8 +254,8 @@ public class LdapGroupProvider implements GroupProvider {
if (manager.isDebugEnabled()) {
Log.debug("Trying to find all groups in the system.");
}
DirContext ctx;
NamingEnumeration<SearchResult> answer = null;
DirContext ctx = null;
NamingEnumeration<SearchResult> answer;
try {
ctx = manager.getContext();
if (manager.isDebugEnabled()) {
......@@ -272,13 +272,23 @@ public class LdapGroupProvider implements GroupProvider {
if (manager.isDebugEnabled()) {
Log.debug("... search finished");
}
return answer;
}
catch (Exception e) {
if (manager.isDebugEnabled()) {
Log.debug("Error while searching for groups.", e);
}
return null;
}
finally {
if (ctx != null) {
try {
ctx.close();
}
catch (Exception ex) { /* do nothing */ }
}
}
return answer;
}
/**
......@@ -292,10 +302,10 @@ public class LdapGroupProvider implements GroupProvider {
if (manager.isDebugEnabled()) {
Log.debug("Starting to populate groups with users.");
}
DirContext ctx = null;
try {
TreeMap<String, Group> groups = new TreeMap<String, Group>();
DirContext ctx;
try {
ctx = manager.getContext();
}
......@@ -318,7 +328,8 @@ public class LdapGroupProvider implements GroupProvider {
String description;
try {
name = ((String) ((a.get(manager.getGroupNameField())).get()));
description = ((String) ((a.get(manager.getGroupDescriptionField())).get()));
description =
((String) ((a.get(manager.getGroupDescriptionField())).get()));
}
catch (Exception e) {
description = "";
......@@ -336,10 +347,12 @@ public class LdapGroupProvider implements GroupProvider {
// We have to do a new search to find the username field
String combinedFilter = "(&(" + ldapcn + ")" + userSearchFilter + ")";
String combinedFilter =
"(&(" + ldapcn + ")" + userSearchFilter + ")";
NamingEnumeration usrAnswer = ctx.search("", combinedFilter, ctrls);
if (usrAnswer.hasMoreElements()) {
username = (String) ((SearchResult) usrAnswer.next()).getAttributes().get(
username = (String) ((SearchResult) usrAnswer.next())
.getAttributes().get(
manager.getUsernameField()).get();
}
else {
......@@ -380,7 +393,8 @@ public class LdapGroupProvider implements GroupProvider {
}
}
if (manager.isDebugEnabled()) {
Log.debug("Adding group \"" + name + "\" with " + members.size() + " members.");
Log.debug("Adding group \"" + name + "\" with " + members.size() +
" members.");
}
Group g = new Group(name, description, members, new ArrayList<JID>());
groups.put(name, g);
......@@ -394,13 +408,18 @@ public class LdapGroupProvider implements GroupProvider {
if (manager.isDebugEnabled()) {
Log.debug("Finished populating group(s) with users.");
}
return groups.values();
}
finally {
try {
if (ctx != null) {
ctx.close();
}
}
catch (Exception e) {
// Ignore.
}
return groups.values();
}
}
}
\ No newline at end of file
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