View | Details | Raw Unified | Return to bug 8993
Collapse All | Expand All

(-)a/C4/Auth_with_ldap.pm (-5 / +9 lines)
Lines 77-83 unless ( $$ldap{authmethod} ) { Link Here
77
77
78
$ldapname     = $ldap->{user};
78
$ldapname     = $ldap->{user};
79
$ldappassword = $ldap->{pass};
79
$ldappassword = $ldap->{pass};
80
our %mapping  = %{$ldap->{mapping}}; # FIXME dpavlin -- don't die because of || (); from 6eaf8511c70eb82d797c941ef528f4310a15e9f9
80
our %mapping  = %{$ldap->{mapping}} if $ldap->{mapping};
81
my @mapkeys = keys %mapping;
81
my @mapkeys = keys %mapping;
82
$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
82
$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
83
@mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
83
@mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
Lines 177-183 sub accept_borrower { Link Here
177
        }
177
        }
178
    }
178
    }
179
179
180
    my ($id) = exists_local( $userid ) or debug_msg "$userid is newcommer";
180
    my ($id, $cardnumber) = exists_local( $userid ) or debug_msg "$userid is newcommer";
181
181
182
    my $newcommer = not $id;
182
    my $newcommer = not $id;
183
183
Lines 189-195 sub accept_borrower { Link Here
189
        if ( $config{replicate} ) {
189
        if ( $config{replicate} ) {
190
            delete $$borrower{column}{dateenrolled};
190
            delete $$borrower{column}{dateenrolled};
191
            delete $$borrower{column}{dateexpiry};
191
            delete $$borrower{column}{dateexpiry};
192
            my $cardnumber = update_local
192
            $cardnumber = update_local
193
            ( $userid, $$borrower{column}{password}, $id, $$borrower{column} ); 
193
            ( $userid, $$borrower{column}{password}, $id, $$borrower{column} ); 
194
            if ( my $old_cardnumber = $$borrower{column}{cardnumber} ) {
194
            if ( my $old_cardnumber = $$borrower{column}{cardnumber} ) {
195
                if ( $old_cardnumber ne $cardnumber ) {
195
                if ( $old_cardnumber ne $cardnumber ) {
Lines 205-211 sub accept_borrower { Link Here
205
        set_xattr $id, $borrower;
205
        set_xattr $id, $borrower;
206
    }
206
    }
207
207
208
    return 1
208
    return ( 1, $cardnumber, $userid );
209
}
209
}
210
210
211
sub cnx {
211
sub cnx {
Lines 214-220 sub cnx { Link Here
214
    };
214
    };
215
    # bind MUST success
215
    # bind MUST success
216
    my $msg = eval {
216
    my $msg = eval {
217
        $cnx->bind ($ldap->{manager}, password => $ldap->{password})
217
        if ( $ldap->{manager} ) {
218
            $cnx->bind ($ldap->{manager}, password => $ldap->{password})
219
        } else {
220
            $cnx->bind();
221
        }
218
    };
222
    };
219
    debug_msg "ldap $_:", $msg->$_ for qw/ error code /;
223
    debug_msg "ldap $_:", $msg->$_ for qw/ error code /;
220
    if ( $@ ) {
224
    if ( $@ ) {
(-)a/C4/LDAPAuthMethodTutorial.pod (-9 / +28 lines)
Lines 8-19 a try if your needs of mappings and transformations are low. Link Here
8
8
9
=head3 How to reach the service
9
=head3 How to reach the service
10
10
11
What we need is build the url of the ldap service we want to reach. So ask him
11
What we need is build the uri of the ldap service we want to reach. So ask him
12
for the URL. If he don't know, ask for the scheme (or protocol), the hostname
12
for the URL. If he don't know, ask for the scheme (or protocol), the hostname
13
and the port of the directory. Only hostname and scheme are mandatory.
13
and the port of the directory. Only hostname and scheme are mandatory.
14
14
15
The scheme must be ldap or ldaps (ldaps is for crypted ldap, ldap over SSL).
15
The scheme must be ldap or ldaps (ldaps is for crypted ldap, ldap over SSL).
16
The url construction is:
16
The uri construction is:
17
17
18
    scheme://hostname:port
18
    scheme://hostname:port
19
    scheme://hostname
19
    scheme://hostname
Lines 49-65 First of all, you need to tell koha that ldap authentication is now relevant Link Here
49
49
50
    <useldapserver>1</useldapserver>
50
    <useldapserver>1</useldapserver>
51
51
52
If you use anonymous method, you have to give credentials of koha account
52
If you are using anonymous method, you just omit LDAP credentials
53
53
54
    <ldapserver url="ldap://directory.example.com"
54
    <ldapserver uri="ldap://directory.example.com"
55
          manager="uid=koha,ou=people,dc=example,dc=com"
56
          password="MYS3CRET"
57
          authmethod="search_dn" >
55
          authmethod="search_dn" >
58
56
59
Also, you can set the values for replication and update (documented in legacy
57
Also, you can set the values for replication and update (documented in legacy
60
pod):
58
pod):
61
59
62
    <ldapserver url="ldap://directory.example.com"
60
    <ldapserver uri="ldap://directory.example.com"
63
          manager="uid=koha,ou=people,dc=example,dc=com"
61
          manager="uid=koha,ou=people,dc=example,dc=com"
64
          password="MYS3CRET"
62
          password="MYS3CRET"
65
          authmethod="search_dn"
63
          authmethod="search_dn"
Lines 69-75 pod): Link Here
69
You must now tell koha the ldap branches where to find users
67
You must now tell koha the ldap branches where to find users
70
68
71
    <useldapserver>1</useldapserver>
69
    <useldapserver>1</useldapserver>
72
    <ldapserver url="ldap://directory.example.com"
70
    <ldapserver uri="ldap://directory.example.com"
73
          manager="uid=koha,ou=people,dc=example,dc=com"
71
          manager="uid=koha,ou=people,dc=example,dc=com"
74
          password="MYS3CRET"
72
          password="MYS3CRET"
75
          authmethod="search_dn"
73
          authmethod="search_dn"
Lines 85-91 sofisticated transformations directly in perl: Link Here
85
83
86
      <transformation module="C4::LDAPTransform::CustomTransform" />
84
      <transformation module="C4::LDAPTransform::CustomTransform" />
87
85
88
This module only have to define a subroutine named get_borrower
86
This module only have to define a subroutine named get_borrower which will
87
receive C<Net::LDAP::Entry> object and returns hash which corresponds to
88
fields in C<borrowers> table similar to:
89
89
90
    {
91
        column => {
92
            email     => "test.user\\@example.com",
93
            firstname => "Test",
94
            surname   => "User"
95
            userid    => "testuser",
96
        }
97
    }
90
98
99
If you don't have <mapping> section in your C<kona-conf.xml> you will have
100
to add additional attribute to your ldapserver directive to indicate which
101
field will be used to bind to LDAP using <userid_from>:
102
103
    <ldapserver uri="ldap://directory.example.com"
104
          manager="uid=koha,ou=people,dc=example,dc=com"
105
          password="MYS3CRET"
106
          authmethod="search_dn"
107
          replicate="1" update="1"
108
          userid_from="uid"
109
    >
91
110
(-)a/C4/LDAPTransform/RepeatableValues.pm (-1 / +27 lines)
Line 0 Link Here
0
- 
1
package C4::LDAPTransform::Example;
2
3
use warnings;
4
use strict;
5
6
my $mapping = { qw/
7
givenName	firstname
8
sn		surname
9
uid		userid
10
mail		email
11
/ };
12
13
sub get_borrower {
14
	my $ldap_entry = shift;
15
	$ldap_entry->isa('Net::LDAP::Entry') or die "argument to transform get_borrower is not Net::LDAP::Entry";
16
17
	my $user = { column => {} };
18
19
	while (my ($from, $to) = each %$mapping) {
20
		my @vals = $ldap_entry->get_value( $from );
21
		$user->{column}->{$to} = $vals[0];
22
	}
23
24
	return $user;
25
}
26
27
1;

Return to bug 8993