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

(-)a/C4/Auth_with_ldap.pm (-5 / +9 lines)
Lines 78-84 unless ( $$ldap{authmethod} ) { Link Here
78
78
79
$ldapname     = $ldap->{user};
79
$ldapname     = $ldap->{user};
80
$ldappassword = $ldap->{pass};
80
$ldappassword = $ldap->{pass};
81
our %mapping  = %{$ldap->{mapping}}; # FIXME dpavlin -- don't die because of || (); from 6eaf8511c70eb82d797c941ef528f4310a15e9f9
81
our %mapping  = %{$ldap->{mapping}} if $ldap->{mapping};
82
my @mapkeys = keys %mapping;
82
my @mapkeys = keys %mapping;
83
$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
83
$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
84
@mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
84
@mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
Lines 178-184 sub accept_borrower { Link Here
178
        }
178
        }
179
    }
179
    }
180
180
181
    my ($id) = exists_local( $userid ) or debug_msg "$userid is newcommer";
181
    my ($id, $cardnumber) = exists_local( $userid ) or debug_msg "$userid is newcommer";
182
182
183
    my $newcommer = not $id;
183
    my $newcommer = not $id;
184
184
Lines 190-196 sub accept_borrower { Link Here
190
        if ( $config{replicate} ) {
190
        if ( $config{replicate} ) {
191
            delete $$borrower{column}{dateenrolled};
191
            delete $$borrower{column}{dateenrolled};
192
            delete $$borrower{column}{dateexpiry};
192
            delete $$borrower{column}{dateexpiry};
193
            my $cardnumber = update_local
193
            $cardnumber = update_local
194
            ( $userid, $$borrower{column}{password}, $id, $$borrower{column} ); 
194
            ( $userid, $$borrower{column}{password}, $id, $$borrower{column} ); 
195
            if ( my $old_cardnumber = $$borrower{column}{cardnumber} ) {
195
            if ( my $old_cardnumber = $$borrower{column}{cardnumber} ) {
196
                if ( $old_cardnumber ne $cardnumber ) {
196
                if ( $old_cardnumber ne $cardnumber ) {
Lines 206-212 sub accept_borrower { Link Here
206
        set_xattr $id, $borrower;
206
        set_xattr $id, $borrower;
207
    }
207
    }
208
208
209
    return 1
209
    return ( 1, $cardnumber, $userid );
210
}
210
}
211
211
212
sub cnx {
212
sub cnx {
Lines 215-221 sub cnx { Link Here
215
    };
215
    };
216
    # bind MUST success
216
    # bind MUST success
217
    my $msg = eval {
217
    my $msg = eval {
218
        $cnx->bind ($ldap->{manager}, password => $ldap->{password})
218
        if ( $ldap->{manager} ) {
219
            $cnx->bind ($ldap->{manager}, password => $ldap->{password})
220
        } else {
221
            $cnx->bind();
222
        }
219
    };
223
    };
220
    debug_msg "ldap $_:", $msg->$_ for qw/ error code /;
224
    debug_msg "ldap $_:", $msg->$_ for qw/ error code /;
221
    if ( $@ ) {
225
    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