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 ); |
our @config_fields = keys %{ Jifty->config->app('LDAP') }; |
10 |
Jifty->log->debug("using fields from configuration: ",dump( @config_fields )); |
Jifty->log->debug("using fields from configuration: ",dump( @config_fields )); |
11 |
__PACKAGE__->mk_accessors( qw(ldap current_search), @config_fields ); |
__PACKAGE__->mk_accessors( qw(ldap current_search), @config_fields ); |
12 |
|
|
42 |
} |
} |
43 |
} |
} |
44 |
|
|
45 |
|
# configuration sanity testing |
46 |
|
foreach ( qw/server dn password base objectClass link/ ) { |
47 |
|
die "missing required field $_ in LDAP from etc/config.yaml" unless $args->{$_}; |
48 |
|
} |
49 |
|
foreach ( qw/person organization/ ) { |
50 |
|
die "missing required field $_ in LDAP.objectClass.$_ from etc/config.yaml" unless $args->{objectClass}->{$_}; |
51 |
|
} |
52 |
|
foreach ( qw/person_filter display_from value_from/ ) { |
53 |
|
die "missing required field $_ in LDAP.link.$_ from etc/config.yaml" unless $args->{link}->{$_}; |
54 |
|
} |
55 |
|
|
56 |
my $ldap = Net::LDAP->new( $args->{server} ) or die "$@"; |
my $ldap = Net::LDAP->new( $args->{server} ) or die "$@"; |
57 |
|
|
58 |
# an anonymous bind |
# an anonymous bind |
113 |
$self->current_search->count; |
$self->current_search->count; |
114 |
} |
} |
115 |
|
|
116 |
=head2 as_collection_of |
=head2 collection |
117 |
|
|
118 |
my $connection = $ldap->collection( |
my $connection = $ldap->collection( |
119 |
# name of model to use |
# name of model to use |
120 |
'Organization', |
$ldap->objectClass->{organization}, |
121 |
# optional params |
# optional params |
122 |
limit => $limit, |
limit => $limit, |
123 |
filter => '(uid=foobar)', |
filter => '(uid=foobar)', |
196 |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
197 |
$data->{$attr} = $entry->get_value( $attr ); |
$data->{$attr} = $entry->get_value( $attr ); |
198 |
# } elsif ( $attr !~ m/^(objectClass)$/i ) { |
# } elsif ( $attr !~ m/^(objectClass)$/i ) { |
199 |
# Jifty->log->warn(ref($model)," doesn't have $attr"); |
} else { |
200 |
|
Jifty->log->warn(ref($model)," doesn't have $attr"); |
201 |
} |
} |
202 |
} |
} |
203 |
|
|