Commit d8980554 authored by Guus der Kinderen's avatar Guus der Kinderen

Merge pull request #511 from anuko/master

A fix for OF-1041
parents fa5b0ee0 c66703d9
...@@ -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,9 +293,16 @@ public class LdapGroupProvider extends AbstractGroupProvider { ...@@ -289,9 +293,16 @@ 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();
Attribute userdnAttr = attrs.get("distinguishedName"); if (isAD) {
if (username.equals((String)userdnAttr.get())) { Attribute userdnAttr = attrs.get("distinguishedName");
// Exact match found, use it. if (username.equals((String)userdnAttr.get())) {
// Exact match found, use it.
username = (String)attrs.get(manager.getUsernameField()).get();
break;
}
}
else {
// No iteration occurs here, which is probably a bug.
username = (String)attrs.get(manager.getUsernameField()).get(); username = (String)attrs.get(manager.getUsernameField()).get();
break; break;
} }
......
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