[Bps-public-commit] rt-authen-externalauth branch, multiple-emails, updated. 0.10_01-62-geb7667e

Jim Brandt jbrandt at bestpractical.com
Mon Jun 25 15:50:26 EDT 2012


The branch, multiple-emails has been updated
       via  eb7667eeca7b0af39701c7f4cef45ec5abe7901c (commit)
      from  3d57a3dac5e24c70e544af2237eb9a12d6fc4b6f (commit)

Summary of changes:
 lib/RT/Authen/ExternalAuth.pm      |    4 +++-
 lib/RT/Authen/ExternalAuth/LDAP.pm |   17 +++++++++++++++--
 xt/ldap/multiple-emails.t          |    6 ++++--
 3 files changed, 22 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit eb7667eeca7b0af39701c7f4cef45ec5abe7901c
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Jun 25 15:42:43 2012 -0400

    Add proxyAddresses handling for 'smtp:' prefix
    
    Added special prefixing for LDAP searches against AD where
    additional emails in the proxyAddresses element have
    'smtp:' prepended to them by AD.
    
    Also two bugfixes:
    
    * one to skip LDAP entries spec'd in the config that have have no
    value for the current user
    
    * returning the search_by term as the first item from
    FindRecordsWithAlternatives

diff --git a/lib/RT/Authen/ExternalAuth.pm b/lib/RT/Authen/ExternalAuth.pm
index 319afb3..20f6388 100644
--- a/lib/RT/Authen/ExternalAuth.pm
+++ b/lib/RT/Authen/ExternalAuth.pm
@@ -179,6 +179,7 @@ This software is released under version 2 of the GNU
 General Public License. The license is distributed with
 this package in the LICENSE file found in the directory 
 root.
+
 =cut    
 
 use RT::Authen::ExternalAuth::LDAP;
@@ -773,6 +774,7 @@ sub CanonicalizeUserInfo {
         my (%other) = FindRecordsByOtherFields( $self, %args );
         while ( my ($search_by, $values) = each %other ) {
             foreach my $value ( @$values ) {
+		next if not defined $value; # Entry in config, but no value in LDAP
                 my $rv = $orig->( $self, $search_by => $value );
                 return $rv if $self->id;
             }
@@ -847,7 +849,7 @@ sub FindRecordsWithAlternatives {
         my @alternatives = grep defined && length && $_ ne $args{ $search_by }, values %params;
 
         # Don't Check any more services
-        return @alternatives;
+        return ($search_by, @alternatives);
     }
     return;
 }
diff --git a/lib/RT/Authen/ExternalAuth/LDAP.pm b/lib/RT/Authen/ExternalAuth/LDAP.pm
index 0bb5917..c2811e3 100644
--- a/lib/RT/Authen/ExternalAuth/LDAP.pm
+++ b/lib/RT/Authen/ExternalAuth/LDAP.pm
@@ -135,9 +135,22 @@ sub CanonicalizeUserInfo {
     # Load the config
     my $config = $RT::ExternalSettings->{$service};
 
+    # Build the LDAP filters
+    my @filter_list;
+    foreach my $filter_key ( ref $key ? @$key : ($key) ){
+        push @filter_list, "($filter_key=" . escape_filter_value( $value ) . ")";
+
+        # Prepend special prefixes for AD
+        if( $filter_key eq 'proxyAddresses' ){
+            foreach my $prefix ( 'smtp:' ){
+                push @filter_list, "($filter_key=" . escape_filter_value( $prefix . $value ) . ")";
+           }
+        }
+    }
+
     my $filter = JoinFilters(
         '&',
-        JoinFilters('|', map "($_=". escape_filter_value( $value ) .")", ref $key? @$key: ($key) ),
+        JoinFilters('|', @filter_list ),
         $config->{'filter'},
     ) or return (0);
 
@@ -240,7 +253,7 @@ sub UserExists {
         return 0;
     }
     undef $user_found;
-    
+
     # If we havent returned now, there must be a valid user.
     return 1;
 }
diff --git a/xt/ldap/multiple-emails.t b/xt/ldap/multiple-emails.t
index 290923b..4948e4f 100644
--- a/xt/ldap/multiple-emails.t
+++ b/xt/ldap/multiple-emails.t
@@ -13,7 +13,7 @@ ok($queue->id, "loaded the General queue");
 RT->Config->Set( AutoCreate                  => { Privileged => 1 } );
 
 RT->Config->Get('ExternalSettings')->{'My_LDAP'}{'attr_map'}{'EmailAddress'}
-    = ['mail', 'alias'];
+    = ['mail', 'alias', 'proxyAddresses', 'foo'];
 
 RT::Test->set_rights(
     { Principal => 'Everyone', Right => [qw(SeeQueue ShowTicket CreateTicket)] },
@@ -44,6 +44,7 @@ diag "login then send emails from different addresses";
         is( $user->EmailAddress, "$username\@invalid.tld" );
     }
 
+diag "Send first email from initial address.";
     {
         my $mail = << "MAIL";
 Subject: Test
@@ -159,5 +160,6 @@ MAIL
 
 $client->unbind();
 
-sub new_user { return $class->add_ldap_user_simple( alias => '%name at alternative.tld' ) }
+sub new_user { return $class->add_ldap_user_simple( alias => '%name at alternative.tld',
+						    proxyAddresses => 'smtp:%name at alternative.tld') }
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list