[Bps-public-commit] RT-Extension-LDAPImport branch, master, updated. 0.32_03-3-g672722b

Jim Brandt jbrandt at bestpractical.com
Mon Apr 9 13:23:30 EDT 2012


The branch, master has been updated
       via  672722b901b3380c876d2f0e52c2c3d412da239f (commit)
       via  add5d84bebe5f7ac09a3222847b3821ae1296513 (commit)
       via  3d28a2035e84b71bf53985033687f6daef7c6f05 (commit)
      from  8c4e83f22cb3ee511d886ae770085d533e8ac203 (commit)

Summary of changes:
 lib/RT/Extension/LDAPImport.pm |   25 ++++++++++++++++++++++++-
 t/group-import.t               |   35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 3d28a2035e84b71bf53985033687f6daef7c6f05
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Apr 9 11:45:11 2012 -0400

    Add regex match option for LDAP group members.
    
    Added a feature to allow you to use a regex to match an LDAP member
    field. But upon further review, I don't think it would ever be
    needed unless someone's LDAP was really mis-configured. So this
    commit is for posterity only.
    (cherry picked from commit f5b2b5c7d0a02577f36782bebfdc5ff2082f9951)

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index 411f138..b4a7b70 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -18,11 +18,6 @@ use Data::Dumper;
 
 RT::Extension::LDAPImport - Import Users from an LDAP store
 
-
-=head1 SYNOPSIS
-
-    use RT::Extension::LDAPImport;
-
 =head1 METHODS
 
 =head2 connect_ldap
@@ -865,6 +860,13 @@ sub _get_group_members_from_ldap {
     my $mapping = $RT::LDAPGroupMapping;
 
     my $members = $ldap_entry->get_value($mapping->{Member_Attr}, asref => 1);
+
+    if ( exists $mapping->{Member_Attr_Regex}
+	 and defined $mapping->{Member_Attr_Regex} ) {
+      @{$members} = map{ /$mapping->{Member_Attr_Regex}/ } @{$members};
+    }
+
+    return $members;
 }
 
 
diff --git a/t/group-import.t b/t/group-import.t
index 6d28e80..e15754b 100644
--- a/t/group-import.t
+++ b/t/group-import.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use lib 't/lib';
-use RT::Extension::LDAPImport::Test tests => 66;
+use RT::Extension::LDAPImport::Test tests => 74;
 eval { require Net::LDAP::Server::Test; 1; } or do {
     plan skip_all => 'Unable to test without Net::Server::LDAP::Test';
 };
@@ -99,6 +99,39 @@ RT->Config->Set('LDAPGroupMapping',
                    });
 import_group_members_ok( memberUid => 'uid' );
 
+# Test a regex on Member_Attr
+# This is for a case where the member attribute
+# isn't the simple member name.
+
+ at ldap_group_entries = ();
+{
+    my $groupname = "Test Group 5";
+    my $dn = "cn=$groupname,ou=groups,dc=bestpractical,dc=com";
+    my $entry = {
+        cn   =>  $groupname,
+        members => [ map { $_->{dn} } @ldap_user_entries[3,7,11] ],
+       # Make an entries that looks like cn=testuser12,ou=foo,dc=bestpractical
+        memberUid => [ map { 'cn=' . $_->{uid} . ',ou=foo,dc=bestpractical' }
+		       @ldap_user_entries[3,7,11] ],
+        objectClass => 'Test5',
+    };
+    $ldap->add( $dn, attr => [%$entry] );
+
+    # Fix entry for expected value after regex.
+    $entry->{memberUid} = [ map { $_->{uid} } @ldap_user_entries[3,7,11] ];
+    push @ldap_group_entries, $entry;
+}
+
+RT->Config->Set('LDAPGroupFilter','(objectClass=Test5)');
+RT->Config->Set('LDAPGroupMapping',
+                   {Name                => 'cn',
+                    Member_Attr         => 'memberUid',
+                    Member_Attr_Value   => 'uid',
+		    Member_Attr_Regex   => qr/^cn=(\w+)\,/,
+                   });
+
+import_group_members_ok( memberUid => 'uid' );
+
 sub import_group_members_ok {
     my $attr = shift;
     my $user_attr = shift;

commit add5d84bebe5f7ac09a3222847b3821ae1296513
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Apr 9 13:20:30 2012 -0400

    Adding back docs for this feature.

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index b4a7b70..c663094 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -18,6 +18,23 @@ use Data::Dumper;
 
 RT::Extension::LDAPImport - Import Users from an LDAP store
 
+=head1 CONFIGURATION
+
+If the LDAP group field you are mapping to doesn't have a
+simple username, you provide a regex to pull the name out
+with Member_Attr_Regex. The capture value in the regex will be
+used to find the username.
+
+    Set($LDAPGroupMapping, {Name               => 'cn',
+                            Member_Attr        => 'member',
+                            Member_Attr_Value  => 'dn'
+                            Member_Attr_Regex   => qr/^cn=(\w+)\,/,
+                           });
+
+The above would pull the name out of an entry something like
+
+    cn=somename,ou=company
+
 =head1 METHODS
 
 =head2 connect_ldap

commit 672722b901b3380c876d2f0e52c2c3d412da239f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Apr 9 13:23:06 2012 -0400

    Putting back the old Synopsis.

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index c663094..0da089a 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -18,6 +18,10 @@ use Data::Dumper;
 
 RT::Extension::LDAPImport - Import Users from an LDAP store
 
+=head1 SYNOPSIS
+
+    use RT::Extension::LDAPImport;
+
 =head1 CONFIGURATION
 
 If the LDAP group field you are mapping to doesn't have a

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



More information about the Bps-public-commit mailing list