source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap/Onlyaddress.pm @ 1616

Last change on this file since 1616 was 1491, checked in by nanardon, 9 years ago

Typo

File size: 3.3 KB
Line 
1package LATMOS::Accounts::Bases::Ldap::Onlyaddress;
2
3use 5.010000;
4use strict;
5use warnings;
6
7use base qw(LATMOS::Accounts::Bases::Ldap::objects);
8use Net::LDAP;
9use Net::LDAPS;
10use Net::LDAP::Entry;
11use Net::LDAP::Control::Paged;
12use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); 
13use Net::LDAP::Util     qw( escape_filter_value );
14use LATMOS::Accounts::Log;
15
16our $VERSION = (q$Rev: 649 $ =~ /^Rev: (\d+) /)[0];
17
18=head1 NAME
19
20LATMOS::Ldap - Perl extension for blah blah blah
21
22=head1 SYNOPSIS
23
24  use LATMOS::Ldap;
25  blah blah blah
26
27=head1 DESCRIPTION
28
29Stub documentation for LATMOS::Ldap, created by h2xs. It looks like the
30author of the extension was negligent enough to leave the stub
31unedited.
32
33Blah blah blah.
34
35=head1 FUNCTIONS
36
37=cut
38
39sub _class_filter { '(&(ObjectClass=inetOrgPerson))' }
40
41sub _key_attr { 'cn' } 
42
43sub _my_ldap_classes { qw(
44    top
45    inetOrgPerson
46    organizationalPerson
47) }
48
49sub _get_attr_schema {
50    my ($class, $base) = @_;
51    my $info = {
52        # inetOrgPerson
53        displayName => {},
54        givenName => {},
55        initials => {},
56        # mail => {},
57        sn => {},
58        mobile => {},
59        o => {},
60        uid => {},
61        facsimileTelephoneNumber => {},
62        # organizationalPerson
63        street => {},
64        postOfficeBox => {},
65        postalCode => {},
66        postalAddress => {},
67        streetAddress => {},
68        physicalDeliveryOfficeName => {},
69        ou => {},
70        st => {},
71        l => {},
72        telephoneNumber => {},
73        cn => { ro => 1 },
74        dn => { ro => 1 },
75        objectClass => { ro => 1 },
76    };
77
78    $info->{$class->_key_attribute($base)}{ro} = 1;
79    $info->{$class->_dn_attribute($base)}{ro} = 1;
80
81    $info
82}
83
84sub is_supported {
85    my ($class, $base) = @_;
86    return $base->config('onlyaddress_container') ? 1 : 0;
87}
88
89sub _create {
90    my ($class, $base, $id, %data) = @_;
91
92    my $entry = Net::LDAP::Entry->new();
93
94    $entry->dn(join(',',
95        sprintf('%s=%s',
96            $class->_dn_attribute($base),
97            escape_filter_value($id)),
98            $base->object_base_dn($class->type),
99    ));
100    $entry->replace(objectClass =>
101        [ $class->_my_ldap_classes ],);
102    $data{sn} ||= $id; # sn is mandatory
103    $data{$class->_key_attribute($base)} = $id;
104    foreach (keys %data) {
105        $class->_populate_entry($entry,
106            $_, $data{$_}, $base);
107    }
108
109    my $msg = $base->ldap->add($entry);
110    if ($msg->code) {
111        $base->log(LA_ERR, "Cannot create onlyaddress: %s", $msg->error);
112        return 0;
113    }
114    return 1;
115}
116
117sub get_field {
118    my ($self, $field) = @_;
119
120    $field eq 'streetAddress' and $field = 'street';
121    $self->SUPER::get_field($field);
122}
123
124sub _populate_entry {
125    my ($self, $entry, $f, $val, $base) = @_;
126    $base ||= $self->base;
127    for ($f) {
128        /^sn$/ and $val ||= $entry->get_value($self->_key_attribute($base));
129    }
130    $self->SUPER::_populate_entry($entry, $f, $val, $base);
131}
132
1331;
134
135__END__
136
137=head1 SEE ALSO
138
139=head1 AUTHOR
140
141Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt>
142
143=head1 COPYRIGHT AND LICENSE
144
145Copyright (C) 2008 CNRS SA/CETP/LATMOS
146
147This library is free software; you can redistribute it and/or modify
148it under the same terms as Perl itself, either Perl version 5.10.0 or,
149at your option, any later version of Perl 5 you may have available.
150
151=cut
Note: See TracBrowser for help on using the repository browser.