14 |
my $ldap_config = Jifty->config->app('LDAP'); |
my $ldap_config = Jifty->config->app('LDAP'); |
15 |
Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); |
Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); |
16 |
|
|
17 |
my $ldap = Net::LDAP->new( Jifty->config->app('LDAP')->{Server} ) or die "$@"; |
my $ldap = Net::LDAP->new( $ldap_config->{Server} ) or die "$@"; |
18 |
|
|
19 |
# an anonymous bind |
# an anonymous bind |
20 |
#my $mesg = $ldap->bind; |
#my $mesg = $ldap->bind; |
21 |
my $mesg = $ldap->bind( |
my $mesg = $ldap->bind( |
22 |
DN => Jifty->config->app('LDAP')->{DN}, |
DN => $ldap_config->{DN}, |
23 |
password => Jifty->config->app('LDAP')->{Password}, |
password => $ldap_config->{Password}, |
24 |
); |
); |
25 |
|
|
26 |
|
Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN}); |
27 |
|
|
28 |
# perform a search |
# perform a search |
29 |
$mesg = $ldap->search( |
$mesg = $ldap->search( |
30 |
base => "dc=skole,dc=hr", |
base => "dc=skole,dc=hr", |
31 |
# filter => "(&(sn=Barr) (o=Texas Instruments))", |
# filter => "(&(sn=Barr) (o=Texas Instruments))", |
32 |
filter => "(objectClass=hrEduPerson)", |
filter => "(objectClass=hrEduPerson)", |
33 |
sizelimit => 3, # 0 = off |
sizelimit => 100, # 0 = off |
34 |
); |
); |
35 |
|
|
36 |
if ( $mesg->code ) { |
if ( $mesg->code ) { |
44 |
$entry->dump; |
$entry->dump; |
45 |
|
|
46 |
my $data; |
my $data; |
47 |
my $user = CAdmin::Model::User->new; |
my $user = A3C::Model::User->new; |
48 |
|
|
49 |
my @columns = map { $_->name } $user->columns; |
my @columns = map { $_->name } $user->columns; |
50 |
#warn "# columns = ",dump( @columns ); |
#warn "# columns = ",dump( @columns ); |
53 |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
54 |
$data->{$attr} = $entry->get_value( $attr ); |
$data->{$attr} = $entry->get_value( $attr ); |
55 |
} else { |
} else { |
56 |
warn "model ",ref($user)," doesn't have column $attr\n"; |
Jifty->log->error(ref($user)," doesn't have $attr"); |
57 |
} |
} |
58 |
} |
} |
59 |
|
|
60 |
Jifty->log->debug( dump( $data ) ); |
Jifty->log->debug( dump( $data ) ); |
61 |
|
|
62 |
$user->load_or_create( %$data ); |
my ( $id, $message ) = $user->load_or_create( %$data ); |
63 |
|
|
64 |
|
Jifty->log->error( $message ) if ! $id; |
65 |
} |
} |
66 |
|
|