6 |
use Net::LDAP; |
use Net::LDAP; |
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use base qw(Jifty::Object Class::Accessor::Fast); |
use base qw(Jifty::Object Class::Accessor::Fast); |
9 |
our @config_fields = qw( server dn password base ); |
use Jifty; |
10 |
|
our @config_fields = keys %{ Jifty->config->app('LDAP') }; |
11 |
Jifty->log->debug("using fields from configuration: ",dump( @config_fields )); |
Jifty->log->debug("using fields from configuration: ",dump( @config_fields )); |
12 |
__PACKAGE__->mk_accessors( qw(ldap current_search), @config_fields ); |
__PACKAGE__->mk_accessors( qw(ldap current_search), @config_fields ); |
13 |
|
|
43 |
} |
} |
44 |
} |
} |
45 |
|
|
46 |
|
# configuration sanity testing |
47 |
|
foreach ( qw/server dn password base objectClass link/ ) { |
48 |
|
die "missing required field $_ in LDAP from etc/config.yaml" unless $args->{$_}; |
49 |
|
} |
50 |
|
foreach ( qw/person organization/ ) { |
51 |
|
die "missing required field $_ in LDAP.objectClass.$_ from etc/config.yaml" unless $args->{objectClass}->{$_}; |
52 |
|
} |
53 |
|
foreach ( qw/person_filter display_from value_from/ ) { |
54 |
|
die "missing required field $_ in LDAP.link.$_ from etc/config.yaml" unless $args->{link}->{$_}; |
55 |
|
} |
56 |
|
|
57 |
my $ldap = Net::LDAP->new( $args->{server} ) or die "$@"; |
my $ldap = Net::LDAP->new( $args->{server} ) or die "$@"; |
58 |
|
|
59 |
# an anonymous bind |
# an anonymous bind |
114 |
$self->current_search->count; |
$self->current_search->count; |
115 |
} |
} |
116 |
|
|
117 |
=head2 as_collection_of |
=head2 collection |
118 |
|
|
119 |
my $connection = $ldap->collection( |
my $connection = $ldap->collection( |
120 |
# name of model to use |
# name of model to use |
121 |
'Organization', |
$ldap->objectClass->{organization}, |
122 |
# optional params |
# optional params |
123 |
limit => $limit, |
limit => $limit, |
124 |
filter => '(uid=foobar)', |
filter => '(uid=foobar)', |
163 |
|
|
164 |
while ( my $entry = $self->next ) { |
while ( my $entry = $self->next ) { |
165 |
my $model_obj = Jifty->app_class('Model',$model)->new; |
my $model_obj = Jifty->app_class('Model',$model)->new; |
|
#warn dump( $model_obj ); |
|
166 |
my $additional; |
my $additional; |
167 |
$self->model_from_entry( $model_obj, $entry, %$additional ); |
$self->model_from_entry( $model_obj, $entry, %$additional ); |
168 |
$collection->add_record( $model_obj ); |
$collection->add_record( $model_obj ); |
183 |
|
|
184 |
$ldap->model_from_entry( $model, $entry, $additional ); |
$ldap->model_from_entry( $model, $entry, $additional ); |
185 |
|
|
186 |
|
This method will join repeatable attributes by magic marker, |
187 |
|
see C<XXX> in code! |
188 |
|
|
189 |
=cut |
=cut |
190 |
|
|
191 |
sub model_from_entry { |
sub model_from_entry { |
199 |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
200 |
$data->{$attr} = $entry->get_value( $attr ); |
$data->{$attr} = $entry->get_value( $attr ); |
201 |
# } elsif ( $attr !~ m/^(objectClass)$/i ) { |
# } elsif ( $attr !~ m/^(objectClass)$/i ) { |
202 |
# Jifty->log->warn(ref($model)," doesn't have $attr"); |
} else { |
203 |
|
Jifty->log->warn(ref($model)," doesn't have $attr"); |
204 |
} |
} |
205 |
} |
} |
206 |
|
|