blib/lib/Lemonldap/NG/Portal/Issuer/CAS.pm

filter: Statementstmt 15.6% 75 / 480 Branchbran 7.0% 16 / 226 Conditioncond 7.2% 8 / 111 MC/DCmcdc 5.8% 4 / 68 Subroutinesub 36.3% 12 / 33 Podpod 14.2% 2 / 14 totaltotal 12.5% 117 / 932 CC 162 SCAR 69.3
CC
162
Cov
12%
run
2450.0
_validate_generic
1806.0
proxy
56.0
CRAP 1022.7
« blib/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm »
1 package Lemonldap::NG::Portal::Issuer::CAS;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Lemonldap::NG::Common::FormEncode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 use Lemonldap::NG::Portal::Main::Constants qw(
8 portalConsts
9 URIRE
10 PE_OK
11 PE_INFO
12 PE_ERROR
13 PE_LOGOUT_OK
14 PE_SENDRESPONSE
15 PE_UNKNOWNPARTNER
16 PE_UNAUTHORIZEDURL
17 PE_UNAUTHORIZEDPARTNER
18 PE_BADURL
19 PE_CAS_SERVICE_NOT_ALLOWED
20 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 our $VERSION = '2.22.0';
24  
25 5 extends 'Lemonldap::NG::Portal::Main::Issuer',
26 'Lemonldap::NG::Portal::Lib::CAS';
27  
28 # INITIALIZATION
29  
30 5 ▶use constant beforeAuth => 'storeEnvAndCheckGateway';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use constant sessionKind => 'ICAS';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 ▶use constant hook => { updateSessionId => 'updateCasSecondarySessions', };
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 5 has rule => ( is => 'rw' );
36  
37 sub init {
38 11 ▶ my ($self) = @_;
Subroutine init: called CC=6 SCAR=19.0
Pod undocumented
39  
40 # Parse activation rule
41 11 my $hd = $self->p->HANDLER;
42 11 $self->logger->debug( "CAS rule -> " . $self->conf->{issuerDBCASRule} );
43 my $rule =
44 11 $hd->buildSub( $hd->substitute( $self->conf->{issuerDBCASRule} ) );
45 11 ▶ unless ($rule) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule) 0 11 11
46 0 ▶ my $error = $hd->tsv->{jail}->error || '???';
Condition0%0/2
$hd->tsv->{'jail'}->error || '???'
l!l
00
MC/DC0%0/1
$hd->tsv->{'jail'}->error || '???'
$hd->tsv->{'jail'}->error
Truth table0%0/2
A
A= $hd->tsv->{'jail'}->error
Aresult
11
00
47 0 $self->error("Bad CAS activation rule -> $error");
48 0 return 0;
49 }
50 11 $self->{rule} = $rule;
51  
52 # Launch parents initialization subroutines, then launch IdP and SP lists
53 11 my $res = $self->Lemonldap::NG::Portal::Main::Issuer::init();
54 11 ▶ return 0 unless ( $self->loadApp );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loadApp 0 11 11
55 11 $self->addUnauthRoute(
56 ( $self->path ) => {
57 samlValidate => 'samlValidate',
58 serviceValidate => 'serviceValidate',
59 relayLogout => 'relayLogout',
60 validate => 'validate',
61 logout => 'unauthlogout',
62 proxyValidate => 'proxyValidate',
63 proxy => 'proxy',
64 p3 => {
65 serviceValidate => 'serviceValidate',
66 proxyValidate => 'proxyValidate'
67 }
68 },
69 ['GET']
70 );
71  
72 11 $self->addUnauthRoute(
73 ( $self->path ) => {
74 samlValidate => 'samlValidate',
75 },
76 ['POST']
77 );
78  
79 # Add CAS Services, so we can check service= parameter on logout
80 11 foreach my $casSrv ( keys %{ $self->casAppList } ) {
81 23 for my $serviceUrl (
82 split(
83 /\s+/,
84 $self->casAppList->{$casSrv}->{casAppMetaDataOptionsService}
85 )
86 )
87 {
88 27 push @{ $self->p->{additionalTrustedDomains} }, $serviceUrl;
89 27 $self->logger->debug(
90 "CAS Service $serviceUrl added in trusted domains");
91 }
92 }
93 11 return $res;
94 }
95  
96 # RUNNING METHODS
97  
98 sub storeEnvAndCheckGateway {
99 9 ▶ my ( $self, $req ) = @_;
Subroutine storeEnvAndCheckGateway: called CC=13 SCAR=26.1
Pod undocumented
100 9 ▶ my $service = $self->p->getHiddenFormValue( $req, 'service' )
Condition66%2/3
$self->p->getHiddenFormValue($req, 'service') || $req->param('service')
l!l&&r!l&&!r
072
MC/DC50%1/2
$self->p->getHiddenFormValue($req, 'service') || $req->param('service')
$self->p->getHiddenFormValue($req, 'service') $req->param('service')
Truth table66%2/3
A || B
A= $self->p->getHiddenFormValue($req, 'service')B= $req->param('service')
ABresult
1X1
011
000
101 || $req->param('service');
102 9 ▶ $service = '' if ( $self->p->checkXSSAttackUrldc( 'service', $service ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttackUrldc("service", $service) 0 9 9
103 9 ▶ my $gateway = $self->p->getHiddenFormValue( $req, 'gateway' )
Condition66%2/3
$self->p->getHiddenFormValue($req, 'gateway') || $req->param('gateway')
l!l&&r!l&&!r
045
MC/DC50%1/2
$self->p->getHiddenFormValue($req, 'gateway') || $req->param('gateway')
$self->p->getHiddenFormValue($req, 'gateway') $req->param('gateway')
Truth table66%2/3
A || B
A= $self->p->getHiddenFormValue($req, 'gateway')B= $req->param('gateway')
ABresult
1X1
011
000
104 || $req->param('gateway');
105  
106 9 ▶ if ( $gateway and $gateway eq "true" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gateway and $gateway eq "true") 4 5 9
Condition66%2/3
$gateway and $gateway eq "true"
!ll&&!rl&&r
504
MC/DC50%1/2
$gateway and $gateway eq "true"
$gateway $gateway eq "true"
Truth table66%2/3
A and B
A= $gatewayB= $gateway eq "true"
ABresult
0X0
100
111
107 4 ▶ if ( $self->_gatewayAllowedRedirect( $req, $service ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_gatewayAllowedRedirect($req, $service)) { } 2 2 4
108 2 $self->logger->debug(
109 "Gateway mode requested, redirect without authentication");
110 2 $req->response(
111 [ 302, [ Location => URI->new($service)->as_string ], [] ] );
112 2 for my $s ( $self->ipath, $self->ipath . 'Path' ) {
113 $self->logger->debug("Removing $s from pdata")
114 4 ▶ if delete $req->pdata->{$s};
Branch: 1 branch
BranchTrueFalseTotal
if delete $req->pdata->{$s} 4 0 4
115 }
116  
117 2 return PE_SENDRESPONSE;
118 }
119 else {
120 2 $self->logger->error(
121 "Disallowing redirection to unknown service $service");
122 2 return PE_UNKNOWNPARTNER;
123 }
124 }
125  
126 5 ▶ if ( $service and $service =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service and $service =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]) 3 2 5
Condition66%2/3
$service and $service =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
!ll&&!rl&&r
203
MC/DC50%1/2
$service and $service =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
$service $service =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
Truth table66%2/3
A and B
A= $serviceB= $service =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
ABresult
0X0
100
111
127 3 my $app = $self->getCasApp($service);
128  
129 3 ▶ if ($app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 2 1 3
130 2 $req->env->{llng_cas_app} = $app;
131  
132 # Store target authentication level in pdata
133 2 my $targetAuthnLevel = $self->spLevelRules->{$app}->( $req, {} );
134  
135 2 ▶ $req->pdata->{targetAuthnLevel} = $targetAuthnLevel
Branch: 1 branch
BranchTrueFalseTotal
if $targetAuthnLevel 0 2 2
136 if $targetAuthnLevel;
137  
138 }
139 }
140  
141 5 return PE_OK;
142 }
143  
144 sub _gatewayAllowedRedirect {
145 4 ▶ my ( $self, $req, $service ) = @_;
Subroutine _gatewayAllowedRedirect: called CC=3 SCAR=11.1
146  
147 4 my $app = $self->getCasApp($service);
148 4 my $casAccessControlPolicy = $self->conf->{casAccessControlPolicy};
149  
150 # Redirect is allowed if there is no access control or if
151 # the service is declared in CAS apps
152 4 ▶ if ( $casAccessControlPolicy !~ /^(error|faketicket)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casAccessControlPolicy =~ /^(error|faketicket)$/i) 0 4 4
153 0 return 1;
154 }
155 4 ▶ if ($app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 2 2 4
156 2 return 1;
157 }
158  
159 2 return 0;
160 }
161  
162 # Main method (launched only for authenticated users, see Main/Issuer)
163 sub run {
164 0 ▶ my ( $self, $req, $target ) = @_;
Subroutine run: not called CC=49 SCAR=78.0
Pod documented
165  
166 # Check activation rule
167 0 ▶ unless ( $self->rule->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->rule->($req, $req->sessionInfo)) 0 0 0
168 0 $self->userLogger->error('CAS service not authorized');
169 0 return PE_CAS_SERVICE_NOT_ALLOWED;
170 }
171  
172 # CAS URL
173 0 my $cas_login = 'login';
174 0 my $cas_logout = 'logout';
175 0 my $cas_validate = 'validate';
176 0 my $cas_serviceValidate = 'serviceValidate';
177 0 my $cas_p3_serviceValidate = 'p3/serviceValidate';
178 0 my $cas_proxyValidate = 'proxyValidate';
179 0 my $cas_p3_proxyValidate = 'p3/proxyValidate';
180 0 my $cas_proxy = 'proxy';
181  
182 # Called URL
183 0 my $url = $req->uri();
184  
185 # Session ID
186 0 ▶ my $session_id = $req->{sessionInfo}->{_session_id} || $req->id;
Condition0%0/3
$req->{'sessionInfo'}{'_session_id'} || $req->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{'sessionInfo'}{'_session_id'} || $req->id
$req->{'sessionInfo'}{'_session_id'} $req->id
Truth table0%0/3
A || B
A= $req->{'sessionInfo'}{'_session_id'}B= $req->id
ABresult
1X1
011
000
187  
188 # 1. LOGIN
189 0 ▶ if ( $target eq $cas_login ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_login) 0 0 0
190  
191 0 $self->logger->debug("URL $url detected as an CAS LOGIN URL");
192  
193 0 my $cas_request = {};
194  
195 0 foreach my $param (qw/service renew gateway/) {
196 0 ▶ $cas_request->{$param} =
Condition0%0/3
$self->p->getHiddenFormValue($req, $param) || $req->param($param)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->p->getHiddenFormValue($req, $param) || $req->param($param)
$self->p->getHiddenFormValue($req, $param) $req->param($param)
Truth table0%0/3
A || B
A= $self->p->getHiddenFormValue($req, $param)B= $req->param($param)
ABresult
1X1
011
000
197 $self->p->getHiddenFormValue( $req, $param )
198 || $req->param($param);
199 }
200  
201 0 my $h = $self->p->processHook( $req, 'casGotRequest', $cas_request );
202 0 ▶ return $self->_failLogin(
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 0 0
203 $req,
204 msg => "casGotRequest hook failed",
205 res => $h
206 ) if ( $h != PE_OK );
207  
208 0 my $service = $cas_request->{service};
209 0 ▶ $service = ''
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttackUrldc("service", $service) 0 0 0
210 if ( $self->p->checkXSSAttackUrldc( 'service', $service ) );
211 0 my $renew = $cas_request->{renew};
212 0 my $gateway = $cas_request->{gateway};
213  
214 # If no service defined, exit
215 0 ▶ unless ( defined $service ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $service) 0 0 0
216 0 $self->logger->debug("No service defined in CAS URL");
217 0 return PE_OK;
218 }
219  
220 0 ▶ unless ( $service =~ m#^(https?://[^/]+)(/.*)?$# ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service =~ m[^(https?://[^/]+)(/.*)?$]) 0 0 0
221 0 return $self->_failLogin(
222 $req,
223 msg => "Bad service $service",
224 res => PE_BADURL,
225 );
226 }
227 0 my $app = $self->getCasApp($service);
228  
229 0 my $spAuthnLevel = 0;
230 0 ▶ if ($app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 0 0 0
231 $spAuthnLevel =
232 0 $self->spLevelRules->{$app}->( $req, $req->sessionInfo );
233 }
234  
235 # Renew
236 0 ▶ if ( $renew
Branch: 1 branch
BranchTrueFalseTotal
if ($renew and $renew eq "true" and &CORE::GLOBAL::time() - $req->sessionInfo->{"_lastAuthnUTime"} > $self->conf->{"portalForceAuthnInterval"}) 0 0 0
Condition0%0/6
$renew and $renew eq "true" and &CORE::GLOBAL::time() - $req->sessionInfo->{"_lastAuthnUTime"} > $self->conf->{"portalForceAuthnInterval"}
!ll&&!rl&&r
000
$renew and $renew eq "true"
!ll&&!rl&&r
000
MC/DC0%0/3
$renew and $renew eq "true" and &CORE::GLOBAL::time() - $req->sessionInfo->{"_lastAuthnUTime"} > $self->conf->{"portalForceAuthnInterval"}
$renew $renew eq "true" &CORE::GLOBAL::time() - $req->sessionInfo->{"_lastAuthnUTime"} > $self->conf->{"portalForceAuthnInterval"}
Truth table0%0/4
A and B and C
A= $renewB= $renew eq "true"C= &CORE::GLOBAL::time() - $req->sessionInfo->{"_lastAuthnUTime"} > $self->conf->{"portalForceAuthnInterval"}
ABCresult
0XX0
10X0
1100
1111
237 and $renew eq 'true'
238 and time - $req->sessionInfo->{_lastAuthnUTime} >
239 $self->conf->{portalForceAuthnInterval} )
240 {
241  
242 # Authentication must be replayed
243 0 $self->logger->debug("Authentication renew requested");
244 0 $self->{updateSession} = 1;
245 0 $req->env->{QUERY_STRING} =~ s/renew=true/renew=false/;
246  
247 0 $req->pdata->{targetAuthnLevel} = $spAuthnLevel;
248 0 return $self->reAuth($req);
249 }
250  
251 # Check access on the service
252 0 my $casAccessControlPolicy = $self->conf->{casAccessControlPolicy};
253  
254 0 ▶ if ( $casAccessControlPolicy =~ /^(error|faketicket)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($casAccessControlPolicy =~ /^(error|faketicket)$/i) 0 0 0
255 0 $self->logger->debug(
256 "CAS access control requested on service $service");
257  
258 0 ▶ unless ($app) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app) 0 0 0
259 0 return $self->_failLogin(
260 $req,
261 msg => 'CAS service not configured',
262 res => PE_UNKNOWNPARTNER,
263 );
264 }
265  
266 # Check if we have sufficient auth level
267 my $authenticationLevel =
268 0 ▶ $req->{sessionInfo}->{authenticationLevel} || 0;
Condition0%0/2
$req->{'sessionInfo'}{'authenticationLevel'} || 0
l!l
00
MC/DC0%0/1
$req->{'sessionInfo'}{'authenticationLevel'} || 0
$req->{'sessionInfo'}{'authenticationLevel'}
Truth table0%0/2
A
A= $req->{'sessionInfo'}{'authenticationLevel'}
Aresult
11
00
269 0 ▶ if ( $authenticationLevel < $spAuthnLevel ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authenticationLevel < $spAuthnLevel) 0 0 0
270 0 $self->logger->debug(
271 "Insufficient authentication level for service $app"
272 . " (has: $authenticationLevel, want: $spAuthnLevel)" );
273  
274 # Reauth with sp auth level as target
275 0 $req->pdata->{targetAuthnLevel} = $spAuthnLevel;
276 0 return $self->upgradeAuth($req);
277 }
278  
279 # Check access rule
280 0 ▶ if ( my $rule = $self->spRules->{$app} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rule = $self->spRules->{$app}) 0 0 0
281 0 ▶ if ( $rule->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$rule($req, $req->sessionInfo)) { } 0 0 0
282 0 $self->logger->debug("CAS service $service access allowed");
283 }
284 else {
285 0 return $self->_failLoginRule( $req, $cas_request, $app );
286 }
287 }
288 }
289  
290 # Check last authentication time to decide if
291 # the authentication is recent or not
292 0 my $casRenewFlag = 0;
293 0 ▶ my $last_authn_utime = $req->{sessionInfo}->{_lastAuthnUTime} || 0;
Condition0%0/2
$req->{'sessionInfo'}{'_lastAuthnUTime'} || 0
l!l
00
MC/DC0%0/1
$req->{'sessionInfo'}{'_lastAuthnUTime'} || 0
$req->{'sessionInfo'}{'_lastAuthnUTime'}
Truth table0%0/2
A
A= $req->{'sessionInfo'}{'_lastAuthnUTime'}
Aresult
11
00
294 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&CORE::GLOBAL::time() - $last_authn_utime < $self->conf->{"portalForceAuthnInterval"}) 0 0 0
295 time() - $last_authn_utime <
296 $self->conf->{portalForceAuthnInterval} )
297 {
298 0 $self->logger->debug(
299 "Authentication is recent, will set CAS renew flag to true");
300 0 $casRenewFlag = 1;
301 }
302  
303 # Create a service ticket
304 $self->logger->debug(
305 0 "Create a CAS service ticket for service $service");
306  
307 my $_utime =
308 $self->conf->{casTicketExpiration}
309 ? (
310 time + $self->conf->{casTicketExpiration} - $self->conf->{timeout} )
311 0 ▶ : ( $req->{sessionInfo}->{_utime} || time() );
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'casTicketExpiration'} ? : 0 0 0
Condition0%0/3
$req->{"sessionInfo"}{"_utime"} or &CORE::GLOBAL::time()
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"sessionInfo"}{"_utime"} or &CORE::GLOBAL::time()
$req->{"sessionInfo"}{"_utime"} &CORE::GLOBAL::time()
Truth table0%0/3
A or B
A= $req->{"sessionInfo"}{"_utime"}B= &CORE::GLOBAL::time()
ABresult
1X1
011
000
312  
313 0 my $Sinfos;
314 0 $Sinfos->{type} = 'casService';
315 0 $Sinfos->{service} = $service;
316 0 $Sinfos->{renew} = $casRenewFlag;
317 0 $Sinfos->{_cas_id} = $session_id;
318 0 $Sinfos->{_utime} = $_utime;
319 0 $Sinfos->{_casApp} = $app;
320  
321 0 $h = $self->p->processHook( $req, 'casGenerateServiceTicket',
322 $cas_request, $app, $Sinfos );
323 0 ▶ return $self->_failLogin(
Branch: 2 branches
BranchTrueFalseTotal
if $h != 0 0 0 0
$app ? : 0 0 0
324 $req,
325 msg => 'casGenerateServiceTicket hook failed',
326 res => $h,
327 ( $app ? ( app => $app ) : () ),
328 ) if ( $h != PE_OK );
329  
330 0 my $casServiceSession = $self->getCasSession( undef, $Sinfos );
331  
332 0 ▶ unless ($casServiceSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casServiceSession) 0 0 0
333 0 ▶ return $self->_failLogin(
Branch: 1 branch
BranchTrueFalseTotal
$app ? : 0 0 0
334 $req,
335 msg => "Unable to create CAS session",
336 ( $app ? ( app => $app ) : () ),
337 );
338 }
339  
340 0 my $casServiceSessionID = $casServiceSession->id;
341 0 my $casServiceTicket = "ST-" . $casServiceSessionID;
342  
343 0 $self->logger->debug(
344 "CAS service session $casServiceSessionID created");
345  
346 0 my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
347 0 ▶ $self->auditLog(
Branch: 2 branches
BranchTrueFalseTotal
$app ? : 0 0 0
$app ? : 0 0 0
348 $req,
349 code => "ISSUER_CAS_LOGIN_SUCCESS",
350 ( $app ? ( app => $app ) : () ),
351 service => $service,
352 user => $user,
353 message => (
354 $app
355 ? ("User $user is authorized to access to $app")
356 : ("User $user is redirected to $service")
357 ),
358 );
359  
360 return $self->_redirectUser( $req, $cas_request->{service},
361 0 $casServiceTicket );
362 }
363  
364 # 2. LOGOUT
365 0 ▶ if ( $target eq $cas_logout ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_logout) 0 0 0
366  
367 0 $self->logger->debug("URL $url detected as an CAS LOGOUT URL");
368  
369 # Disable Content-Security-Policy header since logout can be embedded
370 # in a frame
371 0 $req->frame(1);
372  
373 # GET parameters
374 0 my $logout_url = $req->param('url'); # CAS 2.0
375 0 my $logout_service = $req->param('service'); # CAS 3.0
376 0 ▶ $logout_service = ''
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttackUrldc("service", $logout_service) 0 0 0
377 if ( $self->p->checkXSSAttackUrldc( 'service', $logout_service ) );
378  
379 # If we use access control, check that the service URL is trusted
380 0 ▶ if ( $self->conf->{casAccessControlPolicy} =~ /^(error|faketicket)$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"casAccessControlPolicy"} =~ /^(error|faketicket)$/i) 0 0 0
381 {
382 0 ▶ if ( $logout_service
Branch: 1 branch
BranchTrueFalseTotal
if ($logout_service and not $self->p->isTrustedUrl($logout_service)) 0 0 0
Condition0%0/3
$logout_service and not $self->p->isTrustedUrl($logout_service)
!ll&&!rl&&r
000
MC/DC0%0/2
$logout_service and not $self->p->isTrustedUrl($logout_service)
$logout_service not $self->p->isTrustedUrl($logout_service)
Truth table0%0/3
A and not(B)
A= $logout_serviceB= not $self->p->isTrustedUrl($logout_service)
ABresult
0X0
100
111
383 and not $self->p->isTrustedUrl($logout_service) )
384 {
385 0 $self->userLogger->error(
386 "Untrusted service URL $logout_service"
387 . "specified for CAS Logout" );
388 0 return PE_UNAUTHORIZEDURL;
389 }
390 }
391  
392 # Legacy code without logout propagation for CAS 2.0
393 0 ▶ if ($logout_url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logout_url) { } 0 0 0
394 0 my $session = $self->p->getApacheSession($session_id);
395 0 ▶ return PE_LOGOUT_OK unless ($session);
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
396  
397 # This will call Issuer logout methods, incluing our own
398 # TODO: call authLogout and deleteSession instead of duplicating code
399 0 my $res = $self->p->do( $req, [ @{ $self->p->beforeLogout } ] );
400  
401 0 ▶ unless ( $self->p->_deleteSession( $req, $session ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->p->_deleteSession($req, $session)) 0 0 0
402 0 $self->logger->error("Fail to delete session $session_id ");
403 }
404  
405 # Display a link to the provided URL
406 0 $self->logger->debug("Logout URL $logout_url will be displayed");
407  
408 0 $req->info(
409 $self->loadTemplate(
410 $req, 'casBack2Url', params => { url => $logout_url }
411 )
412 );
413 0 $req->data->{activeTimer} = 0;
414  
415 0 delete $req->pdata->{_url};
416 0 return PE_INFO;
417 }
418 else {
419 0 ▶ $req->{issuerNextUrl} = $logout_service if $logout_service;
Branch: 1 branch
BranchTrueFalseTotal
if $logout_service 0 0 0
420 0 $req->data->{nofail} = 1;
421 $req->steps(
422 0 [ @{ $self->p->beforeLogout }, "authLogout", "deleteSession" ]
423 );
424 0 my $res = $self->p->process($req);
425  
426 0 $req->error($res);
427 0 ▶ if ( $res and $res != PE_LOGOUT_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res and $res != 47) 0 0 0
Condition0%0/3
$res and $res != 47
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $res != 47
$res $res != 47
Truth table0%0/3
A and B
A= $resB= $res != 47
ABresult
0X0
100
111
428 0 ▶ if ( $res > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0) 0 0 0
429 0 $self->logger->error(
430 "Logout process returns error code $res");
431 }
432 0 return $res;
433 }
434 0 ▶ if ($logout_service) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logout_service) 0 0 0
435 0 return $self->_redirectUser( $req, $logout_service );
436 }
437  
438 }
439  
440 0 return PE_LOGOUT_OK;
441  
442 }
443  
444 # 3. VALIDATE [CAS 1.0]
445 0 ▶ if ( $target eq $cas_validate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_validate) 0 0 0
446  
447 0 $self->logger->debug("URL $url detected as an CAS VALIDATE URL");
448  
449 # This URL must not be called by authenticated users
450 0 $self->userLogger->info(
451 "CAS VALIDATE URL called by authenticated user, ignore it");
452  
453 0 return PE_OK;
454 }
455  
456 # 4. SERVICE VALIDATE [CAS 2.0]
457 0 ▶ if ( $target eq $cas_serviceValidate
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_serviceValidate or $target eq $cas_p3_serviceValidate) 0 0 0
Condition0%0/3
$target eq $cas_serviceValidate or $target eq $cas_p3_serviceValidate
l!l&&r!l&&!r
000
MC/DC0%0/2
$target eq $cas_serviceValidate or $target eq $cas_p3_serviceValidate
$target eq $cas_serviceValidate $target eq $cas_p3_serviceValidate
Truth table0%0/3
A or B
A= $target eq $cas_serviceValidateB= $target eq $cas_p3_serviceValidate
ABresult
1X1
011
000
458 || $target eq $cas_p3_serviceValidate )
459 {
460  
461 0 $self->logger->debug(
462 "URL $url detected as an CAS SERVICE VALIDATE URL");
463  
464 # This URL must not be called by authenticated users
465 0 $self->userLogger->info(
466 "CAS SERVICE VALIDATE URL called by authenticated user, ignore it");
467  
468 0 return PE_OK;
469 }
470  
471 # 5. PROXY VALIDATE [CAS 2.0]
472 0 ▶ if ( $target eq $cas_proxyValidate || $target eq $cas_p3_proxyValidate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_proxyValidate or $target eq $cas_p3_proxyValidate) 0 0 0
Condition0%0/3
$target eq $cas_proxyValidate or $target eq $cas_p3_proxyValidate
l!l&&r!l&&!r
000
MC/DC0%0/2
$target eq $cas_proxyValidate or $target eq $cas_p3_proxyValidate
$target eq $cas_proxyValidate $target eq $cas_p3_proxyValidate
Truth table0%0/3
A or B
A= $target eq $cas_proxyValidateB= $target eq $cas_p3_proxyValidate
ABresult
1X1
011
000
473  
474 0 $self->logger->debug("URL $url detected as an CAS PROXY VALIDATE URL");
475  
476 # This URL must not be called by authenticated users
477 0 $self->userLogger->info(
478 "CAS PROXY VALIDATE URL called by authenticated user, ignore it");
479  
480 0 return PE_OK;
481 }
482  
483 # 6. PROXY [CAS 2.0]
484 0 ▶ if ( $target eq $cas_proxy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $cas_proxy) 0 0 0
485  
486 0 $self->logger->debug("URL $url detected as an CAS PROXY URL");
487  
488 # This URL must not be called by authenticated users
489 0 $self->userLogger->info(
490 "CAS PROXY URL called by authenticated user, ignore it");
491  
492 0 return PE_OK;
493 }
494  
495 0 return PE_OK;
496 }
497  
498 sub logout {
499 0 ▶ my ( $self, $req ) = @_;
Subroutine logout: not called CC=3 SCAR=24.8
Pod documented
500  
501 # Session ID
502 0 ▶ my $session_id = $req->{sessionInfo}->{_session_id} || $req->id;
Condition0%0/3
$req->{'sessionInfo'}{'_session_id'} || $req->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{'sessionInfo'}{'_session_id'} || $req->id
$req->{'sessionInfo'}{'_session_id'} $req->id
Truth table0%0/3
A || B
A= $req->{'sessionInfo'}{'_session_id'}B= $req->id
ABresult
1X1
011
000
503  
504 # Delete linked CAS sessions
505 0 ▶ $self->deleteCasSecondarySessions($session_id) if ($session_id);
Branch: 1 branch
BranchTrueFalseTotal
if $session_id 0 0 0
506  
507 0 $self->_send_back_channel_LogoutRequests( $req, $req->sessionInfo );
508  
509 0 return PE_OK;
510 }
511  
512 # Direct request from SP to IdP
513 sub validate {
514 0 ▶ my ( $self, $req ) = @_;
Subroutine validate: not called CC=1 SCAR=6.9
Pod undocumented
515 0 $self->logger->debug(
516 'URL ' . $req->uri . ' detected as an CAS VALIDATE URL' );
517  
518 0 return $self->_validate_generic(
519 $req,
520 ticket => scalar( $req->param('ticket') ),
521 service => scalar( $req->param('service') ),
522 renew => scalar( $req->param('renew') ),
523 success => 'returnCasValidateSuccess',
524 failure => '_failValidate1',
525 );
526 }
527  
528 sub proxy {
529 0 ▶ my ( $self, $req ) = @_;
Subroutine proxy: not called CC=7 SCAR=40.3
Pod undocumented
530  
531 0 $self->logger->debug(
532 'URL ' . $req->uri . " detected as an CAS PROXY URL" );
533  
534 # GET parameters
535 0 my $pgt = $req->param('pgt');
536 0 my $targetService = $req->param('targetService');
537  
538 # Required parameters: pgt and targetService
539 0 ▶ unless ( $pgt and $targetService ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pgt and $targetService) 0 0 0
Condition0%0/3
$pgt and $targetService
!ll&&!rl&&r
000
MC/DC0%0/2
$pgt and $targetService
$pgt $targetService
Truth table0%0/3
A and B
A= $pgtB= $targetService
ABresult
0X0
100
111
540 0 $self->logger->error("Pgt and TargetService parameters required");
541 0 $self->returnCasProxyError( $req, 'INVALID_REQUEST',
542 'Missing mandatory parameters (pgt, targetService)' );
543 }
544  
545 $self->logger->debug(
546 0 "Get proxy request with ticket $pgt for service $targetService");
547  
548 # Get CAS session corresponding to ticket
549 0 ▶ unless ( $pgt =~ s/^PGT-// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pgt =~ s/^PGT-//) 0 0 0
550 0 $self->logger->error(
551 "Provided ticket is not a proxy granting ticket (PGT)");
552 0 $self->returnCasProxyError( $req, 'BAD_PGT',
553 'Provided ticket is not a proxy granting ticket' );
554 }
555  
556 0 my $casProxyGrantingSession = $self->getCasSession($pgt);
557  
558 0 ▶ unless ($casProxyGrantingSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casProxyGrantingSession) 0 0 0
559 0 $self->logger->warn("Proxy granting ticket session $pgt not found");
560 0 $self->returnCasProxyError( $req, 'BAD_PGT', 'Ticket not found' );
561 }
562  
563 0 $self->logger->debug("Proxy granting session $pgt found");
564  
565 # Create a proxy ticket
566 0 $self->logger->debug(
567 "Create a CAS proxy ticket for service $targetService");
568  
569 0 my $casProxySession = $self->getCasSession();
570  
571 0 ▶ unless ($casProxySession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casProxySession) 0 0 0
572 0 $self->logger->error("Unable to create CAS proxy session");
573 0 $self->returnCasProxyError( $req, 'INTERNAL_ERROR',
574 'Error in proxy session management' );
575 }
576  
577 my $_utime =
578 $self->conf->{casTicketExpiration}
579 ? ( time + $self->conf->{casTicketExpiration} - $self->conf->{timeout} )
580 0 ▶ : $casProxyGrantingSession->data->{_utime};
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'casTicketExpiration'} ? : 0 0 0
581  
582 0 my $Pinfos;
583 0 $Pinfos->{type} = 'casProxy';
584 0 $Pinfos->{service} = $targetService;
585 0 $Pinfos->{_cas_id} = $casProxyGrantingSession->data->{_cas_id};
586 0 $Pinfos->{_utime} = $_utime;
587 0 $Pinfos->{proxies} = $casProxyGrantingSession->data->{proxies};
588  
589 0 $casProxySession->update($Pinfos);
590  
591 0 my $casProxySessionID = $casProxySession->id;
592 0 my $casProxyTicket = "PT-" . $casProxySessionID;
593  
594 0 $self->logger->debug("CAS proxy session $casProxySessionID created");
595  
596 0 return $self->returnCasProxySuccess( $req, $casProxyTicket );
597 }
598  
599 sub serviceValidate {
600 0 ▶ my ( $self, $req ) = @_;
Subroutine serviceValidate: not called CC=1 SCAR=6.9
Pod undocumented
601  
602 0 $self->logger->debug(
603 'URL ' . $req->uri . " detected as an CAS SERVICE VALIDATE URL" );
604  
605 0 return $self->_validate_generic(
606 $req,
607 service => scalar( $req->param('service') ),
608 ticket => scalar( $req->param('ticket') ),
609 pgtUrl => scalar( $req->param('pgtUrl') ),
610 renew => scalar( $req->param('renew') ),
611 success => 'returnCasServiceValidateSuccess',
612 failure => '_failValidate2',
613 );
614 }
615  
616 sub samlValidate {
617 0 ▶ my ( $self, $req ) = @_;
Subroutine samlValidate: not called CC=1 SCAR=6.9
Pod undocumented
618  
619 0 my $service = $req->query_parameters->{TARGET};
620 0 my $ticket = $self->getServiceTicketFromSamlRequest( $req->content );
621  
622 0 return $self->_validate_generic(
623 $req,
624 service => $service,
625 ticket => $ticket,
626 success => 'returnSamlValidateSuccess',
627 failure => '_failValidateSaml',
628 );
629 }
630  
631 sub proxyValidate {
632 0 ▶ my ( $self, $req ) = @_;
Subroutine proxyValidate: not called CC=1 SCAR=6.9
Pod undocumented
633  
634 0 $self->logger->debug(
635 'URL ' . $req->uri . " detected as an CAS PROXY VALIDATE URL" );
636  
637 0 return $self->_validate_generic(
638 $req,
639 ticketType => "PROXY",
640 service => scalar( $req->param('service') ),
641 ticket => scalar( $req->param('ticket') ),
642 pgtUrl => scalar( $req->param('pgtUrl') ),
643 renew => scalar( $req->param('renew') ),
644 success => 'returnCasServiceValidateSuccess',
645 failure => '_failValidate2',
646 );
647 }
648  
649 # INTERNAL METHODS
650  
651 sub _validate_generic {
652 0 ▶ my ( $self, $req, %params ) = @_;
Subroutine _validate_generic: not called CC=42 SCAR=75.0
653  
654 0 my $service = $params{service};
655 0 my $ticket = $params{ticket};
656 0 ▶ my $renew = $params{renew} // "false";
Condition0%0/2
$params{"renew"} // "false"
l!l
00
MC/DC0%0/1
$params{"renew"} // "false"
$params{"renew"}
Truth table0%0/2
A
A= $params{"renew"}
Aresult
11
00
657 0 my $success = $params{success};
658 0 my $failure = $params{failure};
659 0 my $pgtUrl = $params{pgtUrl};
660 0 ▶ my $urlType = $params{ticketType} // "SERVICE";
Condition0%0/2
$params{"ticketType"} // "SERVICE"
l!l
00
MC/DC0%0/1
$params{"ticketType"} // "SERVICE"
$params{"ticketType"}
Truth table0%0/2
A
A= $params{"ticketType"}
Aresult
11
00
661  
662 # PGTIOU
663 0 my $casProxyGrantingTicketIOU;
664  
665 # Required parameters: service and ticket
666 0 ▶ unless ( $service and $ticket ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service and $ticket) 0 0 0
Condition0%0/3
$service and $ticket
!ll&&!rl&&r
000
MC/DC0%0/2
$service and $ticket
$service $ticket
Truth table0%0/3
A and B
A= $serviceB= $ticket
ABresult
0X0
100
111
667 0 $self->logger->error("Service and Ticket parameters required");
668 0 return $self->$failure(
669 $req,
670 code => 'INVALID_REQUEST',
671 msg => 'Missing mandatory parameters (service, ticket)'
672 );
673 }
674  
675 0 $self->logger->debug( "Get "
676 . lc($urlType)
677 . " validate request with ticket $ticket for service $service" );
678  
679 # Get CAS session corresponding to ticket
680 0 ▶ if ( $urlType eq 'SERVICE' and !( $ticket =~ s/^ST-// ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($urlType eq 'SERVICE' and not $ticket =~ s/^ST-//) { } 0 0 0
elsif ($urlType eq 'PROXY' and not $ticket =~ s/^(P|S)T-//) { } 0 0 0
Condition0%0/3
$urlType eq "SERVICE" and not $ticket =~ s/^ST-//
!ll&&!rl&&r
000
MC/DC0%0/2
$urlType eq "SERVICE" and not $ticket =~ s/^ST-//
$urlType eq "SERVICE" not $ticket =~ s/^ST-//
Truth table0%0/3
A and not(B)
A= $urlType eq "SERVICE"B= not $ticket =~ s/^ST-//
ABresult
0X0
100
111
681 0 $self->logger->error("Provided ticket is not a service ticket (ST)");
682 0 return $self->$failure(
683 $req,
684 code => 'INVALID_TICKET',
685 msg => 'Provided ticket is not a service ticket'
686 );
687 }
688 ▶ elsif ( $urlType eq 'PROXY' and !( $ticket =~ s/^(P|S)T-// ) ) {
Condition0%0/3
$urlType eq "PROXY" and not $ticket =~ s/^(P|S)T-//
!ll&&!rl&&r
000
MC/DC0%0/2
$urlType eq "PROXY" and not $ticket =~ s/^(P|S)T-//
$urlType eq "PROXY" not $ticket =~ s/^(P|S)T-//
Truth table0%0/3
A and not(B)
A= $urlType eq "PROXY"B= not $ticket =~ s/^(P|S)T-//
ABresult
0X0
100
111
689 0 $self->userLogger->error(
690 "Provided ticket is not a service or proxy ticket ($1T)");
691 0 return $self->$failure(
692 $req,
693 code => 'INVALID_TICKET',
694 msg => 'Provided ticket is not a service or proxy ticket'
695 );
696 }
697  
698 0 my $casServiceSession = $self->getCasSession($ticket);
699  
700 0 ▶ unless ($casServiceSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casServiceSession) 0 0 0
701 0 $self->logger->warn("$urlType ticket session $ticket not found");
702 0 return $self->$failure(
703 $req,
704 code => 'INVALID_TICKET',
705 msg => 'Ticket not found'
706 );
707 }
708 0 $self->deleteCasSession($casServiceSession);
709  
710 # Make sure the token is still valid, we already compensated for
711 # different TTLs when storing _utime
712 0 ▶ if ( $casServiceSession->{data}->{_utime} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($casServiceSession->{"data"}{"_utime"}) 0 0 0
713 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&CORE::GLOBAL::time() > $casServiceSession->{"data"}{"_utime"} + $self->conf->{"timeout"}) 0 0 0
714 time >
715 ( $casServiceSession->{data}->{_utime} + $self->conf->{timeout} ) )
716 {
717 0 $self->logger->info("$urlType ticket session $ticket has expired");
718 0 return $self->$failure(
719 $req,
720 code => 'INVALID_TICKET',
721 msg => 'Ticket expired'
722 );
723 }
724 }
725  
726 0 my $app = $casServiceSession->data->{_casApp};
727  
728 0 $self->logger->debug("$urlType ticket session $ticket found");
729  
730 0 my $service1_uri = URI->new($service);
731 0 my $service2_uri = URI->new( $casServiceSession->data->{service} );
732  
733 # Check service
734 0 ▶ unless ( $service1_uri->eq($service2_uri) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service1_uri->eq($service2_uri)) { } 0 0 0
735  
736 # Tolerate that relative URI are the same
737 0 ▶ if ( $service1_uri->rel($service2_uri) eq "./"
Branch: 1 branch
BranchTrueFalseTotal
if ($service1_uri->rel($service2_uri) eq './' or $service2_uri->rel($service1_uri) eq './') { } 0 0 0
Condition0%0/3
$service1_uri->rel($service2_uri) eq "./" or $service2_uri->rel($service1_uri) eq "./"
l!l&&r!l&&!r
000
MC/DC0%0/2
$service1_uri->rel($service2_uri) eq "./" or $service2_uri->rel($service1_uri) eq "./"
$service1_uri->rel($service2_uri) eq "./" $service2_uri->rel($service1_uri) eq "./"
Truth table0%0/3
A or B
A= $service1_uri->rel($service2_uri) eq "./"B= $service2_uri->rel($service1_uri) eq "./"
ABresult
1X1
011
000
738 or $service2_uri->rel($service1_uri) eq "./" )
739 {
740 0 $self->logger->notice( "Submitted service $service1_uri"
741 . " does not exactly match initial service "
742 . $service2_uri
743 . ' but difference is tolerated.' );
744 }
745 else {
746 $self->userLogger->error(
747 "Submitted service $service does not match initial service "
748 0 . $casServiceSession->data->{service} );
749 0 $self->deleteCasSession($casServiceSession);
750 0 return $self->_failValidate2(
751 $req,
752 app => $app,
753 code => 'INVALID_SERVICE',
754 msg => 'Submitted service does not match initial service'
755 );
756 }
757 }
758 else {
759 0 $self->logger->debug(
760 "Submitted service $service match initial service");
761 }
762  
763 # Check renew
764 0 ▶ if ( $renew and $renew eq 'true' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($renew and $renew eq "true") 0 0 0
Condition0%0/3
$renew and $renew eq "true"
!ll&&!rl&&r
000
MC/DC0%0/2
$renew and $renew eq "true"
$renew $renew eq "true"
Truth table0%0/3
A and B
A= $renewB= $renew eq "true"
ABresult
0X0
100
111
765  
766 # We should check the ST was delivered with primary credentials
767 0 $self->logger->debug("Renew flag detected ");
768  
769 0 ▶ unless ( $casServiceSession->data->{renew} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($casServiceSession->data->{"renew"}) 0 0 0
770 0 $self->logger->error( "Authentication renew requested,"
771 . " but not done in former authentication process" );
772 0 return $self->$failure(
773 $req,
774 app => $app,
775 code => 'INVALID_TICKET',
776 msg => 'Authentication renew requested,'
777 . ' but not done in former authentication process'
778 );
779 }
780  
781 }
782  
783 # Proxies (for PROXY VALIDATE only)
784 0 my $proxies = $casServiceSession->data->{proxies};
785  
786 # Proxy granting ticket
787 0 ▶ if ($pgtUrl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pgtUrl) 0 0 0
788  
789 0 my $allow_proxy = 1;
790 0 ▶ if ($app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 0 0 0
791 $allow_proxy =
792 0 ▶ $self->casAppList->{$app}->{casAppMetaDataOptionsAllowProxy} // 1;
Condition0%0/2
$self->casAppList->{$app}{"casAppMetaDataOptionsAllowProxy"} // 1
l!l
00
MC/DC0%0/1
$self->casAppList->{$app}{"casAppMetaDataOptionsAllowProxy"} // 1
$self->casAppList->{$app}{"casAppMetaDataOptionsAllowProxy"}
Truth table0%0/2
A
A= $self->casAppList->{$app}{"casAppMetaDataOptionsAllowProxy"}
Aresult
11
00
793 }
794 0 ▶ if ( !$allow_proxy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_proxy) 0 0 0
795 0 return $self->$failure(
796 $req,
797 app => $app,
798 code => 'UNAUTHORIZED_SERVICE_PROXY',
799 msg => 'CAS proxy is not allowed'
800 );
801 }
802  
803 # Create a proxy granting ticket
804 $self->logger->debug(
805 0 "Create a CAS proxy granting ticket for service $service");
806  
807 0 my $PGinfos;
808  
809 # PGT session
810 0 $PGinfos->{type} = 'casProxyGranting';
811 0 $PGinfos->{service} = $service;
812 0 $PGinfos->{_cas_id} = $casServiceSession->data->{_cas_id};
813 0 $PGinfos->{_utime} = time;
814 0 $PGinfos->{_casApp} = $app;
815  
816 # Trace proxies
817 $PGinfos->{proxies} = (
818 $proxies
819 0 ▶ ? $proxies . $self->conf->{multiValuesSeparator} . $pgtUrl
Branch: 1 branch
BranchTrueFalseTotal
$proxies ? : 0 0 0
820 : $pgtUrl
821 );
822  
823 0 my $casProxyGrantingSession = $self->getCasSession( undef, $PGinfos );
824  
825 0 ▶ if ($casProxyGrantingSession) {
Branch: 1 branch
BranchTrueFalseTotal
if ($casProxyGrantingSession) { } 0 0 0
826  
827 0 my $casProxyGrantingSessionID = $casProxyGrantingSession->id;
828 0 my $casProxyGrantingTicket = "PGT-" . $casProxyGrantingSessionID;
829  
830 0 $self->logger->debug(
831 "CAS proxy granting session $casProxyGrantingSessionID created"
832 );
833  
834 # Generate the proxy granting ticket IOU
835 0 my $tmpCasSession = $self->getCasSession();
836  
837 0 ▶ if ($tmpCasSession) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpCasSession) 0 0 0
838  
839 0 $casProxyGrantingTicketIOU = "PGTIOU-" . $tmpCasSession->id;
840 0 $self->deleteCasSession($tmpCasSession);
841 0 $self->logger->debug( "Generate proxy granting ticket IOU"
842 . $casProxyGrantingTicketIOU );
843  
844 # Request pgtUrl
845 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->callPgtUrl($pgtUrl, $casProxyGrantingTicketIOU, $casProxyGrantingTicket)) { } 0 0 0
846 $self->callPgtUrl(
847 $pgtUrl, $casProxyGrantingTicketIOU,
848 $casProxyGrantingTicket
849 )
850 )
851 {
852 0 $self->logger->debug(
853 "Proxy granting URL $pgtUrl called with success");
854 }
855 else {
856 0 $self->logger->error(
857 "Error calling proxy granting URL $pgtUrl");
858 0 $casProxyGrantingTicketIOU = undef;
859 }
860 }
861  
862 }
863 else {
864 0 $self->logger->warn(
865 "Error in proxy granting ticket management, bypass it");
866 }
867 }
868  
869 # Open local session
870 my $localSession =
871 0 $self->p->getApacheSession( $casServiceSession->data->{_cas_id} );
872  
873 0 ▶ unless ($localSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($localSession) 0 0 0
874 $self->userLogger->warn( "Local session "
875 . $casServiceSession->data->{_cas_id}
876 0 . " notfound" );
877 0 return $self->$failure(
878 $req,
879 app => $app,
880 code => 'INTERNAL_ERROR',
881 msg => 'No session associated to ticket'
882 );
883 }
884  
885 # Get username
886 0 my $username = $self->getUsernameForApp( $req, $app, $localSession->data );
887  
888 # Useful for logging
889 0 $req->sessionInfo( $localSession->data );
890  
891 0 $self->logger->debug("Get username $username");
892  
893 # Get attributes [CAS 3.0]
894 0 my $attributes = {};
895 my $ev =
896 ( $app and $self->conf->{casAppMetaDataExportedVars}->{$app} )
897 0 ▶ ? $self->conf->{casAppMetaDataExportedVars}->{$app}
Branch: 1 branch
BranchTrueFalseTotal
$app && $self->conf->{'casAppMetaDataExportedVars'}{$app} ? : 0 0 0
Condition0%0/3
$app and $self->conf->{"casAppMetaDataExportedVars"}{$app}
!ll&&!rl&&r
000
MC/DC0%0/2
$app and $self->conf->{"casAppMetaDataExportedVars"}{$app}
$app $self->conf->{"casAppMetaDataExportedVars"}{$app}
Truth table0%0/3
A and B
A= $appB= $self->conf->{"casAppMetaDataExportedVars"}{$app}
ABresult
0X0
100
111
898 : {};
899 0 ▶ unless (%$ev) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$ev) 0 0 0
900 0 ▶ $ev = $self->conf->{casAttributes} || {};
Condition0%0/2
$self->conf->{'casAttributes'} || {}
l!l
00
MC/DC0%0/1
$self->conf->{'casAttributes'} || {}
$self->conf->{'casAttributes'}
Truth table0%0/2
A
A= $self->conf->{'casAttributes'}
Aresult
11
00
901 }
902  
903 0 foreach my $casAttribute ( keys %$ev ) {
904 0 my $sessionAttr = $ev->{$casAttribute};
905 0 my $value;
906  
907 # Lookup per-service macros first, and then local sessions
908 #
909 0 ▶ if ( $app and $self->spMacros->{$app}->{$sessionAttr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app and $self->spMacros->{$app}{$sessionAttr}) { } 0 0 0
Condition0%0/3
$app and $self->spMacros->{$app}{$sessionAttr}
!ll&&!rl&&r
000
MC/DC0%0/2
$app and $self->spMacros->{$app}{$sessionAttr}
$app $self->spMacros->{$app}{$sessionAttr}
Truth table0%0/3
A and B
A= $appB= $self->spMacros->{$app}{$sessionAttr}
ABresult
0X0
100
111
910 0 $value = $self->spMacros->{$app}->{$sessionAttr}
911 ->( $req, $localSession->data );
912 }
913 else {
914 0 $value = $localSession->data->{$sessionAttr};
915 }
916  
917 0 ▶ $attributes->{$casAttribute} = $value
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
918 if defined $value;
919 }
920  
921 # Return success message
922 0 ▶ if ( $self->isLogoutEnabled($app) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isLogoutEnabled($app)) 0 0 0
923 0 $self->_save_ticket_for_single_logout( $localSession, $service,
924 $req->param('ticket') );
925 }
926  
927 0 ▶ $self->p->registerProtectedAppAccess( $req, $username, "cas:$app" ) if $app;
Branch: 1 branch
BranchTrueFalseTotal
if $app 0 0 0
928  
929 0 my $h =
930 $self->p->processHook( $req, 'casGenerateValidateResponse', $username,
931 $attributes );
932 0 ▶ return $self->$failure(
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 0 0
933 $req,
934 app => $app,
935 code => "INTERNAL_ERROR",
936 msg => "Internal error during request validation",
937 res => $h,
938 ) if ( $h != PE_OK );
939  
940 0 my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
941 0 ▶ my $by_app = $app ? " by $app" : "";
Branch: 1 branch
BranchTrueFalseTotal
$app ? : 0 0 0
942 0 ▶ my $attr_str =
Branch: 1 branch
BranchTrueFalseTotal
defined $attributes && keys %$attributes ? : 0 0 0
Condition0%0/3
defined $attributes and keys %$attributes
!ll&&!rl&&r
000
MC/DC0%0/2
defined $attributes and keys %$attributes
defined $attributes keys %$attributes
Truth table0%0/3
A and B
A= defined $attributesB= keys %$attributes
ABresult
0X0
100
111
943 ( defined($attributes) && keys %$attributes )
944 ? ( " with attributes " . join( ',', sort( keys(%$attributes) ) ) )
945 : "";
946 0 ▶ $self->auditLog(
Branch: 1 branch
BranchTrueFalseTotal
$app ? : 0 0 0
947 $req,
948 code => "ISSUER_CAS_VALIDATE_SUCCESS",
949 message => (
950 "CAS validation succeeded for ${user}${by_app}"
951 . " as ${username}${attr_str}"
952 ),
953 ( $app ? ( app => $app ) : () ),
954 user => $user,
955 cas_user => $username,
956 cas_proxies => $proxies,
957 attributes => $attributes,
958 );
959 0 return $self->$success( $req, $username,
960 $casProxyGrantingTicketIOU, $proxies, $attributes );
961 }
962  
963 # Returns the main attribute (sub) to use for this App
964 # It can be a session attribute, or per-App macro
965 sub getUsernameForApp {
966 0 ▶ my ( $self, $req, $app, $data ) = @_;
Subroutine getUsernameForApp: not called CC=6 SCAR=37.4
Pod undocumented
967  
968 my $username_attribute =
969 ( $app
970 and $self->casAppList->{$app}->{casAppMetaDataOptionsUserAttribute} )
971 ? $self->casAppList->{$app}->{casAppMetaDataOptionsUserAttribute}
972 : ( $self->conf->{casAttr}
973 0 ▶ || $self->conf->{whatToTrace} );
Branch: 1 branch
BranchTrueFalseTotal
$app && $self->casAppList->{$app}{'casAppMetaDataOptionsUserAttribute'} ? : 0 0 0
Condition0%0/6
$app and $self->casAppList->{$app}{"casAppMetaDataOptionsUserAttribute"}
!ll&&!rl&&r
000
$self->conf->{"casAttr"} or $self->conf->{"whatToTrace"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$app and $self->casAppList->{$app}{"casAppMetaDataOptionsUserAttribute"}
$app $self->casAppList->{$app}{"casAppMetaDataOptionsUserAttribute"}
MC/DC0%0/2
$self->conf->{"casAttr"} or $self->conf->{"whatToTrace"}
$self->conf->{"casAttr"} $self->conf->{"whatToTrace"}
Truth table0%0/3
A and B
A= $appB= $self->casAppList->{$app}{"casAppMetaDataOptionsUserAttribute"}
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $self->conf->{"casAttr"}B= $self->conf->{"whatToTrace"}
ABresult
1X1
011
000
974  
975 0 my $username;
976  
977 # If the main attribute is a SP macro, resolve it
978 # else, get it directly from session data
979 0 ▶ if ( $app and $self->spMacros->{$app}->{$username_attribute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app and $self->spMacros->{$app}{$username_attribute}) { } 0 0 0
Condition0%0/3
$app and $self->spMacros->{$app}{$username_attribute}
!ll&&!rl&&r
000
MC/DC0%0/2
$app and $self->spMacros->{$app}{$username_attribute}
$app $self->spMacros->{$app}{$username_attribute}
Truth table0%0/3
A and B
A= $appB= $self->spMacros->{$app}{$username_attribute}
ABresult
0X0
100
111
980 $username =
981 0 $self->spMacros->{$app}->{$username_attribute}->( $req, $data );
982 }
983 else {
984 0 $username = $data->{$username_attribute};
985 }
986 0 return $username;
987 }
988  
989 sub _save_ticket_for_single_logout {
990 0 ▶ my ( $self, $localSession, $service, $ticket ) = @_;
Subroutine _save_ticket_for_single_logout: not called CC=2 SCAR=17.9
991  
992 0 $self->logger->debug("Saving service $service ticket $ticket for SLO");
993  
994 0 ▶ my $service2ticket = $localSession->data->{cas_tickets_for_SLO} || {};
Condition0%0/2
$localSession->data->{'cas_tickets_for_SLO'} || {}
l!l
00
MC/DC0%0/1
$localSession->data->{'cas_tickets_for_SLO'} || {}
$localSession->data->{'cas_tickets_for_SLO'}
Truth table0%0/2
A
A= $localSession->data->{'cas_tickets_for_SLO'}
Aresult
11
00
995 0 $service2ticket->{$service} = $ticket;
996 0 $localSession->update( { cas_tickets_for_SLO => $service2ticket } );
997 }
998  
999 sub _send_back_channel_LogoutRequests {
1000 0 ▶ my ( $self, $req, $sessionData ) = @_;
Subroutine _send_back_channel_LogoutRequests: not called CC=4 SCAR=30.0
1001  
1002 0 ▶ my $service2ticket = $sessionData->{cas_tickets_for_SLO} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $service2ticket = $sessionData->{"cas_tickets_for_SLO"} or return 0 0 0
1003  
1004 0 my $content;
1005 0 foreach my $service ( keys %$service2ticket ) {
1006  
1007 # Create a new relay session
1008 my $relayInfos = {
1009 service => $service,
1010 0 ticket => $service2ticket->{$service},
1011 _type => "relay"
1012 };
1013 0 my $relaySession = $self->getCasSession( undef, $relayInfos );
1014 0 my $relayid = $relaySession->id;
1015  
1016 # Build the URL that could be used to play this logout request
1017 0 my $slo_url =
1018 $self->p->buildUrl( $req->portal, "cas", "relayLogout",
1019 { relay => $relayid } );
1020  
1021 0 my $name = $self->getNameFromService($service);
1022  
1023 # Display information to the user
1024 0 $content .= $self->loadTemplate(
1025 $req,
1026 'samlSpSoapLogout',
1027 params => {
1028 imgUrl => $slo_url,
1029 name => $name,
1030 }
1031 );
1032 }
1033  
1034 # Build Relay URL and display it
1035 $req->info(
1036 0 ▶ $self->loadTemplate(
Branch: 1 branch
BranchTrueFalseTotal
if $content 0 0 0
1037 $req, 'samlSpsLogout', params => { content => $content }
1038 )
1039 ) if $content;
1040 }
1041  
1042 sub getNameFromService {
1043 0 ▶ my ( $self, $service ) = @_;
Subroutine getNameFromService: not called CC=2 SCAR=17.9
Pod undocumented
1044  
1045 0 my $app = $self->getCasApp($service);
1046 0 ▶ if ( $self->casAppList->{$app}->{casAppMetaDataOptionsDisplayName} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->casAppList->{$app}{"casAppMetaDataOptionsDisplayName"}) 0 0 0
1047 0 return $self->casAppList->{$app}->{casAppMetaDataOptionsDisplayName};
1048 }
1049 0 return $app;
1050 }
1051  
1052 sub relayLogout {
1053 0 ▶ my ( $self, $req ) = @_;
Subroutine relayLogout: not called CC=5 SCAR=34.0
Pod undocumented
1054  
1055 0 my $relay = $req->param("relay");
1056 0 ▶ unless ($relay) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($relay) 0 0 0
1057 0 $self->logger->error("Missing relay parameter");
1058 0 return $self->p->imgnok($req);
1059 }
1060  
1061 0 my $session = $self->getCasSession($relay);
1062 0 ▶ unless ($session) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session) 0 0 0
1063 0 $self->logger->warn("CAS session $relay not found");
1064 0 return $self->p->imgnok($req);
1065 }
1066  
1067 0 ▶ unless ( $session->data->{_type} eq "relay" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->data->{"_type"} eq "relay") 0 0 0
1068 $self->logger->error( "CAS session $relay has incorrect type "
1069 0 . $session->data->{_type} );
1070 0 return $self->p->imgnok($req);
1071 }
1072  
1073 0 my $service = $session->data->{service};
1074 0 my $ticket = $session->data->{ticket};
1075 0 $self->logger->debug(
1076 "Sending back-channel LogoutRequest to $service (ticket $ticket)");
1077  
1078 0 my $logoutRequest = $self->buildLogoutRequest($ticket);
1079  
1080 0 $self->logger->debug("Sending back-channel LogoutRequest to $service");
1081 0 my $response = $self->ua->post(
1082 $service,
1083 { logoutRequest => $logoutRequest },
1084 "Content-Type" => 'application/x-www-form-urlencoded'
1085 );
1086  
1087 0 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
1088 0 $self->logger->debug("CAS back-channel logout to $service OK");
1089 0 return $self->p->imgok($req);
1090 }
1091 else {
1092 0 $self->logger->error( "CAS back-channel logout to $service error: "
1093 . $response->message );
1094 0 $self->logger->debug( $response->dump );
1095 0 return $self->p->imgnok($req);
1096 }
1097 }
1098  
1099 sub isLogoutEnabled {
1100 0 ▶ my ( $self, $app ) = @_;
Subroutine isLogoutEnabled: not called CC=5 SCAR=34.0
Pod undocumented
1101  
1102 0 my $option = -1;
1103 0 ▶ if ($app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 0 0 0
1104 $option = $self->casAppList->{$app}->{casAppMetaDataOptionsLogout}
1105 0 ▶ // -1;
Condition0%0/2
$self->casAppList->{$app}{"casAppMetaDataOptionsLogout"} // -1
l!l
00
MC/DC0%0/1
$self->casAppList->{$app}{"casAppMetaDataOptionsLogout"} // -1
$self->casAppList->{$app}{"casAppMetaDataOptionsLogout"}
Truth table0%0/2
A
A= $self->casAppList->{$app}{"casAppMetaDataOptionsLogout"}
Aresult
11
00
1106 }
1107  
1108 0 ▶ if ( $option == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option == -1) { } 0 0 0
1109 0 ▶ return $self->conf->{casBackChannelSingleLogout} || 0;
Condition0%0/2
$self->conf->{'casBackChannelSingleLogout'} || 0
l!l
00
MC/DC0%0/1
$self->conf->{'casBackChannelSingleLogout'} || 0
$self->conf->{'casBackChannelSingleLogout'}
Truth table0%0/2
A
A= $self->conf->{'casBackChannelSingleLogout'}
Aresult
11
00
1110 }
1111 else {
1112 0 return $option;
1113 }
1114 }
1115  
1116 sub _failValidate1 {
1117 0 ▶ my ( $self, $req, %params ) = @_;
Subroutine _failValidate1: not called CC=5 SCAR=34.0
1118 0 ▶ my $reason = $params{'msg'} ? ": $params{'msg'}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$params{'msg'} ? : 0 0 0
1119 0 ▶ my $res = $params{res} || PE_ERROR;
Condition0%0/2
$params{'res'} || 24
l!l
00
MC/DC0%0/1
$params{'res'} || 24
$params{'res'}
Truth table0%0/2
A
A= $params{'res'}
Aresult
11
00
1120 0 my $app = $params{app};
1121  
1122 $self->auditLog(
1123 $req,
1124 code => "ISSUER_CAS_VALIDATE_FAILED",
1125 message => ( "CAS validation failed" . $reason ),
1126 ( $reason ? ( reason => $reason ) : () ),
1127 ( $app ? ( app => $app ) : () ),
1128 portal_error => portalConsts->{$res},
1129 user => $req->sessionInfo->{ $self->conf->{whatToTrace} },
1130 0 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
$reason ? : 0 0 0
$app ? : 0 0 0
1131  
1132 0 return $self->returnCasValidateError();
1133 }
1134  
1135 sub _failValidate2 {
1136 0 ▶ my ( $self, $req, %params ) = @_;
Subroutine _failValidate2: not called CC=6 SCAR=37.4
1137 0 ▶ my $message = $params{'msg'} ? ": $params{'msg'}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$params{'msg'} ? : 0 0 0
1138 0 my $reason = $params{'msg'};
1139 0 ▶ my $code = $params{'code'} || 'INTERNAL_ERROR';
Condition0%0/2
$params{'code'} || 'INTERNAL_ERROR'
l!l
00
MC/DC0%0/1
$params{'code'} || 'INTERNAL_ERROR'
$params{'code'}
Truth table0%0/2
A
A= $params{'code'}
Aresult
11
00
1140 0 ▶ my $res = $params{res} || PE_ERROR;
Condition0%0/2
$params{'res'} || 24
l!l
00
MC/DC0%0/1
$params{'res'} || 24
$params{'res'}
Truth table0%0/2
A
A= $params{'res'}
Aresult
11
00
1141 0 my $app = $params{app};
1142  
1143 $self->auditLog(
1144 $req,
1145 code => "ISSUER_CAS_VALIDATE_FAILED",
1146 message => ( "CAS validation failed" . $message ),
1147 ( $reason ? ( reason => $reason ) : () ),
1148 ( $app ? ( app => $app ) : () ),
1149 cas_code => $code,
1150 portal_error => portalConsts->{$res},
1151 user => $req->sessionInfo->{ $self->conf->{whatToTrace} },
1152 0 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
$reason ? : 0 0 0
$app ? : 0 0 0
1153  
1154 0 return $self->returnCasServiceValidateError( $req, $code, $reason );
1155 }
1156  
1157 sub _failValidateSaml {
1158 0 ▶ my ( $self, $req, %params ) = @_;
Subroutine _failValidateSaml: not called CC=5 SCAR=34.0
1159 0 ▶ my $message = $params{'msg'} ? ": $params{'msg'}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$params{'msg'} ? : 0 0 0
1160 0 my $reason = $params{'msg'};
1161 0 my $code = $params{'code'};
1162 0 ▶ my $res = $params{res} || PE_ERROR;
Condition0%0/2
$params{'res'} || 24
l!l
00
MC/DC0%0/1
$params{'res'} || 24
$params{'res'}
Truth table0%0/2
A
A= $params{'res'}
Aresult
11
00
1163 0 my $app = $params{app};
1164  
1165 $self->auditLog(
1166 $req,
1167 code => "ISSUER_CAS_VALIDATE_FAILED",
1168 message => ( "CAS validation failed" . $message ),
1169 ( $reason ? ( reason => $reason ) : () ),
1170 ( $app ? ( app => $app ) : () ),
1171 cas_code => $code,
1172 portal_error => portalConsts->{$res},
1173 user => $req->sessionInfo->{ $self->conf->{whatToTrace} },
1174 0 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
$reason ? : 0 0 0
$app ? : 0 0 0
1175  
1176 0 return $self->returnSamlValidateError( $req, $code, $reason );
1177 }
1178  
1179 sub _failLogin {
1180 0 ▶ my ( $self, $req, %params ) = @_;
Subroutine _failLogin: not called CC=5 SCAR=34.0
1181 0 ▶ my $reason = $params{'msg'} ? ": $params{'msg'}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$params{'msg'} ? : 0 0 0
1182 0 ▶ my $res = $params{res} || PE_ERROR;
Condition0%0/2
$params{'res'} || 24
l!l
00
MC/DC0%0/1
$params{'res'} || 24
$params{'res'}
Truth table0%0/2
A
A= $params{'res'}
Aresult
11
00
1183 0 my $app = $params{app};
1184  
1185 $self->auditLog(
1186 $req,
1187 code => "ISSUER_CAS_LOGIN_FAILED",
1188 message => ( "CAS login failed" . $reason ),
1189 ( $reason ? ( reason => $reason ) : () ),
1190 ( $app ? ( app => $app ) : () ),
1191 portal_error => portalConsts->{$res},
1192 user => $req->sessionInfo->{ $self->conf->{whatToTrace} },
1193 0 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
$reason ? : 0 0 0
$app ? : 0 0 0
1194  
1195 0 return $res;
1196 }
1197  
1198 sub _failLoginRule {
1199 0 ▶ my ( $self, $req, $cas_request, $app ) = @_;
Subroutine _failLoginRule: not called CC=3 SCAR=24.8
1200 0 my $casAccessControlPolicy = $self->conf->{casAccessControlPolicy};
1201  
1202 0 my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
1203 0 ▶ $self->auditLog(
Branch: 1 branch
BranchTrueFalseTotal
$app ? : 0 0 0
1204 $req,
1205 code => "ISSUER_CAS_LOGIN_FAILED",
1206 ( $app ? ( app => $app ) : () ),
1207 message => ("User $user is not authorized to access to $app"),
1208 reason => "User is not authorized by access rule",
1209 user => $user,
1210 );
1211  
1212 0 ▶ if ( $casAccessControlPolicy =~ /^(error)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($casAccessControlPolicy =~ /^(error)$/i) { } 0 0 0
1213 0 return PE_UNAUTHORIZEDPARTNER;
1214 }
1215 else {
1216 return $self->_redirectUser( $req, $cas_request->{service},
1217 0 "ST-F4K3T1CK3T" );
1218 }
1219 }
1220  
1221 sub _redirectUser {
1222 0 ▶ my ( $self, $req, $destination, $ticket ) = @_;
Subroutine _redirectUser: not called CC=3 SCAR=24.8
1223  
1224 # Redirect to service
1225 # cas_request may have been modified by hook
1226 0 ▶ if ($ticket) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ticket) 0 0 0
1227 0 ▶ $destination .= ( $destination =~ /\?/ ? '&' : '?' )
Branch: 1 branch
BranchTrueFalseTotal
$destination =~ /\?/ ? : 0 0 0
1228 . build_urlencoded( ticket => $ticket );
1229 }
1230  
1231 0 $self->logger->debug("Redirect user to $destination");
1232  
1233 0 $req->{urldc} = $destination;
1234 0 $req->steps( [] );
1235 0 return PE_OK;
1236 }
1237  
1238 sub unauthlogout {
1239 0 ▶ my ( $self, $req ) = @_;
Subroutine unauthlogout: not called CC=7 SCAR=40.3
Pod undocumented
1240 0 $self->logger->debug(
1241 "URL " . $req->path_info . " detected as an CAS LOGOUT URL" );
1242  
1243 # GET parameters
1244 0 my $logout_url = $req->param('url'); # CAS 2.0
1245 0 my $logout_service = $req->param('service'); # CAS 3.0
1246 0 ▶ $logout_service = ''
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttackUrldc("service", $logout_service) 0 0 0
1247 if ( $self->p->checkXSSAttackUrldc( 'service', $logout_service ) );
1248  
1249 # If we use access control, check that the service URL is trusted
1250 0 ▶ if ( $self->conf->{casAccessControlPolicy} =~ /^(error|faketicket)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"casAccessControlPolicy"} =~ /^(error|faketicket)$/i) 0 0 0
1251 0 ▶ if ( $logout_service
Branch: 1 branch
BranchTrueFalseTotal
if ($logout_service and not $self->p->isTrustedUrl($logout_service)) 0 0 0
Condition0%0/3
$logout_service and not $self->p->isTrustedUrl($logout_service)
!ll&&!rl&&r
000
MC/DC0%0/2
$logout_service and not $self->p->isTrustedUrl($logout_service)
$logout_service not $self->p->isTrustedUrl($logout_service)
Truth table0%0/3
A and not(B)
A= $logout_serviceB= not $self->p->isTrustedUrl($logout_service)
ABresult
0X0
100
111
1252 and not $self->p->isTrustedUrl($logout_service) )
1253 {
1254 0 $self->userLogger->error(
1255 "Untrusted service URL $logout_service"
1256 . "specified for CAS Logout" );
1257 0 return $self->p->do( $req, [ [ returnPE => PE_UNAUTHORIZEDURL ] ] );
1258 }
1259 }
1260  
1261 # Legacy code without logout propagation for CAS 2.0
1262 0 ▶ if ($logout_url) {
Branch: 2 branches
BranchTrueFalseTotal
if ($logout_url) { } 0 0 0
elsif ($logout_service) { } 0 0 0
1263  
1264 # Display a link to the provided URL
1265 0 $self->logger->debug("Logout URL $logout_url will be displayed");
1266  
1267 0 $req->info(
1268 $self->loadTemplate(
1269 $req, 'casBack2Url', params => { url => $logout_url }
1270 )
1271 );
1272 0 $req->data->{activeTimer} = 0;
1273  
1274 0 delete $req->pdata->{_url};
1275 0 return $self->p->do( $req, [ [ returnPE => PE_INFO ] ] );
1276 }
1277 elsif ($logout_service) {
1278 0 $self->_redirectUser( $req, $logout_service );
1279 }
1280  
1281 0 return $self->p->unauthLogout($req);
1282 }
1283  
1284 5 1;
« blib/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm »