Commit c66703d9 authored by Nik Okuntseff's avatar Nik Okuntseff

A fix for OF-1041

Made a search by distinguishedName Active Directory specific
as it is difficult to come up with a generic solution.
parent fb9c6a39
...@@ -226,8 +226,12 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -226,8 +226,12 @@ public class LdapGroupProvider extends AbstractGroupProvider {
Pattern pattern = Pattern pattern =
Pattern.compile("(?i)(^" + manager.getUsernameField() + "=)([^,]+)(.+)"); Pattern.compile("(?i)(^" + manager.getUsernameField() + "=)([^,]+)(.+)");
// We have to process Active Directory differently.
boolean isAD = manager.getUsernameField().equals("sAMAccountName");
String[] returningAttributes = isAD ? new String[] { "distinguishedName", manager.getUsernameField() } : new String[] { manager.getUsernameField() };
SearchControls searchControls = new SearchControls(); SearchControls searchControls = new SearchControls();
searchControls.setReturningAttributes(new String[] { "distinguishedName", manager.getUsernameField() }); searchControls.setReturningAttributes(returningAttributes);
// 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);
...@@ -289,6 +293,7 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -289,6 +293,7 @@ public class LdapGroupProvider extends AbstractGroupProvider {
while(usrAnswer.hasMoreElements()) { while(usrAnswer.hasMoreElements()) {
searchResult = (SearchResult) usrAnswer.nextElement(); searchResult = (SearchResult) usrAnswer.nextElement();
Attributes attrs = searchResult.getAttributes(); Attributes attrs = searchResult.getAttributes();
if (isAD) {
Attribute userdnAttr = attrs.get("distinguishedName"); Attribute userdnAttr = attrs.get("distinguishedName");
if (username.equals((String)userdnAttr.get())) { if (username.equals((String)userdnAttr.get())) {
// Exact match found, use it. // Exact match found, use it.
...@@ -296,6 +301,12 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -296,6 +301,12 @@ public class LdapGroupProvider extends AbstractGroupProvider {
break; break;
} }
} }
else {
// No iteration occurs here, which is probably a bug.
username = (String)attrs.get(manager.getUsernameField()).get();
break;
}
}
} }
// Close the enumeration. // Close the enumeration.
usrAnswer.close(); usrAnswer.close();
......
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