@@ -, +, @@ authmethod="search_dn" replicate="1" update="0" userid_from="uid" > --- 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 --- a/C4/Auth_with_ldap.pm +++ a/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 ( $@ ) { --- a/C4/LDAPAuthMethodTutorial.pod +++ a/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 : + + --- a/C4/LDAPTransform/RepeatableValues.pm +++ a/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; --