Commit 9b8d1093 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Do not log error when group does not exist. JM-850

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5660 b35dd754-fafc-0310-a699-88a17e54d16e
parent 18674a57
...@@ -78,6 +78,7 @@ public class LdapGroupProvider implements GroupProvider { ...@@ -78,6 +78,7 @@ public class LdapGroupProvider implements GroupProvider {
} }
public Group getGroup(String groupName) throws GroupNotFoundException { public Group getGroup(String groupName) throws GroupNotFoundException {
Collection<Group> groups;
LdapContext ctx = null; LdapContext ctx = null;
try { try {
ctx = manager.getContext(); ctx = manager.getContext();
...@@ -95,17 +96,10 @@ public class LdapGroupProvider implements GroupProvider { ...@@ -95,17 +96,10 @@ public class LdapGroupProvider implements GroupProvider {
String filter = MessageFormat.format(manager.getGroupSearchFilter(), groupName); String filter = MessageFormat.format(manager.getGroupSearchFilter(), groupName);
NamingEnumeration<SearchResult> answer = ctx.search("", filter, searchControls); NamingEnumeration<SearchResult> answer = ctx.search("", filter, searchControls);
Collection<Group> groups = populateGroups(answer); groups = populateGroups(answer);
// Close the enumeration. // Close the enumeration.
answer.close(); answer.close();
if (groups.size() > 1) { if (groups.size() == 1) {
// If multiple groups found, throw exception.
throw new GroupNotFoundException("Too many groups with name " + groupName + " were found.");
}
else if (groups.isEmpty()) {
throw new GroupNotFoundException("Group with name " + groupName + " not found.");
}
else {
return groups.iterator().next(); return groups.iterator().next();
} }
} }
...@@ -124,6 +118,12 @@ public class LdapGroupProvider implements GroupProvider { ...@@ -124,6 +118,12 @@ public class LdapGroupProvider implements GroupProvider {
// Ignore. // Ignore.
} }
} }
if (groups.size() > 1) {
// If multiple groups found, throw exception.
throw new GroupNotFoundException(
"Too many groups with name " + groupName + " were found.");
}
throw new GroupNotFoundException("Group with name " + groupName + " not found.");
} }
/** /**
......
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