I got around this using the attached patch. Instead of directly loading
the user, I have a GetEmail method that fetches the email of the user
from LDAP and uses this to load the current user.
diff -Nbaur lib.orig/RT/Authen/ExternalAuth/LDAP.pm lib/RT/Authen/ExternalAuth/LDAP.pm
--- lib.orig/RT/Authen/ExternalAuth/LDAP.pm 2011-03-30 14:18:36.000000000 +0530
+++ lib/RT/Authen/ExternalAuth/LDAP.pm 2011-03-30 14:17:31.000000000 +0530
@@ -476,4 +476,75 @@
# }}}
+sub GetEmail {
+
+ my ($service, $username) = @_;
+
+ my $config = $RT::ExternalSettings->{$service};
+ $RT::Logger->debug( "Getting email from service:",$service);
+
+ my $base = $config->{'base'};
+ my $filter = $config->{'filter'};
+ my $group = $config->{'group'};
+ my $group_attr = $config->{'group_attr'};
+ my $attr_map = $config->{'attr_map'};
+ my @attrs = qw(dn mail);
+
+ # Empty parentheses as filters cause Net::LDAP to barf.
+ # We take care of this by using Net::LDAP::Filter, but
+ # there's no harm in fixing this right now.
+ if ($filter eq "()") { undef($filter) };
+
+ # Now let's get connected
+ my $ldap = _GetBoundLdapObj($config);
+ return 0 unless ($ldap);
+
+ $filter = Net::LDAP::Filter->new( '(&(' .
+ $attr_map->{'ExternalAuthId'} .
+ '=' .
+ $username .
+ ')' .
+ $filter .
+ ')'
+ );
+
+ $RT::Logger->debug( "LDAP Search get email === ",
+ "Base:",
+ $base,
+ "== Filter:",
+ $filter->as_string,
+ "== Attrs:",
+ join(',',@attrs));
+
+ my $ldap_msg = $ldap->search( base => $base,
+ filter => $filter,
+ attrs => \@attrs);
+
+ unless ($ldap_msg->code == LDAP_SUCCESS || $ldap_msg->code == LDAP_PARTIAL_RESULTS) {
+ $RT::Logger->debug( "search for",
+ $filter->as_string,
+ "failed:",
+ ldap_error_name($ldap_msg->code),
+ $ldap_msg->code);
+ # Didn't even get a partial result - jump straight to the next external auth service
+ return 0;
+ }
+
+ unless ($ldap_msg->count == 1) {
+ $RT::Logger->info( $service,
+ "AUTH FAILED:",
+ $username,
+ "User not found or more than one user found");
+ # We got no user, or too many users.. jump straight to the next external auth service
+ return 0;
+ }
+
+ my $ldap_mail = $ldap_msg->first_entry->get_value($attr_map->{EmailAddress});
+ $RT::Logger->debug( "Found LDAP Mail:",
+ $ldap_mail);
+
+ return $ldap_mail;
+
+}
+
1;
diff -Nbaur lib.orig/RT/Authen/ExternalAuth.pm lib/RT/Authen/ExternalAuth.pm
--- lib.orig/RT/Authen/ExternalAuth.pm 2011-03-30 14:03:28.000000000 +0530
+++ lib/RT/Authen/ExternalAuth.pm 2011-03-30 14:14:27.000000000 +0530
@@ -115,7 +115,13 @@
# Does user already exist internally to RT?
$session->{'CurrentUser'} = RT::CurrentUser->new();
+ my $mail;
+ if ($config->{'type'} eq 'ldap') {
+ $mail = RT::Authen::ExternalAuth::LDAP::GetEmail($service,$username);
+ $session->{'CurrentUser'}->LoadByEmail($mail);
+ } else {
$session->{'CurrentUser'}->Load($username);
+ }
# Unless we have loaded a valid user with a UserID create one.
unless ($session->{'CurrentUser'}->Id) {