blib/lib/Lemonldap/NG/Portal/Auth/AD.pm

filter: Statementstmt 21.5% 14 / 65 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 4 totaltotal 11.0% 17 / 154 CC 24 SCAR 54.3
CC
24
Cov
12%
authenticate
380.0
stop
12.0
__ANON__
6.0
CRAP 228.0
« blib/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/OpenID.pm »
1 # Auth::AD inherits from Auth::LDAP. It defines some additional configuration
2 # parameters and manage AD password expiration
3  
4 package Lemonldap::NG::Portal::Auth::AD;
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 PE_OK
10 PE_PP_PASSWORD_EXPIRED
11 PE_PP_CHANGE_AFTER_RESET
12 PE_BADCREDENTIALS
13 PE_PP_PASSWORD_EXPIRES_SOON
14 1 );
15  
16 1 our $VERSION = '2.22.0';
17  
18 1 extends 'Lemonldap::NG::Portal::Auth::LDAP';
19  
20 # PROPERTIES
21  
22 has adPwdMaxAge => (
23 is => 'rw',
24 lazy => 1,
25 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 my $conf = $_[0]->{conf};
27 0 ▶ my $res = $conf->{ADPwdMaxAge} || 0;
Condition0%0/2
$conf->{'ADPwdMaxAge'} || 0
l!l
00
MC/DC0%0/1
$conf->{'ADPwdMaxAge'} || 0
$conf->{'ADPwdMaxAge'}
Truth table0%0/2
A
A= $conf->{'ADPwdMaxAge'}
Aresult
11
00
28 0 return $res * 10000000; # padding with '0' to obtain 0.1 micro-seconds
29 }
30 1 );
31  
32 has adPwdExpireWarning => (
33 is => 'rw',
34 lazy => 1,
35 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
36 0 my $conf = $_[0]->{conf};
37 0 ▶ my $res = $conf->{ADPwdExpireWarning} || 0;
Condition0%0/2
$conf->{'ADPwdExpireWarning'} || 0
l!l
00
MC/DC0%0/1
$conf->{'ADPwdExpireWarning'} || 0
$conf->{'ADPwdExpireWarning'}
Truth table0%0/2
A
A= $conf->{'ADPwdExpireWarning'}
Aresult
11
00
38 0 return $res * 10000000; # padding with '0' to obtain 0.1 micro-seconds
39 }
40 1 );
41  
42 # AD timestamp starts from Jan 01 1601 and is defined in 0.1 micro seconds.
43 # This method converts Unix timestamp into AD timestamp.
44 0 ▶sub adTime {
Subroutine adTime: not called CC=1 SCAR=6.9
Pod undocumented
45 0 return ( time + 11644473600 ) * 10000000;
46 }
47  
48 # INITIALIZATION
49 # update LDAP configuration
50 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my ($self) = @_;
52  
53 0 $self->conf->{ldapExportedVars}->{_AD_pwdLastSet} = 'pwdLastSet';
54 $self->conf->{ldapExportedVars}->{_AD_userAccountControl} =
55 0 'userAccountControl';
56 $self->conf->{ldapExportedVars}->{_AD_msDS_UACC} =
57 0 'msDS-User-Account-Control-Computed';
58  
59 0 ▶ if ( $self->adPwdExpireWarning > $self->adPwdMaxAge ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->adPwdExpireWarning > $self->adPwdMaxAge) 0 0 0
60 0 $self->adPwdExpireWarning( $self->adPwdMaxAge );
61 0 $self->logger->warn(
62 "Error: ADPwdExpireWarning > ADPwdMaxAge, this should not happen",
63 );
64 }
65 0 return $self->SUPER::init();
66 }
67  
68 # RUNNING METHODS
69  
70 0 ▶sub authenticate {
Subroutine authenticate: not called CC=19 SCAR=59.4
Pod undocumented
71 0 my ( $self, $req ) = @_;
72 0 my $res = $self->SUPER::authenticate($req);
73  
74 my $pls =
75 0 $self->ldap->getLdapValue( $req->data->{ldapentry}, 'pwdLastSet' );
76 my $computed = $self->ldap->getLdapValue( $req->data->{ldapentry},
77 0 'msDS-User-Account-Control-Computed' );
78 my $_adUac =
79 0 ▶ $self->ldap->getLdapValue( $req->data->{ldapentry}, 'userAccountControl' )
Condition0%0/2
$self->ldap->getLdapValue($req->data->{'ldapentry'}, 'userAccountControl') || 0
l!l
00
MC/DC0%0/1
$self->ldap->getLdapValue($req->data->{'ldapentry'}, 'userAccountControl') || 0
$self->ldap->getLdapValue($req->data->{'ldapentry'}, 'userAccountControl')
Truth table0%0/2
A
A= $self->ldap->getLdapValue($req->data->{'ldapentry'}, 'userAccountControl')
Aresult
11
00
80 || 0;
81  
82 0 ▶ unless ( $res == PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 0) { } 0 0 0
83  
84 # Explicit bad credentials message
85 0 ▶ if ( $req->data->{ldapError}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"ldapError"} and $req->data->{"ldapError"} =~ /LdapErr: .* data ([^,]+),.*/) 0 0 0
Condition0%0/3
$req->data->{"ldapError"} and $req->data->{"ldapError"} =~ /LdapErr: .* data ([^,]+),.*/
!ll&&!rl&&r
000
MC/DC0%0/2
$req->data->{"ldapError"} and $req->data->{"ldapError"} =~ /LdapErr: .* data ([^,]+),.*/
$req->data->{"ldapError"} $req->data->{"ldapError"} =~ /LdapErr: .* data ([^,]+),.*/
Truth table0%0/3
A and B
A= $req->data->{"ldapError"}B= $req->data->{"ldapError"} =~ /LdapErr: .* data ([^,]+),.*/
ABresult
0X0
100
111
86 and $req->data->{ldapError} =~ /LdapErr: .* data ([^,]+),.*/ )
87 {
88 0 ▶ if ( $1 eq '52e' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "52e") 0 0 0
89 0 return PE_BADCREDENTIALS;
90 }
91 }
92  
93 # Check specific AD attributes
94 0 my $mask = 0xf00000; # mask to get the 8 at 6th position
95 0 my $expired_flag =
96 0x800000; # 8 at 6th position for flag UF_PASSWORD_EXPIRED to be set
97 0 ▶ if ( ( $computed & $mask ) == $expired_flag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($computed & $mask) == $expired_flag) 0 0 0
98 0 $self->userLogger->warn("[AD] Password has expired");
99 0 $res = PE_PP_PASSWORD_EXPIRED;
100 }
101  
102 # Password must be changed if pwdLastSet 0
103 0 ▶ if ( defined $pls and $pls == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pls and $pls == 0) 0 0 0
Condition0%0/3
defined $pls and $pls == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pls and $pls == 0
defined $pls $pls == 0
Truth table0%0/3
A and B
A= defined $plsB= $pls == 0
ABresult
0X0
100
111
104 0 $self->userLogger->warn(
105 "[AD] Password reset. User must change his password");
106 0 $res = PE_PP_CHANGE_AFTER_RESET;
107 }
108  
109 }
110 else {
111 0 my $timestamp = $self->adTime;
112  
113 # Compute password expiration time (date)
114 0 ▶ my $_pwdExpire = $pls || $timestamp;
Condition0%0/3
$pls || $timestamp
l!l&&r!l&&!r
000
MC/DC0%0/2
$pls || $timestamp
$pls $timestamp
Truth table0%0/3
A || B
A= $plsB= $timestamp
ABresult
1X1
011
000
115 0 $_pwdExpire += $self->adPwdMaxAge;
116  
117 # computing when the warning message is displayed on portal
118 # (date - delay = date)
119 0 my $_pwdWarning = $_pwdExpire - $self->adPwdExpireWarning;
120  
121 # display warning if account warning time before expiration is
122 # reached and flag "password nevers expires" is not set
123 0 ▶ if ( $timestamp > $_pwdWarning
Branch: 1 branch
BranchTrueFalseTotal
if ($timestamp > $_pwdWarning and $timestamp < $_pwdExpire and ($_adUac & 65536) != 65536) 0 0 0
Condition0%0/6
$timestamp > $_pwdWarning and $timestamp < $_pwdExpire and ($_adUac & 65536) != 65536
!ll&&!rl&&r
000
$timestamp > $_pwdWarning and $timestamp < $_pwdExpire
!ll&&!rl&&r
000
MC/DC0%0/3
$timestamp > $_pwdWarning and $timestamp < $_pwdExpire and ($_adUac & 65536) != 65536
$timestamp > $_pwdWarning $timestamp < $_pwdExpire ($_adUac & 65536) != 65536
Truth table0%0/4
A and B and C
A= $timestamp > $_pwdWarningB= $timestamp < $_pwdExpireC= ($_adUac & 65536) != 65536
ABCresult
0XX0
10X0
1100
1111
124 && $timestamp < $_pwdExpire
125 && ( $_adUac & 0x10000 ) != 0x10000 )
126 {
127  
128 # calculating remaining time before password expiration
129 0 my $remainingTime = $_pwdExpire - $timestamp;
130 0 my $remainingSeconds = int( $remainingTime / 10000000 );
131 0 ▶ if ( $self->{conf}->{ldapForcePasswordChangeExpirationWarning}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'conf'}{'ldapForcePasswordChangeExpirationWarning'} and $remainingSeconds < $self->{'conf'}{'ldapForcePasswordChangeExpirationWarning'}) { } 0 0 0
Condition0%0/3
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} and $remainingSeconds < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} and $remainingSeconds < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} $remainingSeconds < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
Truth table0%0/3
A and B
A= $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}B= $remainingSeconds < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
ABresult
0X0
100
111
132 and $remainingSeconds <
133 $self->{conf}->{ldapForcePasswordChangeExpirationWarning} )
134 {
135 0 $self->logger->debug(
136 "Force password change on expiration warning");
137 0 $res = PE_PP_PASSWORD_EXPIRES_SOON;
138 }
139 else {
140 0 $req->info(
141 $self->loadTemplate(
142 $req,
143 'pwdWillExpire',
144 params => {
145 time => join( ',',
146 $self->ldap->convertSec($remainingSeconds) )
147 }
148 )
149 );
150 }
151 }
152  
153 }
154  
155 # Remember password if password reset needed
156 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 25 or $res == 112 or $res == 22 and $self->conf->{"ldapAllowResetExpiredPassword"}) 0 0 0
Condition0%0/9
$res == 25 or $res == 112 or $res == 22 and $self->conf->{"ldapAllowResetExpiredPassword"}
l!l&&r!l&&!r
000
$res == 25 or $res == 112
l!l&&r!l&&!r
000
$res == 22 and $self->conf->{"ldapAllowResetExpiredPassword"}
!ll&&!rl&&r
000
MC/DC0%0/4
$res == 25 or $res == 112 or $res == 22 and $self->conf->{"ldapAllowResetExpiredPassword"}
$res == 25 $res == 112 $res == 22 $self->conf->{"ldapAllowResetExpiredPassword"}
Truth table0%0/5
A or B or C and D
A= $res == 25B= $res == 112C= $res == 22D= $self->conf->{"ldapAllowResetExpiredPassword"}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
157 $res == PE_PP_CHANGE_AFTER_RESET
158 or $res == PE_PP_PASSWORD_EXPIRES_SOON
159 or ( $res == PE_PP_PASSWORD_EXPIRED
160 and $self->conf->{ldapAllowResetExpiredPassword} )
161 )
162 {
163 0 $req->data->{oldpassword} = $req->data->{password}; # Fix 2377
164 0 $req->data->{noerror} = 1;
165 0 $self->setSecurity($req);
166 }
167  
168 0 return $res;
169 }
170  
171 # Define which error codes will stop Combination process
172 # @param res error code
173 # @return result 1 if stop is needed
174 0 ▶sub stop {
Subroutine stop: not called CC=3 SCAR=24.8
Pod undocumented
175 0 my ( $self, $res ) = @_;
176  
177 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $res == 22 or $res == 25 0 0 0
Condition0%0/3
$res == 22 or $res == 25
l!l&&r!l&&!r
000
MC/DC0%0/2
$res == 22 or $res == 25
$res == 22 $res == 25
Truth table0%0/3
A or B
A= $res == 22B= $res == 25
ABresult
1X1
011
000
178 if ( $res == PE_PP_PASSWORD_EXPIRED
179 or $res == PE_PP_CHANGE_AFTER_RESET );
180 0 return 0;
181 }
182  
183 1 1;
« blib/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/OpenID.pm »