blib/lib/Lemonldap/Portal/Authntsso.pm

filter: Statementstmt 11.1% 20 / 179 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 23.0% 6 / 26 Podpod 66.6% 6 / 9 totaltotal 10.9% 32 / 293 CC 30 SCAR 32.2
CC
30
Cov
8%
__controlSyntax
90.0
process
42.0
func_bind
20.0
CRAP 25.1
↑ Summary
1 package Lemonldap::Portal::Authntsso;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::LDAP;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Authen::Smb;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '0.05';
9  
10 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
11 0 my $class = shift;
12 0 my %args = @_;
13 0 ▶ my $self = bless {}, ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
14 0 $self->{controlUrlOrigin} = \&__controlUrlOrigin;
15 0 $self->{controlTimeOut} = \&__controlTimeOut;
16 0 $self->{controlSyntax} = \&__controlSyntax;
17 0 $self->{bind} = \&__bind;
18 0 $self->{formateUser} = \&__none;
19 0 $self->{formateFilter} = \&__Filter;
20 0 $self->{formateBaseLDAP} = \&__none;
21 0 $self->{contactServer} = \&__contactServer;
22 0 $self->{bind} = \&__bind;
23 0 $self->{search} = \&__ldapsearch;
24 0 $self->{setSessionInfo} = \&__session;
25 0 $self->{unbind} = \&__unbind;
26 0 $self->{credentials} = \&__credentials;
27 0 my $mess = {
28 1 =>
29 'Your connection has expired; You must to be authentified once again',
30 2 => 'User and password fields must be filled',
31 3 => 'Wrong directory manager account or password',
32 4 => 'not found in directory',
33 5 => 'wrong credentials',
34 };
35 0 $self->{msg} = $mess;
36  
37 0 foreach ( keys %args ) {
38 0 $self->{$_} = $args{$_};
39 }
40  
41 0 return $self;
42 }
43 ##------------------------------------------------------------------
44 ## method none
45 ## This method does nothing ..
46 ##------------------------------------------------------------------
47 0 ▶sub __none { #does ...nothing;
Subroutine __none: not called CC=1 SCAR=0.0
48  
49 }
50 ##------------------------------------------------------------------
51 ## method controlUrlOrigin
52 ## This method looks at param cgi 'urlc' in order to determine if
53 ## the request comes with a vip url (redirection) or for the menu
54 ##------------------------------------------------------------------
55 0 ▶sub __controlUrlOrigin {
Subroutine __controlUrlOrigin: not called CC=2 SCAR=17.9
56 0 my $urldc;
57 0 my $self = shift;
58 0 my $urlc = $self->{param}->{'url'};
59  
60 0 ▶ if ( defined($urlc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $urlc) 0 0 0
61 0 $urldc = decode_base64($urlc);
62  
63 # $urldc =~ s#:\d+/#/#; # Suppress port number in URL
64 0 $urlc = encode_base64( $urldc, '' );
65 0 $self->{'urlc'} = $urlc;
66 0 $self->{'urldc'} = $urldc;
67 }
68 }
69 ##------------------------------------------------------------------
70 ## method controlTimeOut
71 ## This method looks at param cgi 'op'
72 ## if op eq 't' (like timeout) the handler couldn't retrieve the
73 ## storage session from id session
74 ##------------------------------------------------------------------
75 0 ▶sub __controlTimeOut {
Subroutine __controlTimeOut: not called CC=3 SCAR=24.8
76 0 my $self = shift;
77 0 my $operation = $self->{param}->{'op'};
78 0 $self->{operation} = $operation;
79 0 ▶ if ( defined($operation)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $operation and $operation eq "t") 0 0 0
Condition0%0/3
defined $operation and $operation eq "t"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $operation and $operation eq "t"
defined $operation $operation eq "t"
Truth table0%0/3
A and B
A= defined $operationB= $operation eq "t"
ABresult
0X0
100
111
80 and $operation eq 't' )
81 {
82 0 $self->{'message'} = $self->{msg}{1};
83 0 $self->{'error'} = 1;
84 }
85 }
86 ##------------------------------------------------------------------
87 ## method controlSyntax
88 ## This method looks at param cgi 'identifant' and 'secret'
89 ##
90 ##------------------------------------------------------------------
91 0 ▶sub __controlSyntax {
Subroutine __controlSyntax: not called CC=9 SCAR=45.0
92 0 my $self = shift;
93 0 my $user = $self->{param}->{'identifiant'};
94 0 $self->{'user'} = $user;
95 0 my $password = $self->{param}->{'secret'};
96 0 $self->{'password'} = $password;
97 0 ▶ if ( defined($user)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user or defined $password) 0 0 0
Condition0%0/3
defined $user or defined $password
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $user or defined $password
defined $user defined $password
Truth table0%0/3
A or B
A= defined $userB= defined $password
ABresult
1X1
011
000
98 or defined($password) )
99 {
100 0 ▶ if ( !defined($user)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $user or $user eq "" or not defined $password or $password eq "") 0 0 0
Condition0%0/9
not defined $user or $user eq "" or not defined $password or $password eq ""
l!l&&r!l&&!r
000
not defined $user or $user eq "" or not defined $password
l!l&&r!l&&!r
000
not defined $user or $user eq ""
l!l&&r!l&&!r
000
MC/DC0%0/4
not defined $user or $user eq "" or not defined $password or $password eq ""
not defined $user $user eq "" not defined $password $password eq ""
Truth table0%0/5
not(A) or B or not(C) or D
A= not defined $userB= $user eq ""C= not defined $passwordD= $password eq ""
ABCDresult
1XXX1
01XX1
001X1
00011
00000
101 or $user eq ''
102 or !defined($password)
103 or $password eq '' )
104 {
105 0 $self->{'message'} = $self->{msg}{2};
106 0 $self->{'error'} = 2;
107 }
108  
109 }
110 0 ▶ if ( !defined($user)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $user || defined $password) 0 0 0
Condition0%0/3
defined $user || defined $password
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $user || defined $password
defined $user defined $password
Truth table0%0/3
A || B
A= defined $userB= defined $password
ABresult
1X1
011
000
111 and !defined($password) )
112 { # empty form
113 0 $self->{'message'} = '';
114 0 $self->{'error'} = 9;
115 }
116  
117 }
118 ##---------------------------------------------------------------------------
119 ## Connection ldap on server and port ldap
120 ##---------------------------------------------------------------------------
121  
122 0 ▶sub __contactServer {
Subroutine __contactServer: not called CC=3 SCAR=24.8
123 0 my $self = shift;
124 0 ▶ unless ( $self->{ldap} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ldap"}) 0 0 0
125 my $ldap = Net::LDAP->new(
126 $self->{server},
127 port => $self->{port},
128 0 ▶ onerror => undef,
Branch: 1 branch
BranchTrueFalseTotal
my $ldap = "Net::LDAP"->new($self->{"server"}, "port", $self->{"port"}, "onerror", undef) or die 'Net::LDAP->new: ' . $@ 0 0 0
129 )
130 or die( 'Net::LDAP->new: ' . $@ );
131 0 $self->{ldap} = $ldap;
132 }
133 }
134  
135 0 ▶sub func_bind {
Subroutine func_bind: not called CC=4 SCAR=30.0
Pod undocumented
136 0 my $ldap = shift;
137 0 my $dn = shift;
138 0 my $password = shift;
139 0 my $mesg;
140 0 ▶ if ( $dn and $password ) { #named bind
Branch: 1 branch
BranchTrueFalseTotal
if ($dn and $password) { } 0 0 0
Condition0%0/3
$dn and $password
!ll&&!rl&&r
000
MC/DC0%0/2
$dn and $password
$dn $password
Truth table0%0/3
A and B
A= $dnB= $password
ABresult
0X0
100
111
141 0 $mesg = $ldap->bind( $dn, password => $password );
142 }
143 else { # anonymous bind
144 0 $mesg = $ldap->bind();
145 }
146  
147 0 my $me = $mesg->code();
148 0 ▶ if ( $mesg->code() != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
149 0 $ldap = undef;
150 0 return ("wrong password");
151 }
152 0 return;
153 }
154  
155 ##---------------------------------------------------------------------------
156 ## formate filter
157 ##---------------------------------------------------------------------------
158 0 ▶sub __Filter {
Subroutine __Filter: not called CC=1 SCAR=6.9
159 0 my $self = shift;
160 0 my $user = $self->{user};
161 0 my $filtre = "uid=$user";
162 0 $self->{filter} = $filtre;
163 }
164 ##---------------------------------------------------------------------------
165 ## Connection on server LDAP with manager credential
166 ## in order to extract user infos
167 ##---------------------------------------------------------------------------
168  
169 0 ▶sub __bind {
Subroutine __bind: not called CC=2 SCAR=17.9
170 0 my $self = shift;
171 ##---------------------------------------------------------------------------
172 ## Authentification
173 ##---------------------------------------------------------------------------
174  
175 0 my $d = $self->{ldap};
176 0 my $p = $self->{DnManager};
177 0 my $r = $self->{passwdManager};
178  
179 my $mesg =
180 0 &func_bind( $self->{ldap}, $self->{DnManager}, $self->{passwordManager} );
181  
182 0 ▶ if ($mesg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg) 0 0 0
183 0 $self->{'message'} = $self->{sg}{3};
184 0 $self->{'error'} = 3;
185  
186 }
187 }
188  
189 0 ▶sub __ldapsearch {
Subroutine __ldapsearch: not called CC=3 SCAR=24.8
190 0 my $self = shift;
191 0 my $ldap = $self->{ldap};
192 0 my $filter = $self->{filter};
193 0 my $base = $self->{branch};
194  
195 0 my $mesg = $ldap->search(
196 base => $base,
197 scope => 'sub',
198 filter => $filter,
199 );
200 0 ▶ die $mesg->error() if ( $mesg->code() != 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code != 0 0 0 0
201 0 my $retour = $mesg->entry(0);
202 0 my $identifiantCopy = $self->{user};
203 0 ▶ if ( !defined($retour) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $retour) 0 0 0
204 0 $self->{'message'} = "$identifiantCopy :" . $self->{msg}{4};
205 0 $self->{'error'} = 4;
206 0 return;
207 }
208 0 $self->{entry} = $retour;
209 0 return;
210 }
211 ##==============================================================================
212 ## function _session
213 ##
214 ##==============================================================================
215  
216 0 ▶sub __session {
Subroutine __session: not called CC=1 SCAR=6.9
217 0 my $self = shift;
218 0 my %session;
219 0 my $entry = $self->{entry};
220 0 $session{dn} = $entry->dn();
221 0 $self->{dn} = $entry->dn();
222 0 $session{uid} = $entry->get_value('uid');
223 0 $session{cn} = $entry->get_value('cn');
224 0 $session{personaltitle} = $entry->get_value('personaltitle');
225 0 $session{mail} = $entry->get_value('mail');
226 0 $session{title} = $entry->get_value('title');
227 0 $self->{infosession} = \%session;
228  
229 }
230 ##==============================================================================
231 ## Function unbind
232 ## do unbind;
233 ##==============================================================================
234 0 ▶sub __unbind {
Subroutine __unbind: not called CC=2 SCAR=17.9
235 0 my $self = shift;
236 0 ▶ $self->{ldap}->unbind if $self->{ldap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ldap"} 0 0 0
237 }
238 ##---------------------------------------------------------------------------
239 ## Credential against nt domain
240 ##---------------------------------------------------------------------------
241 0 ▶sub __credentials {
Subroutine __credentials: not called CC=3 SCAR=24.8
242 0 my $self = shift;
243 0 my $login = $self->{user};
244 0 my $passwd = $self->{password};
245 0 my $BDC = $self->{BDC};
246 0 my $BDC_secours = $self->{BDC_secours};
247 0 my $ntdomain = $self->{ntDomain};
248  
249 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (Authen::Smb::authen($login, $passwd, $BDC, $BDC_secours || $BDC, $ntdomain) == 0) 0 0 0
Condition0%0/3
$BDC_secours || $BDC
l!l&&r!l&&!r
000
MC/DC0%0/2
$BDC_secours || $BDC
$BDC_secours $BDC
Truth table0%0/3
A || B
A= $BDC_secoursB= $BDC
ABresult
1X1
011
000
250 Authen::Smb::authen( $login, $passwd, $BDC, $BDC_secours || $BDC,
251 $ntdomain ) == 0
252 )
253 {
254  
255 0 $self->{'message'} = $self->{msg}{5};
256 0 $self->{'error'} = 5;
257 }
258 }
259  
260 0 ▶sub message {
Subroutine message: not called CC=1 SCAR=6.9
Pod documented
261 0 my $self = shift;
262 0 return ( $self->{message} );
263 }
264  
265 0 ▶sub infoSession {
Subroutine infoSession: not called CC=1 SCAR=6.9
Pod documented
266 0 my $self = shift;
267 0 return ( $self->{infosession} );
268 }
269  
270 0 ▶sub getAllRedirection {
Subroutine getAllRedirection: not called CC=1 SCAR=6.9
Pod undocumented
271 0 my $self = shift;
272 0 return ( $self->{urlc}, $self->{urldc} );
273 }
274  
275 0 ▶sub getRedirection {
Subroutine getRedirection: not called CC=1 SCAR=6.9
Pod documented
276 0 my $self = shift;
277 0 return ( $self->{urldc} );
278 }
279  
280 0 ▶sub user {
Subroutine user: not called CC=1 SCAR=6.9
Pod undocumented
281 0 my $self = shift;
282 0 return ( $self->{user} );
283 }
284  
285 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
286 0 my $self = shift;
287 0 return ( $self->{error} );
288 }
289  
290 0 ▶sub process {
Subroutine process: not called CC=6 SCAR=37.4
Pod documented
291 0 my $self = shift;
292 0 my %args = @_;
293 0 foreach ( keys %args ) {
294 0 $self->{$_} = $args{$_};
295 }
296 ##------------------------------------------------------------------
297 ## method process
298 ## This method step after step calls methods for dealing the
299 ## connection
300 ## step 0 : setting configuration
301 ## step 1 : manage the source of request
302 ## step 2 : manage timeout
303 ## step 3 : control the input form of user and password
304 ## step 4 : formate the user id if needing
305 ## step 5 : build the filter for the search
306 ## step 6 : build subtree for the search ldap
307 ## step 7 : make socket upon ldap server
308 ## step 8 : bind operation
309 ## step 9 : make search
310 ## step 10 : confection of %session from ldap infos
311 ## step 11 : unbind
312 ## step 12 : validing user's credentials upon ntdomain
313 ##------------------------------------------------------------------
314 0 &{ $self->{controlUrlOrigin} }($self); # no error avaiable in this step
315 0 &{ $self->{controlTimeOut} }($self);
316 0 ▶ return ($self) if $self->{'error'}; ## it's not necessary to go next.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error"} 0 0 0
317 0 &{ $self->{controlSyntax} }($self);
318 0 ▶ return ($self) if $self->{'error'}; ## it's not necessary to go next.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error"} 0 0 0
319 0 &{ $self->{formateUser} }($self); # no error avaiable in this step
320 0 &{ $self->{formateFilter} }($self); # no error avaiable in this step
321 0 &{ $self->{formateBaseLDAP} }($self); # no error avaiable in this step
322 0 &{ $self->{contactServer} }($self)
323 ; # can die if the server if unreachable: critical error
324 0 &{ $self->{bind} }($self);
325 0 ▶ return ($self) if $self->{'error'}; ## it's not necessary to go next.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error"} 0 0 0
326 0 &{ $self->{search} }($self);
327  
328 0 ▶ if ( $self->{'error'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
329 ## it's not necessary to go next.
330 0 &{ $self->{unbind} }($self);
331 0 return ($self);
332 }
333 0 &{ $self->{setSessionInfo} }($self); # no error avaiable in this step
334 0 &{ $self->{credentials} }($self);
335 0 &{ $self->{unbind} }($self); # no error avaiable in this step
336 0 return ($self);
337 }
338  
339 1 1;
340 __END__
↑ Summary