From 4f040e0da15eeddc2800a1248539f795420f8e0e Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 21 Mar 2013 15:48:47 +0100 Subject: [PATCH] Bug 8993 - my attempt to get this module working QA note: please fail this patch. With all this changes, I'm still not able to login using following configuration: This should be one of more simple configuration, and it doesn't work with this patch. While I would love to have LDAP transformations in perl code, I think this patch is too big rewrite with a lot of edge cases which aren't convered. --- C4/Auth_with_ldap.pm | 14 ++++++++---- C4/LDAPAuthMethodTutorial.pod | 37 +++++++++++++++++++++++++-------- C4/LDAPTransform/RepeatableValues.pm | 27 ++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 C4/LDAPTransform/RepeatableValues.pm diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 5eff737..b8720af 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -77,7 +77,7 @@ unless ( $$ldap{authmethod} ) { $ldapname = $ldap->{user}; $ldappassword = $ldap->{pass}; -our %mapping = %{$ldap->{mapping}}; # FIXME dpavlin -- don't die because of || (); from 6eaf8511c70eb82d797c941ef528f4310a15e9f9 +our %mapping = %{$ldap->{mapping}} if $ldap->{mapping}; my @mapkeys = keys %mapping; $debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys ( total ): ", join ' ', @mapkeys, "\n"; @mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys; @@ -177,7 +177,7 @@ sub accept_borrower { } } - my ($id) = exists_local( $userid ) or debug_msg "$userid is newcommer"; + my ($id, $cardnumber) = exists_local( $userid ) or debug_msg "$userid is newcommer"; my $newcommer = not $id; @@ -189,7 +189,7 @@ sub accept_borrower { if ( $config{replicate} ) { delete $$borrower{column}{dateenrolled}; delete $$borrower{column}{dateexpiry}; - my $cardnumber = update_local + $cardnumber = update_local ( $userid, $$borrower{column}{password}, $id, $$borrower{column} ); if ( my $old_cardnumber = $$borrower{column}{cardnumber} ) { if ( $old_cardnumber ne $cardnumber ) { @@ -205,7 +205,7 @@ sub accept_borrower { set_xattr $id, $borrower; } - return 1 + return ( 1, $cardnumber, $userid ); } sub cnx { @@ -214,7 +214,11 @@ sub cnx { }; # bind MUST success my $msg = eval { - $cnx->bind ($ldap->{manager}, password => $ldap->{password}) + if ( $ldap->{manager} ) { + $cnx->bind ($ldap->{manager}, password => $ldap->{password}) + } else { + $cnx->bind(); + } }; debug_msg "ldap $_:", $msg->$_ for qw/ error code /; if ( $@ ) { diff --git a/C4/LDAPAuthMethodTutorial.pod b/C4/LDAPAuthMethodTutorial.pod index 92cac6b..440c110 100644 --- a/C4/LDAPAuthMethodTutorial.pod +++ b/C4/LDAPAuthMethodTutorial.pod @@ -8,12 +8,12 @@ a try if your needs of mappings and transformations are low. =head3 How to reach the service -What we need is build the url of the ldap service we want to reach. So ask him +What we need is build the uri of the ldap service we want to reach. So ask him for the URL. If he don't know, ask for the scheme (or protocol), the hostname and the port of the directory. Only hostname and scheme are mandatory. The scheme must be ldap or ldaps (ldaps is for crypted ldap, ldap over SSL). -The url construction is: +The uri construction is: scheme://hostname:port scheme://hostname @@ -49,17 +49,15 @@ First of all, you need to tell koha that ldap authentication is now relevant 1 -If you use anonymous method, you have to give credentials of koha account +If you are using anonymous method, you just omit LDAP credentials - Also, you can set the values for replication and update (documented in legacy pod): - 1 - -This module only have to define a subroutine named get_borrower +This module only have to define a subroutine named get_borrower which will +receive C object and returns hash which corresponds to +fields in C table similar to: + { + column => { + email => "test.user\\@example.com", + firstname => "Test", + surname => "User" + userid => "testuser", + } + } +If you don't have section in your C you will have +to add additional attribute to your ldapserver directive to indicate which +field will be used to bind to LDAP using : + + diff --git a/C4/LDAPTransform/RepeatableValues.pm b/C4/LDAPTransform/RepeatableValues.pm new file mode 100644 index 0000000..dc7c289 --- /dev/null +++ b/C4/LDAPTransform/RepeatableValues.pm @@ -0,0 +1,27 @@ +package C4::LDAPTransform::Example; + +use warnings; +use strict; + +my $mapping = { qw/ +givenName firstname +sn surname +uid userid +mail email +/ }; + +sub get_borrower { + my $ldap_entry = shift; + $ldap_entry->isa('Net::LDAP::Entry') or die "argument to transform get_borrower is not Net::LDAP::Entry"; + + my $user = { column => {} }; + + while (my ($from, $to) = each %$mapping) { + my @vals = $ldap_entry->get_value( $from ); + $user->{column}->{$to} = $vals[0]; + } + + return $user; +} + +1; -- 1.7.2.5