File Coverage

blib/lib/App/LDAP/LDIF/User.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package App::LDAP::LDIF::User;
2              
3 1     1   4 use Modern::Perl;
  1         1  
  1         8  
4              
5 1     1   579 use Moose;
  0            
  0            
6              
7             extends qw(
8             App::LDAP::ObjectClass::PosixAccount
9             App::LDAP::ObjectClass::ShadowAccount
10             App::LDAP::ObjectClass::InetOrgPerson
11             App::LDAP::LDIF
12             );
13              
14             around BUILDARGS => sub {
15             my $orig = shift;
16             my $self = shift;
17             push @_, (dn => "uid=".{@_}->{uid}.",".{@_}->{base}) if grep /^base$/, @_;
18             $self->$orig(@_);
19             };
20              
21             has '+cn' => (
22             lazy => 1,
23             default => sub {
24             [shift->uid]
25             },
26             );
27              
28             has '+objectClass' => (
29             default => sub {
30             [
31             qw( inetOrgPerson
32             posixAccount
33             top
34             shadowAccount )
35             ],
36             },
37             );
38              
39             has '+userPassword' => (
40             required => 1,
41             );
42              
43             has '+loginShell' => (
44             default => "/bin/bash",
45             );
46              
47             has '+homeDirectory' => (
48             lazy => 1,
49             default => sub {
50             "/home/" . shift->uid;
51             },
52             );
53              
54             has '+shadowLastChange' => (
55             default => sub {
56             use Date::Calc qw(Today Delta_Days);
57             Delta_Days(
58             1970, 1, 1,
59             Today()
60             );
61             },
62             );
63              
64             has '+shadowMin' => (
65             default => 0,
66             );
67              
68             has '+shadowMax' => (
69             default => 99999,
70             );
71              
72             has '+shadowWarning' => (
73             default => 7,
74             );
75              
76             __PACKAGE__->meta->make_immutable;
77             no Moose;
78             1;
79              
80             =pod
81              
82             =head1 NAME
83              
84             App::LDAP::LDIF::User - the representation of users in LDAP
85              
86             =head1 SYNOPSIS
87              
88             my $user = App::LDAP::LDIF::User->new(
89             base => $base, # the OU (organization unit) which the user belongs to
90             uid => $name, # user name
91             userPassword => $password, # the password used by the user
92             uidNumber => $uid, # the uid of the user
93             gidNumber => $gid, # the gid of the user
94             sn => [$sn], # the surname of this user
95             );
96             # these 6 parameters are required
97             # extra parameters of attributes such as title of User can be provided in constructor, too.
98              
99             $user->loginShell("/bin/zsh")
100             # set zsh as the user's shell
101              
102             $uesr->gidNumber("27")
103             # set the user to have 27 as group id
104              
105             my $entry = $user->entry
106             # get the user as a instance of Net::LDAP::Entry
107              
108             my $from_entry = App::LDAP::LDIF::User->new($entry)
109             # new from a Net::LDAP::Entry instance
110              
111             =head1 DESCRIPTION
112              
113             App::LDAP::LDIF::User is composed of objectClass top, posixAccount, shadowAccount and inetOrgPerson.
114              
115             The objectClass top is described in RFC2256 (core.schema of OpenLDAP) indicating this kind of entry MUST have objectClass.
116              
117             The early versions used objectClass account rather than inetOrgPerson. Both account and inetOrgPerson are STRUCTURAL so
118             that only one of them could be satisfied.
119              
120             The objectClass posixAccount and shadowAccount are described in RFC2307 (nis.schema of OpenLDAP).
121              
122             The objectClass inetOrgPerson is described in RFC2798 (inetorgperson.schema of OpenLDAP). The inetOrgPerson is derived
123             from organizationalPerson which is derived from person.
124              
125             =head1 NOTES
126              
127             =head2 userPassword
128              
129             The objectClass posixAccount and shadowAccount define userPassword MAY be an attribute of a uesr. Because App::LDAP is
130             designed for working with pam_ldap, userPassword is defined as a required attribute here.
131              
132             =head2 sn
133              
134             The objectClass inetOrgPerson is derived from organizationalPerson which is derived from person. The person defines sn
135             MUST be a attribute of a user. Since the inetOrgPerson has sn as a required attribute.
136              
137             =head2 cn
138              
139             required attributes. default [ $self->uid ]
140              
141             =head2 loginShell
142              
143             default /bin/bash
144              
145             =head2 shadowLastChange
146              
147             the days from Unix Epoch that last time you changed password.
148              
149             default value is calculated via Date::Calc::Delta_Days().
150              
151             =head2 shadowMin
152              
153             the minimum days that user can change their password.
154              
155             default 0
156              
157             =head2 shadowMax
158              
159             the maximun days that user have to change their password.
160              
161             default 99999
162              
163             =head2 shadowWarning
164              
165             the day that user would be warned before password to be expired
166              
167             default 7
168              
169             =head2 homeDirectory
170              
171             default "/home/" . $self->uid
172              
173             =cut