Commit fb9c6a39 authored by Nik Okuntseff's avatar Nik Okuntseff

Fixed group population for colliding full names.

When LDAP search returns a multiple result set for a user CN,
we now iterate through the entire set to find a matching user DN.
parent 80386d5f
...@@ -227,7 +227,7 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -227,7 +227,7 @@ public class LdapGroupProvider extends AbstractGroupProvider {
Pattern.compile("(?i)(^" + manager.getUsernameField() + "=)([^,]+)(.+)"); Pattern.compile("(?i)(^" + manager.getUsernameField() + "=)([^,]+)(.+)");
SearchControls searchControls = new SearchControls(); SearchControls searchControls = new SearchControls();
searchControls.setReturningAttributes(new String[] { manager.getUsernameField() }); searchControls.setReturningAttributes(new String[] { "distinguishedName", manager.getUsernameField() });
// See if recursive searching is enabled. Otherwise, only search one level. // See if recursive searching is enabled. Otherwise, only search one level.
if (manager.isSubTreeSearch()) { if (manager.isSubTreeSearch()) {
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
...@@ -283,9 +283,18 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -283,9 +283,18 @@ public class LdapGroupProvider extends AbstractGroupProvider {
NamingEnumeration usrAnswer = ctx.search("", NamingEnumeration usrAnswer = ctx.search("",
userFilter.toString(), searchControls); userFilter.toString(), searchControls);
if (usrAnswer != null && usrAnswer.hasMoreElements()) { if (usrAnswer != null && usrAnswer.hasMoreElements()) {
Attribute usernameAttr = ((SearchResult)usrAnswer.next()).getAttributes().get(manager.getUsernameField()); SearchResult searchResult = null;
if (usernameAttr != null) { // We may get multiple search results for the same user CN.
username = (String)usernameAttr.get(); // Iterate through the entire set to find a matching distinguished name.
while(usrAnswer.hasMoreElements()) {
searchResult = (SearchResult) usrAnswer.nextElement();
Attributes attrs = searchResult.getAttributes();
Attribute userdnAttr = attrs.get("distinguishedName");
if (username.equals((String)userdnAttr.get())) {
// Exact match found, use it.
username = (String)attrs.get(manager.getUsernameField()).get();
break;
}
} }
} }
// Close the enumeration. // Close the enumeration.
......
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