« blib/lib/Lemonldap/NG/Portal/Auth/Combination.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Main/Request.pm »
| 1 | package Lemonldap::NG::Portal::Plugins::CDA; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | PE_APACHESESSIONERROR | ||||||||||||||||||||||||||||||||||||||||||
| 8 | PE_ERROR | ||||||||||||||||||||||||||||||||||||||||||
| 9 | PE_OK | ||||||||||||||||||||||||||||||||||||||||||
| 10 | URIRE | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '2.0.14'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | extends 'Lemonldap::NG::Common::Module'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # INTERFACE | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use constant endAuth => 'changeUrldc'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use constant forAuthUser => 'changeUrldc'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # RUNNING METHOD | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | sub _url_is_external { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_url_is_external: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my ( $self, $req, $urldc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my $portal = $req->portal; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | my $domain = $self->p->getCookieDomain($req); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | return $self->_cookie_can_be_seen( $portal, $domain, $urldc ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # This method determines if a cookie set by | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # $portal for domain $domain can be received by URL $urldc | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | sub _cookie_can_be_seen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cookie_can_be_seen: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | my ( $self, $portal, $domain, $urldc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | if ( $urldc =~ URIRE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $host = $3; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # Domain is set: cookie is sent to the domain itself, and all subdomains | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | if ($domain) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | my $domain_without_leading_dot = $domain =~ s/^\.//r; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | return if $host eq $domain_without_leading_dot; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | return $host !~ m@\Q$domain\E$@i; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # Domain is not set: cookie is only sent to the portal itself | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $portal_host = URI->new($portal)->host; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $host ne $portal_host; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | sub changeUrldc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changeUrldc: called CC=10 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | my $urldc = $req->{urldc} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->{'urldc'} || ''
MC/DC100%1/1
$req->{'urldc'} || ''
$req->{'urldc'}
Truth table100%2/2
A
A= $req->{'urldc'}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | if ( $req->id | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$req->id and $self->_url_is_external($req, $urldc) and $self->p->isTrustedUrl($urldc)
$req->id and $self->_url_is_external($req, $urldc)
MC/DC33%1/3
$req->id and $self->_url_is_external($req, $urldc) and $self->p->isTrustedUrl($urldc)
$req->id
$self->_url_is_external($req, $urldc)
$self->p->isTrustedUrl($urldc)
Truth table50%2/4
A and B and C
A= $req->idB= $self->_url_is_external($req, $urldc)C= $self->p->isTrustedUrl($urldc)
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | and $self->_url_is_external( $req, $urldc ) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | and $self->p->isTrustedUrl($urldc) ) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my $ssl = $urldc =~ /^https/; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | $self->logger->debug('CDA request'); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Create CDA session | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | my $cdaInfos = { '_utime' => time }; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | if ( $self->{conf}->{securedCookie} < 2 or $ssl ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"conf"}{"securedCookie"} < 2 or $ssl
MC/DC50%1/2
$self->{"conf"}{"securedCookie"} < 2 or $ssl
$self->{"conf"}{"securedCookie"} < 2
$ssl
Truth table66%2/3
A or B
A= $self->{"conf"}{"securedCookie"} < 2B= $ssl
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | $cdaInfos->{cookie_value} = $req->id; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $cdaInfos->{cookie_name} = $self->{conf}->{cookieName}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | if ( $req->{sessionInfo}->{_httpSession} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | $cdaInfos->{cookie_value} = | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $req->{sessionInfo}->{_httpSession}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $cdaInfos->{cookie_name} = $self->{conf}->{cookieName} . "http"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||
| 82 | "Session does not contain _httpSession field. " | ||||||||||||||||||||||||||||||||||||||||||
| 83 | . "Portal must be accessed over HTTPS when using CDA with double cookie" | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return PE_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | my $cdaSession = | |||||||||||||||||||||||||||||||||||||||||
| 90 | $self->p->getApacheSession( undef, kind => "CDA", info => $cdaInfos ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | unless ($cdaSession) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->logger->error("Unable to create CDA session"); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return PE_APACHESESSIONERROR; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # We are about to redirect the user to the CDA application, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # dismiss any previously stored redirections (#1650) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | delete $req->{pdata}->{_url}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | $req->{urldc} .= | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ( $urldc =~ /\?/ ? '&' : '?' ) | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | . $self->{conf}->{cookieName} . "cda=" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | . $cdaSession->id; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | $self->logger->debug( "CDA redirection to " . $req->{urldc} ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||