blib/lib/Lemonldap/NG/Portal/Main/Plugins.pm

filter: Statementstmt 98.4% 63 / 64 Branchbran 81.2% 26 / 32 Conditioncond 75.0% 27 / 36 MC/DCmcdc 50.0% 10 / 20 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 81.8% 131 / 160 CC 32 SCAR 26.4
CC
32
Cov
88%
enabledPlugins
20.3
enabledServices
8.1
checkConf
7.0
CRAP 14.0
« blib/lib/Lemonldap/NG/Portal/Auth/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/PAM.pm »
1 # This module loads known enabled plugins. To add custom modules, just add them
2 # into "plugins" list in lemonldap-ng.ini, section "portal"
3 package Lemonldap::NG::Portal::Main::Plugins;
4  
5 454 our $VERSION = '2.23.0';
6  
7 package Lemonldap::NG::Portal::Main;
8  
9 454 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 454 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Plugins enabled by a simple boolean value (ordered list)
13 #
14 # Developers: 2FA must be loaded before Notifications
15 # Developers: GlobalLogout must be the last loaded plugin
16 # Developers: Notifications must be loaded before PublicNotifications
17 454 our @pList = (
18 portalDisplayResetPassword => '::Plugins::MailPasswordReset',
19 portalDisplayCertificateResetByMail => '::Plugins::CertificateResetByMail',
20 cda => '::Plugins::CDA',
21 notification => '::Plugins::Notifications',
22 publicNotifications => '::Plugins::PublicNotifications',
23 rememberAuthChoiceRule => '::Plugins::RememberAuthChoice',
24 stayConnected => '::Plugins::StayConnected',
25 portalCheckLogins => '::Plugins::History',
26 bruteForceProtection => '::Plugins::BruteForceProtection',
27 grantSessionRules => '::Plugins::GrantSession',
28 upgradeSession => '::Plugins::Upgrade',
29 autoSigninRules => '::Plugins::AutoSignin',
30 checkState => '::Plugins::CheckState',
31 webCronSecret => '::Plugins::WebCron',
32 portalForceAuthn => '::Plugins::ForceAuthn',
33 checkUser => '::Plugins::CheckUser',
34 checkDevOps => '::Plugins::CheckDevOps',
35 contextSwitchingRule => '::Plugins::ContextSwitching',
36 decryptValueRule => '::Plugins::DecryptValue',
37 findUser => '::Plugins::FindUser',
38 newLocationWarning => '::Plugins::NewLocationWarning',
39 passwordPolicyActivation => '::Plugins::BasePasswordPolicy',
40 checkHIBP => '::Plugins::CheckHIBP',
41 checkEntropy => '::Plugins::CheckEntropy',
42 initializePasswordReset => '::Plugins::InitializePasswordReset',
43 oidcOfflineTokens => '::Plugins::OIDC::OfflineTokens',
44 oidcServiceAllowDynamicRegistration =>
45 '::Plugins::OIDC::DynamicRegistration',
46 adaptativeAuthenticationLevelRules =>
47 '::Plugins::AdaptativeAuthenticationLevel',
48 refreshSessions => '::Plugins::Refresh',
49 externalMenu => '::Plugins::ExternalMenu',
50 crowdsecAgent => '::Plugins::CrowdSecAgent',
51 crowdsec => '::Plugins::CrowdSec',
52 locationDetect => '::Plugins::LocationDetect',
53 globalLogoutRule => '::Plugins::GlobalLogout',
54 samlFederationFiles => '::Plugins::SamlFederation',
55 adminLogoutServerSecret => '::Plugins::AdminLogout',
56 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsAllowNativeSso' =>
57 '::Plugins::OIDC::NativeSso',
58 'or::oidcOPMetaDataOptions/*/oidcOPMetaDataOptionsRequirePkce' =>
59 '::Plugins::OIDC::AuthPkce',
60 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsTokenXAuthorizedRP' =>
61 '::Plugins::OIDC::InternalTokenExchange',
62 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsAllowPasswordGrant' =>
63 '::Plugins::OIDC::PasswordGrant',
64 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsAllowClientCredentialsGrant'
65 => '::Plugins::OIDC::ClientCredentialsGrant',
66 );
67  
68 ##@method list enabledPlugins
69 #
70 #@return list of enabled plugins
71 #
72 # List can be:
73 # * a plugin name
74 # * an array ref containing:
75 # - the property into which the plugin has to be linked
76 # - the plugin name
77 #
78 # If plugin name starts with '::', the prefix Lemonldap::NG::Portal will be
79 # added
80  
81 671 ▶sub enabledServices {
Subroutine enabledServices: called CC=8 SCAR=21.0
Pod undocumented
82 671 my ($self) = @_;
83 671 my $conf = $self->conf;
84 671 my @res;
85  
86 # Second factor
87 671 push @res, [ secondFactor => $self->conf->{'sfEngine'} ];
88  
89 # Portal menu
90 671 push @res, [ menu => "::Main::Menu" ];
91  
92 # Trusted browser
93 671 ▶ if ( $self->conf->{trustedBrowserRule} or $self->conf->{stayConnected} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}) 8 663 671
Condition100%3/3
$self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}
l!l&&r!l&&!r
17663
MC/DC100%2/2
$self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}
$self->conf->{"trustedBrowserRule"} $self->conf->{"stayConnected"}
Truth table100%3/3
A or B
A= $self->conf->{"trustedBrowserRule"}B= $self->conf->{"stayConnected"}
ABresult
1X1
011
000
94 my $module =
95 8 ▶ $self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser';
Condition50%1/2
$self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser'
l!l
08
MC/DC0%0/1
$self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser'
$self->conf->{'trustedBrowserEngine'}
Truth table50%1/2
A
A= $self->conf->{'trustedBrowserEngine'}
Aresult
11
00
96 8 $self->logger->debug("$module needed");
97 8 push @res, [ trustedBrowser => $module ];
98 }
99  
100 # Captcha
101 671 ▶ if ( $self->conf->{captcha_mail_enabled}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}) 671 0 671
Condition66%4/6
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}
l!l&&r!l&&!r
66920
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"}
l!l&&r!l&&!r
66902
MC/DC0%0/3
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}
$self->conf->{"captcha_mail_enabled"} $self->conf->{"captcha_login_enabled"} $self->conf->{"captcha_register_enabled"}
Truth table50%2/4
A or B or C
A= $self->conf->{"captcha_mail_enabled"}B= $self->conf->{"captcha_login_enabled"}C= $self->conf->{"captcha_register_enabled"}
ABCresult
1XX1
01X1
0011
0000
102 || $self->conf->{captcha_login_enabled}
103 || $self->conf->{captcha_register_enabled} )
104 {
105 671 ▶ my $module = $self->conf->{'captcha'} || '::Captcha::SecurityImage';
Condition100%2/2
$self->conf->{'captcha'} || '::Captcha::SecurityImage'
l!l
3668
MC/DC100%1/1
$self->conf->{'captcha'} || '::Captcha::SecurityImage'
$self->conf->{'captcha'}
Truth table100%2/2
A
A= $self->conf->{'captcha'}
Aresult
11
00
106 671 $self->logger->debug("$module needed");
107 671 push @res, [ captcha => $module ];
108 }
109 671 return @res;
110 }
111  
112 331 ▶sub enabledPlugins {
Subroutine enabledPlugins: called CC=19 SCAR=30.1
Pod undocumented
113 331 my ($self) = @_;
114 331 my $conf = $self->conf;
115 331 my @res;
116  
117 # Search for Issuer* modules enabled
118 331 foreach my $key (qw(SAML OpenID CAS OpenIDConnect Get JitsiMeetTokens)) {
119 1986 ▶ if ( $conf->{"issuerDB${key}Activation"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$conf{"issuerDB${key}Activation"}) 112 1874 1986
120 112 $self->logger->debug("Issuer${key} enabled");
121 112 push @res, "::Issuer::$key";
122 }
123 }
124  
125 # Load single session
126 push @res, '::Plugins::SingleSession'
127 if ( $conf->{singleSession}
128 or $conf->{singleIP}
129 or $conf->{singleUserByIP}
130 331 ▶ or $conf->{notifyOther} );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"} 13 318 331
Condition88%8/9
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"}
l!l&&r!l&&!r
130318
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"}
l!l&&r!l&&!r
112318
$conf->{"singleSession"} or $conf->{"singleIP"}
l!l&&r!l&&!r
47320
MC/DC75%3/4
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"}
$conf->{"singleSession"} $conf->{"singleIP"} $conf->{"singleUserByIP"} $conf->{"notifyOther"}
Truth table80%4/5
A or B or C or D
A= $conf->{"singleSession"}B= $conf->{"singleIP"}C= $conf->{"singleUserByIP"}D= $conf->{"notifyOther"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
131  
132 # Load static plugin list
133 331 ▶ for ( my $i = 0 ; $i < @pList ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @Lemonldap::NG::Portal::Main::pList) 13571 331 13902
134 13571 my $pluginConf;
135 13571 ▶ if ( $pList[$i] =~ /^(.*?)::(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lemonldap::NG::Portal::Main::pList[$i] =~ /^(.*?)::(.*)$/) { } 1655 11916 13571
136 1655 $pluginConf = checkConf( $conf, $2, $1 );
137 }
138 else {
139 11916 my $c = $conf->{ $pList[$i] };
140 11916 ▶ $pluginConf = ( ref($c) && ref($c) eq 'HASH' ? scalar(%$c) : $c );
Branch: 1 branch
BranchTrueFalseTotal
ref $c && ref $c eq 'HASH' ? : 331 11585 11916
Condition66%2/3
ref $c and ref $c eq "HASH"
!ll&&!rl&&r
115850331
MC/DC50%1/2
ref $c and ref $c eq "HASH"
ref $c ref $c eq "HASH"
Truth table66%2/3
A and B
A= ref $cB= ref $c eq "HASH"
ABresult
0X0
100
111
141 }
142 13571 ▶ push @res, $pList[ $i + 1 ] if $pluginConf;
Branch: 1 branch
BranchTrueFalseTotal
if $pluginConf 1016 12555 13571
143 }
144  
145 # Check if SOAP is enabled
146 push @res, '::Plugins::SOAPServer'
147 if ( $conf->{soapSessionServer}
148 331 ▶ or $conf->{soapConfigServer} );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"soapSessionServer"} or $conf->{"soapConfigServer"} 0 331 331
Condition33%1/3
$conf->{"soapSessionServer"} or $conf->{"soapConfigServer"}
l!l&&r!l&&!r
00331
MC/DC0%0/2
$conf->{"soapSessionServer"} or $conf->{"soapConfigServer"}
$conf->{"soapSessionServer"} $conf->{"soapConfigServer"}
Truth table33%1/3
A or B
A= $conf->{"soapSessionServer"}B= $conf->{"soapConfigServer"}
ABresult
1X1
011
000
149  
150 # Add REST (check is done by plugin itself)
151 331 push @res, '::Plugins::RESTServer';
152  
153 # Check if password is enabled
154 331 ▶ if ( my $p = $conf->{passwordDB} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $conf->{"passwordDB"}) 331 0 331
155 331 push @res, "::Password::$p";
156 }
157  
158 # Check if register is enabled
159 push @res, '::Plugins::Register'
160 331 ▶ if ( $conf->{registerDB} and $conf->{registerDB} ne 'Null' );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"registerDB"} and $conf->{"registerDB"} ne "Null" 0 331 331
Condition33%1/3
$conf->{"registerDB"} and $conf->{"registerDB"} ne "Null"
!ll&&!rl&&r
03310
MC/DC0%0/2
$conf->{"registerDB"} and $conf->{"registerDB"} ne "Null"
$conf->{"registerDB"} $conf->{"registerDB"} ne "Null"
Truth table33%1/3
A and B
A= $conf->{"registerDB"}B= $conf->{"registerDB"} ne "Null"
ABresult
0X0
100
111
161  
162 # Check if custom plugins are required
163 331 ▶ if ( $conf->{customPlugins} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"customPlugins"}) 15 316 331
164 15 $self->logger->debug( 'Custom plugins: ' . $conf->{customPlugins} );
165 15 push @res, grep ( /\w+/, split( /[,\s]+/, $conf->{customPlugins} ) );
166 }
167  
168 # Impersonation overwrites req->step and pops 'afterData' EP.
169 # Static and custom 'afterData' plugins will be never launched
170 # if they are loaded after Impersonation.
171 # This plugin must be the last 'afterData' loaded plugin. Fix #2655
172 push @res, '::Plugins::Impersonation'
173 331 ▶ if $conf->{impersonationRule};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"impersonationRule"} 0 331 331
174  
175 331 return @res;
176 }
177  
178 3619 ▶sub checkConf {
Subroutine checkConf: called CC=7 SCAR=19.5
Pod undocumented
179 3619 my ( $conf, $path, $type ) = @_;
180 3619 ▶ if ( $path =~ s#^(.*?)/## ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s[^(.*?)/][]) { } 3310 309 3619
181 3310 my $w = $1;
182 3310 ▶ if ( $w eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq '*') { } 1655 1655 3310
183 1655 my @res;
184 1655 ▶ foreach my $k ( keys %{ $conf || {} } ) {
Condition100%2/2
$conf || {}
l!l
3061349
MC/DC100%1/1
$conf || {}
$conf
Truth table100%2/2
A
A= $conf
Aresult
11
00
185 309 push @res, checkConf( $conf->{$k}, $path, $type );
186 }
187 1655 ▶ if ( $type eq 'or' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'or') { } 1655 0 1655
188 1655 my $res = 0;
189 1655 ▶ map { $res ||= $_ } @res;
Condition100%3/3
$res ||= $_
l!l&&r!l&&!r
108291
MC/DC100%2/2
$res ||= $_
$res $_
Truth table100%3/3
A ||= B
A= $resB= $_
ABresult
1X1
011
000
190 1655 return $res;
191 }
192 0 else { die "Unkown type $type"; }
193 }
194 else {
195 1655 return checkConf( $conf->{$w}, $path, $type );
196 }
197 }
198 else {
199 309 return $conf->{$path};
200 }
201 }
202  
203 454 1;
« blib/lib/Lemonldap/NG/Portal/Auth/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/PAM.pm »