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

filter: Statementstmt 57.6% 79 / 137 Branchbran 36.5% 19 / 52 Conditioncond 40.9% 9 / 22 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 6 totaltotal 48.5% 118 / 243 CC 38 SCAR 49.2
CC
38
Cov
51%
extractFormInfo
240.0
init
11.8
authenticate
2.0
CRAP 137.2
« blib/lib/Lemonldap/NG/Portal/UserDB/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/CDC.pm »
1 package Lemonldap::NG::Portal::Auth::CAS;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Lemonldap::NG::Common::FormEncode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 use Lemonldap::NG::Portal::Main::Constants qw(
8 PE_OK
9 PE_ERROR
10 PE_REDIRECT
11 PE_IDPCHOICE
12 PE_SENDRESPONSE
13 14 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 14 our $VERSION = '2.19.0';
16  
17 14 extends qw(
18 Lemonldap::NG::Portal::Main::Auth
19 Lemonldap::NG::Portal::Lib::CAS
20 );
21  
22 # PROPERTIES
23  
24 14 has srvNumber => ( is => 'rw', default => 0 );
25 14 ▶has srvList => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26 14 ▶use constant sessionKind => 'CAS';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # INITIALIZATION
29  
30 sub init {
31 13 ▶ my ($self) = @_;
Subroutine init: called CC=11 SCAR=24.7
Pod undocumented
32  
33 13 ▶ return 0 unless ( $self->loadSrv );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loadSrv 0 13 13
34 13 my @tab = ( keys %{ $self->casSrvList } );
35 13 ▶ unless (@tab) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tab) 0 13 13
36 0 $self->logger->error("No CAS server configured");
37 0 return 0;
38 }
39 13 $self->srvNumber( scalar @tab );
40 13 my @list;
41  
42 13 foreach (@tab) {
43 17 my $name = $_;
44 $name =
45 $self->conf->{casSrvMetaDataOptions}->{$_}
46 ->{casSrvMetaDataOptionsDisplayName}
47 if $self->conf->{casSrvMetaDataOptions}->{$_}
48 17 ▶ ->{casSrvMetaDataOptionsDisplayName};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"casSrvMetaDataOptions"}{$_}{"casSrvMetaDataOptionsDisplayName"} 1 16 17
49 my $icon = $self->conf->{casSrvMetaDataOptions}->{$_}
50 17 ->{casSrvMetaDataOptionsIcon};
51 my $tooltip = $self->conf->{casSrvMetaDataOptions}->{$_}
52 17 ▶ ->{casSrvMetaDataOptionsTooltip} || $name;
Condition66%2/3
$self->conf->{'casSrvMetaDataOptions'}{$_}{'casSrvMetaDataOptionsTooltip'} || $name
l!l&&r!l&&!r
1160
MC/DC0%0/2
$self->conf->{'casSrvMetaDataOptions'}{$_}{'casSrvMetaDataOptionsTooltip'} || $name
$self->conf->{'casSrvMetaDataOptions'}{$_}{'casSrvMetaDataOptionsTooltip'} $name
Truth table66%2/3
A || B
A= $self->conf->{'casSrvMetaDataOptions'}{$_}{'casSrvMetaDataOptionsTooltip'}B= $name
ABresult
1X1
011
000
53 my $order = $self->conf->{casSrvMetaDataOptions}->{$_}
54 17 ▶ ->{casSrvMetaDataOptionsSortNumber} // 0;
Condition100%2/2
$self->conf->{"casSrvMetaDataOptions"}{$_}{"casSrvMetaDataOptionsSortNumber"} // 0
l!l
215
MC/DC100%1/1
$self->conf->{"casSrvMetaDataOptions"}{$_}{"casSrvMetaDataOptionsSortNumber"} // 0
$self->conf->{"casSrvMetaDataOptions"}{$_}{"casSrvMetaDataOptionsSortNumber"}
Truth table100%2/2
A
A= $self->conf->{"casSrvMetaDataOptions"}{$_}{"casSrvMetaDataOptionsSortNumber"}
Aresult
11
00
55 17 my $img_src;
56  
57 17 ▶ if ($icon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($icon) 1 16 17
58 1 ▶ $img_src =
Branch: 1 branch
BranchTrueFalseTotal
$icon =~ m[^https?://] ? : 0 1 1
59 ( $icon =~ m#^https?://# )
60 ? $icon
61 : $self->p->staticPrefix . "/common/" . $icon;
62 }
63 17 push @list,
64 {
65 val => $_,
66 name => $name,
67 title => $tooltip,
68 icon => $img_src,
69 order => $order
70 };
71 }
72 @list =
73 sort {
74 13 $a->{order} <=> $b->{order}
75 or $a->{name} cmp $b->{name}
76 or $a->{val} cmp $b->{val}
77 6 ▶ } @list;
Branch: 1 branch
BranchTrueFalseTotal
$Lemonldap::NG::Portal::Auth::CAS::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::CAS::b->{"order"} or $Lemonldap::NG::Portal::Auth::CAS::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"name"} or $Lemonldap::NG::Portal::Auth::CAS::a->{"val"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"val"} 0 6 6
Condition66%2/3
$Lemonldap::NG::Portal::Auth::CAS::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::CAS::b->{"order"} or $Lemonldap::NG::Portal::Auth::CAS::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"name"}
l!l&&r!l&&!r
420
MC/DC0%0/2
$Lemonldap::NG::Portal::Auth::CAS::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::CAS::b->{"order"} or $Lemonldap::NG::Portal::Auth::CAS::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"name"}
$Lemonldap::NG::Portal::Auth::CAS::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::CAS::b->{"order"} $Lemonldap::NG::Portal::Auth::CAS::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"name"}
Truth table66%2/3
A or B
A= $Lemonldap::NG::Portal::Auth::CAS::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::CAS::b->{"order"}B= $Lemonldap::NG::Portal::Auth::CAS::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::CAS::b->{"name"}
ABresult
1X1
011
000
78 13 $self->srvList( \@list );
79  
80 13 return 1;
81 }
82  
83 # RUNNING METHODS
84  
85 sub extractFormInfo {
86 44 ▶ my ( $self, $req ) = @_;
Subroutine extractFormInfo: called CC=28 SCAR=54.8
Pod undocumented
87  
88 # Local URL
89 44 my $local_url = $self->p->fullUrl($req);
90  
91 # Remove cancel parameter
92 44 $local_url =~ s/cancel=1&?//;
93  
94 # Catch proxy callback
95 44 ▶ if ( $req->param('casProxy') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("casProxy")) 0 44 44
96 0 $self->logger->debug("CAS: Proxy callback detected");
97  
98 0 my $pgtIou = $req->param('pgtIou');
99 0 my $pgtId = $req->param('pgtId');
100  
101 0 ▶ if ( $pgtIou and $pgtId ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pgtIou and $pgtId) 0 0 0
Condition0%0/3
$pgtIou and $pgtId
!ll&&!rl&&r
000
MC/DC0%0/2
$pgtIou and $pgtId
$pgtIou $pgtId
Truth table0%0/3
A and B
A= $pgtIouB= $pgtId
ABresult
0X0
100
111
102  
103 # Store pgtId and pgtIou
104 0 my $pgtSessionId = $self->storePGT( $pgtIou, $pgtId );
105 0 ▶ unless ($pgtSessionId) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pgtSessionId) { } 0 0 0
106 0 $self->userLogger->error(
107 "CAS: Unable to store pgtIou $pgtIou and pgtId $pgtId");
108 }
109 else {
110 0 $self->logger->debug(
111 "CAS: Store pgtIou $pgtIou and pgtId $pgtId in session $pgtSessionId"
112 );
113 }
114 }
115  
116 # Exit
117 0 $req->response( [ 200, [ 'Content-Length' => 0 ], [] ] );
118 0 return PE_SENDRESPONSE;
119 }
120  
121 44 my $srv;
122  
123 # Check Service Ticket
124 44 my $ticket = $req->param('ticket');
125  
126 # Check if CAS server is chosen
127 44 ▶ unless ( ( $ticket and $srv = $req->cookies->{llngcasserver} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ticket and $srv = $req->cookies->{"llngcasserver"} or $srv = $req->param("idp")) 44 0 44
Condition33%2/6
$ticket and $srv = $req->cookies->{"llngcasserver"} or $srv = $req->param("idp")
l!l&&r!l&&!r
0044
$ticket and $srv = $req->cookies->{"llngcasserver"}
!ll&&!rl&&r
4400
MC/DC0%0/3
$ticket and $srv = $req->cookies->{"llngcasserver"} or $srv = $req->param("idp")
$ticket $srv = $req->cookies->{"llngcasserver"} $srv = $req->param("idp")
Truth table20%1/5
A and B or C
A= $ticketB= $srv = $req->cookies->{"llngcasserver"}C= $srv = $req->param("idp")
ABCresult
11X1
0X11
1011
0X00
1000
128 or $srv = $req->param('idp') )
129 {
130 44 $self->logger->debug("Redirecting user to CAS server list");
131  
132 # Auto select provider if there is only one
133 44 ▶ if ( $self->srvNumber == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->srvNumber == 1) { } 42 2 44
134 42 ($srv) = keys %{ $self->casSrvList };
135 42 $self->logger->debug("Selecting the only defined CAS server: $srv");
136 }
137  
138 else {
139  
140 # Try to use server resolution rules
141 2 foreach ( keys %{ $self->srvRules } ) {
142 0 ▶ my $cond = $self->srvRules->{$_} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $cond = $self->srvRules->{$_} or next 0 0 0
143 0 ▶ if ( $cond->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$cond($req, $req->sessionInfo)) 0 0 0
144 0 $self->logger->debug(
145 "CAS Server $_ selected from resolution rule");
146 0 $srv = $_;
147 0 last;
148 }
149 }
150  
151 2 ▶ unless ($srv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($srv) 2 0 2
152  
153 # Server list
154 2 $req->data->{list} = $self->srvList;
155 2 $req->data->{login} = 1;
156 2 return PE_IDPCHOICE;
157 }
158 }
159 }
160  
161 42 my $srvConf = $self->conf->{casSrvMetaDataOptions}->{$srv};
162 42 ▶ unless ($srvConf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($srvConf) 0 42 42
163 0 $self->userLogger->error("CAS server $srv not configured");
164 0 return PE_ERROR;
165 }
166  
167 # Provider is choosen
168 42 $self->logger->debug("CAS server $srv choosen");
169  
170 42 $req->data->{_casSrvCurrent} = $srv;
171  
172 # Unless a ticket has been found, we redirect the user
173 42 ▶ unless ($ticket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ticket) 42 0 42
174  
175 # Add request state parameters
176 42 ▶ if ( $req->data->{_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"_url"}) 0 42 42
177 $local_url .= ( $local_url =~ /\?/ ? '&' : '?' )
178 0 ▶ . build_urlencoded( url => $req->data->{_url} );
Branch: 1 branch
BranchTrueFalseTotal
$local_url =~ /\?/ ? : 0 0 0
179 }
180  
181 # Forward hidden fields
182 42 ▶ if ( $req->{portalHiddenFormValues}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"portalHiddenFormValues"} and %{$req->{"portalHiddenFormValues"};}) 0 42 42
Condition33%1/3
$req->{"portalHiddenFormValues"} and %{$req->{"portalHiddenFormValues"};}
!ll&&!rl&&r
4200
MC/DC0%0/2
$req->{"portalHiddenFormValues"} and %{$req->{"portalHiddenFormValues"};}
$req->{"portalHiddenFormValues"} %{$req->{"portalHiddenFormValues"};}
Truth table33%1/3
A and B
A= $req->{"portalHiddenFormValues"}B= %{$req->{"portalHiddenFormValues"};}
ABresult
0X0
100
111
183 0 and %{ $req->{portalHiddenFormValues} } )
184 {
185  
186 0 $self->logger->debug("Add hidden values to CAS redirect URL\n");
187 $local_url .= ( $local_url =~ /\?/ ? '&' : '?' )
188 0 ▶ . build_urlencoded( %{ $req->{portalHiddenFormValues} } );
Branch: 1 branch
BranchTrueFalseTotal
$local_url =~ /\?/ ? : 0 0 0
189 }
190  
191 # Build login URL
192 42 my $login_url = $self->getServerLoginURL( $local_url, $srvConf );
193 42 ▶ $login_url .= '&renew=true' if $srvConf->{casSrvMetaDataOptionsRenew};
Branch: 1 branch
BranchTrueFalseTotal
if $srvConf->{"casSrvMetaDataOptionsRenew"} 0 42 42
194 $login_url .= '&gateway=true'
195 42 ▶ if $srvConf->{casSrvMetaDataOptionsGateway};
Branch: 1 branch
BranchTrueFalseTotal
if $srvConf->{"casSrvMetaDataOptionsGateway"} 0 42 42
196  
197 42 $self->logger->debug("CAS: Redirect user to $login_url");
198 42 $req->{urldc} = $login_url;
199 42 $req->steps( [] );
200 $req->addCookie(
201 $self->p->cookie(
202 name => 'llngcasserver',
203 value => $srv,
204 secure => $self->conf->{securedCookie},
205 )
206 42 );
207 42 return PE_REDIRECT;
208 }
209  
210 0 $self->logger->debug("CAS: Service Ticket received: $ticket");
211  
212 my $proxied =
213 0 ▶ $self->conf->{casSrvMetaDataOptionsProxiedServices}->{$srv} || {};
Condition0%0/2
$self->conf->{'casSrvMetaDataOptionsProxiedServices'}{$srv} || {}
l!l
00
MC/DC0%0/1
$self->conf->{'casSrvMetaDataOptionsProxiedServices'}{$srv} || {}
$self->conf->{'casSrvMetaDataOptionsProxiedServices'}{$srv}
Truth table0%0/2
A
A= $self->conf->{'casSrvMetaDataOptionsProxiedServices'}{$srv}
Aresult
11
00
214  
215 # Ticket found, try to validate it
216 0 $local_url =~ s/ticket=[^&]+//;
217 0 $local_url =~ s/\?$//;
218 0 $local_url =~ s/\&$//;
219 0 ( $req->{user}, $req->data->{casAttrs} ) =
220 $self->validateST( $req, $local_url, $ticket, $srvConf, $proxied );
221 0 ▶ unless ( $req->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'user'}) { } 0 0 0
222 0 $self->userLogger->error("CAS: Unable to validate ST $ticket");
223 0 return PE_ERROR;
224 }
225 else {
226 0 $self->logger->debug("CAS: User $req->{user} found");
227 }
228  
229 # Request proxy tickets for proxied services
230 0 ▶ if (%$proxied) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$proxied) 0 0 0
231  
232 # Check we received a PGT
233 0 my $pgtId = $req->data->{pgtId};
234  
235 0 ▶ unless ($pgtId) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pgtId) 0 0 0
236 0 $self->logger->error(
237 "CAS: Proxy mode activated, but no PGT received");
238 0 return PE_ERROR;
239 }
240  
241 # Get a proxy ticket for each proxied service
242 0 foreach ( keys %$proxied ) {
243 0 my $service = $proxied->{$_};
244 0 my $pt = $self->retrievePT( $service, $pgtId, $srvConf );
245  
246 0 ▶ unless ($pt) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pt) 0 0 0
247 0 $self->logger->error(
248 "CAS: No proxy ticket received for service $service");
249 0 return PE_ERROR;
250 }
251  
252 $self->logger->debug(
253 0 "CAS: Received proxy ticket $pt for service $service");
254  
255 # Store it in session
256 0 $req->{sessionInfo}->{ '_casPT' . $_ } = $pt;
257 }
258  
259 }
260  
261 0 return PE_OK;
262 }
263  
264 sub authenticate {
265 0 ▶ return PE_OK;
Subroutine authenticate: not called CC=1 SCAR=6.9
Pod undocumented
266 }
267  
268 # Set authenticationLevel.
269 sub setAuthSessionInfo {
270 0 ▶ my ( $self, $req ) = @_;
Subroutine setAuthSessionInfo: not called CC=1 SCAR=6.9
Pod undocumented
271 0 $req->{sessionInfo}->{authenticationLevel} = $self->conf->{casAuthnLevel};
272 0 $req->{sessionInfo}->{_casSrv} = $req->data->{_casSrvCurrent};
273 0 return PE_OK;
274 }
275  
276 sub authLogout {
277 0 ▶ my ( $self, $req ) = @_;
Subroutine authLogout: not called CC=1 SCAR=6.9
Pod undocumented
278  
279 # Build CAS logout URL
280 my $logout_url = $self->getServerLogoutURL( $self->p->fullUrl($req),
281 $self->conf->{casSrvMetaDataOptions}->{ $req->userData->{_casSrv} }
282 0 ->{casSrvMetaDataOptionsUrl} );
283  
284 0 $self->logger->debug("Build CAS logout URL: $logout_url");
285  
286 # Register CAS logout URL in logoutServices
287 0 $req->data->{logoutServices}->{CASserver} = $logout_url;
288  
289 0 return PE_OK;
290 }
291  
292 sub getDisplayType {
293 1 ▶ return "logo";
Subroutine getDisplayType: called CC=1 SCAR=0.0
Pod undocumented
294 }
295  
296 14 1;
« blib/lib/Lemonldap/NG/Portal/UserDB/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/CDC.pm »