]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 229049: Make LDAP authentication work when there are multiple mail= attributes...
authormkanat%bugzilla.org <>
Fri, 14 Dec 2007 23:40:57 +0000 (23:40 +0000)
committermkanat%bugzilla.org <>
Fri, 14 Dec 2007 23:40:57 +0000 (23:40 +0000)
Patch By Emmanuel Seyman <eseyman@linagora.com> r=mkanat, a=mkanat

Bugzilla/Auth/Verify/LDAP.pm

index 0176abdcb31e1873c8d94052bbe2f5e904db23f4..b8dff397f600c11a77946376f3c151c8b38f3bbf 100644 (file)
@@ -37,6 +37,7 @@ use fields qw(
 
 use Bugzilla::Constants;
 use Bugzilla::Error;
+use Bugzilla::User;
 use Bugzilla::Util;
 
 use Net::LDAP;
@@ -90,7 +91,22 @@ sub check_credentials {
                      details => {attr => $mail_attr} };
         }
 
-        $params->{bz_username} = $user_entry->get_value($mail_attr);
+        my @emails = $user_entry->get_value($mail_attr);
+
+        # Default to the first email address returned.
+        $params->{bz_username} = $emails[0];
+
+        if (@emails > 1) {
+            # Cycle through the adresses and check if they're Bugzilla logins.
+            # Use the first one that returns a valid id. 
+            foreach my $email (@emails) {
+                if ( login_to_id($email) ) {
+                    $params->{bz_username} = $email;
+                    last;
+                }
+            }
+        }
+
     } else {
         $params->{bz_username} = $username;
     }