« blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/ClientCredentialsGrant.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/SOAPServer.pm »
| 1 | package Lemonldap::NG::Portal::Main::Process; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 454 | our $VERSION = '2.23.4'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Lemonldap::NG::Portal::Main; | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 454 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 454 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 454 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 454 | ▶ | use Lemonldap::NG::Common::Util qw(isHiddenAttr); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 454 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw(portalConsts); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 454 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Main method | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # ----------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Launch all methods declared in request "steps" array. Methods can be | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # declared by their name (in Lemonldap::NG::Portal::Main namespace) or point | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # to a subroutine (see Lemonldap::NG::Portal::Main::Run.pm) | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 747 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=27 SCAR=38.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 747 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Store ipAddr in env | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 747 | $req->env->{ipAddr} = $req->address; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 747 | my $err = PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 747 | my $nofail = delete $args{nofail}; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 747 | ▶ | if ( grep { ref $_ eq "CODE" } @{ $req->steps } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 23 | $self->logger->debug( | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | "Warning: process pipeline contains non-serializable step"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 747 | ▶ | while ( my $sub = shift @{ $req->steps } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4997 | ▶ | $nofail = 1 if $req->data->{nofail}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4997 | my @args_array; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # This lets you transmit arguments by storing | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # [ "method_name", @args_array ] in steps | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4997 | ▶ | if ( ref($sub) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 222 | my $sub_name = shift @$sub; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 222 | @args_array = @$sub; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 222 | $sub = $sub_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4997 | ▶ | if ( ref $sub eq "CODE" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 56 | $self->logger->debug("Processing code ref"); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 56 | my $tmp = $sub->( $req, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 56 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $err = $tmp unless $err > 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | last unless $nofail and $err != PE_SENDRESPONSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nofail and $err != -4
MC/DC0%0/2
$nofail and $err != -4
$nofail
$err != -4
Truth table0%0/3
A and B
A= $nofailB= $err != -4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | elsif ( my ( $plugin, $callback ) = $sub =~ /(.*)::(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 630 | $self->logger->debug("Processing ${plugin}::${callback}"); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 630 | my $plugin = $self->loadedModules->{$plugin}; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 630 | ▶ | if ( ref($plugin) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 630 | my $tmp = $plugin->$callback( $req, @args_array, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 630 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 42 | ▶ | $err = $tmp unless $err > 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 42 | ▶ | last unless $nofail and $err != PE_SENDRESPONSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nofail and $err != -4
MC/DC0%0/2
$nofail and $err != -4
$nofail
$err != -4
Truth table66%2/3
A and B
A= $nofailB= $err != -4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->logger->error("Plugin $plugin is not loaded"); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4311 | $self->logger->debug("Processing $sub"); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4311 | ▶ | if ( my $as = $self->aroundSub->{$sub} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $tmp = $as->( $req, @args_array, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $err = $tmp unless $err > 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | last unless $nofail and $err != PE_SENDRESPONSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nofail and $err != -4
MC/DC0%0/2
$nofail and $err != -4
$nofail
$err != -4
Truth table0%0/3
A and B
A= $nofailB= $err != -4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4311 | my $tmp = $self->$sub( $req, @args_array, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4310 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 504 | ▶ | $err = $tmp unless $err > 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 504 | ▶ | last unless $nofail and $err != PE_SENDRESPONSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nofail and $err != -4
MC/DC50%1/2
$nofail and $err != -4
$nofail
$err != -4
Truth table66%2/3
A and B
A= $nofailB= $err != -4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3845 | ▶ | if ( $self->afterSub->{$sub} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | unshift @{ $req->steps }, @{ $self->afterSub->{$sub} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 746 | ▶ | $self->logger->debug( "Returned " . $self->_formatProcessResult($err) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | if $err; | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 746 | return $err; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 685 | ▶ | sub processHook { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
processHook: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 685 | my ( $self, $req, $hookName, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 685 | $self->logger->debug("Calling hook $hookName"); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 685 | my $err = PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 685 | for my $sub ( @{ $self->hook->{$hookName} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 17 | ▶ | if ( ref $sub eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # If return code is not PE_OK (0), stop processing | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 17 | ▶ | last if ( $err = $sub->( $req, @args ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->logger->debug("Not a code ref: $sub"); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 685 | ▶ | if ( $err != PE_OK ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my $msg = "Hook $hookName returned $err (" . portalConsts->{$err} . ")"; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | if ( $err > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->logger->warn($msg); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # <0 error codes are normal in some use cases | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | $self->logger->debug($msg); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 685 | return $err; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 546 | ▶ | sub _formatProcessResult { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_formatProcessResult: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 546 | my ( $self, $err ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | return ( ( $err > 0 ? "error" : "status" ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | . ": $err (" | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 546 | ▶ | . portalConsts->{$err} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | . ")" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # First process block: check args | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # ------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # For post requests, parse data | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 151 | ▶ | sub restoreArgs { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restoreArgs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 151 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 151 | $req->mustRedirect(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 151 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 114 | ▶ | sub importHandlerData { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
importHandlerData: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 114 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 114 | $req->{sessionInfo} = $req->userData; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 114 | $req->id( $req->sessionInfo->{_session_id} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 114 | $req->user( $req->sessionInfo->{ $self->conf->{whatToTrace} } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 114 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Verify url and confirm parameter | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 577 | ▶ | sub controlUrl { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
controlUrl: called CC=22 SCAR=35.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 577 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 577 | ▶ | if ( my $c = $req->param('confirm') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Replace confirm stamp by 1 or -1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $c =~ s/^(-?)(.*)$/${1}1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Decrypt confirm stamp if cipher available | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # and confirm not already decrypted | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if ( $self->conf->{cipher} and $2 ne "1" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"cipher"} and $2 ne 1
MC/DC0%0/2
$self->conf->{"cipher"} and $2 ne 1
$self->conf->{"cipher"}
$2 ne 1
Truth table33%1/3
A and B
A= $self->conf->{"cipher"}B= $2 ne 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my $time = time() - $self->conf->{cipher}->decrypt($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | if ( $time < 600 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | $self->logger->debug("Confirm parameter accepted $c"); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | $req->set_param( 'confirm', $c ); | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->logger->notice('Confirmation too old, refused'); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $req->set_param( 'confirm', 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 577 | ▶ | $req->{data}->{_url} ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req->{"data"}{"_url"} ||= ""
MC/DC0%0/1
$req->{"data"}{"_url"} ||= ""
$req->{"data"}{"_url"}
Truth table50%1/2
A
A= $req->{"data"}{"_url"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 577 | ▶ | my $url = $req->param('url') || $req->pdata->{_url}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$req->param('url') || $req->pdata->{'_url'}
MC/DC100%2/2
$req->param('url') || $req->pdata->{'_url'}
$req->param('url')
$req->pdata->{'_url'}
Truth table100%3/3
A || B
A= $req->param('url')B= $req->pdata->{'_url'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 577 | ▶ | if ($url) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # REJECT NON BASE64 URL | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 47 | ▶ | if ( $req->urlNotBase64 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $req->{urldc} = $url; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 47 | ▶ | if ( $url =~ m#[^A-Za-z0-9\+/=]# ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | ▶ | unless ( $req->maybeNotBase64 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | "Value must be BASE64 encoded (param: url | value: $url)" | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return PE_BADURL; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | $req->{urldc} = $url; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 39 | $req->{urldc} = decode_base64($url); | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 39 | $req->{urldc} =~ s/[\r\n]//sg; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 47 | $req->{urldc} = URI->new( $req->{urldc} )->as_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 47 | my $tmp = $req->urldc; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # XSS attack | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 47 | ▶ | if ( $self->checkXSSAttack( 'urldc', $req->{urldc} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | delete $req->{urldc}; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return PE_BADURL; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Unprotected hosts | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 47 | ▶ | if ( $tmp and ( $tmp !~ URIRE ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tmp and not $tmp =~ 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]))*)))?))?)]
MC/DC0%0/2
$tmp and not $tmp =~ 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]))*)))?))?)]
$tmp
not $tmp =~ 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 table33%1/3
A and not(B)
A= $tmpB= not $tmp =~ 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]))*)))?))?)]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $self->auditLog( | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | message => "Bad URL $tmp", | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | code => "UNAUTHORIZED_REDIRECT", | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | url => $tmp, | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | delete $req->{urldc}; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return PE_BADURL; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 47 | my ( $proto, $vhost, $appuri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 47 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 47 | my $u = URI->new($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 47 | ▶ | if ( $u->scheme =~ /^https?$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 47 | $proto = $u->scheme; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 47 | ▶ | $vhost = $u->host if $u->can("host"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 47 | $appuri = $self->HANDLER->canonicalUri( $u->path_query ); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Try to resolve alias | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 47 | my $originalVhost = $self->HANDLER->resolveAlias($vhost); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 47 | $vhost = "$proto://$originalVhost"; | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 47 | ▶ | $self->logger->debug( 'Required URL (param: urldc' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | . ( $tmp ? " | value: $tmp | alias: $vhost)" : ')' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # If the target URL has an authLevel set in config, remember it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 47 | my $level = $self->HANDLER->getLevel( $req, $appuri, $originalVhost ); | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 47 | ▶ | if ($level) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->logger->debug( "VirtualHost $originalVhost requires" | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | . " authentication level $level" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $req->pdata->{targetAuthnLevel} = $level; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 47 | ▶ | if ( $tmp | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
$tmp and not $self->isTrustedUrl($tmp)
MC/DC33%1/3
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
$tmp
not $self->isTrustedUrl($tmp)
not $self->isTrustedUrl($vhost)
Truth table50%2/4
A and not(B) and not(C)
A= $tmpB= not $self->isTrustedUrl($tmp)C= not $self->isTrustedUrl($vhost)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | and !$self->isTrustedUrl($tmp) | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | and !$self->isTrustedUrl($vhost) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $self->auditLog( | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | message => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | "URL contains an unprotected host (param: urldc" | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | . " | value: $tmp | alias: $vhost)" | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | code => "UNAUTHORIZED_REDIRECT", | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | url => $tmp, | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | delete $req->{urldc}; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | return PE_UNPROTECTEDURL; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 43 | $req->env->{urldc} = $req->{urldc}; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 43 | $req->env->{_url} = $req->{_url}; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | $req->data->{_url} = $req->pdata->{_url} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 43 | encode_base64( $req->{urldc}, '' ); # Avoid \n or \r | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 573 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 130 | ▶ | sub cleanPdata { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanPdata: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 130 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 130 | ▶ | my $tmp = $req->pdata->{keepPdata} //= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->pdata->{"keepPdata"} //= []
MC/DC100%1/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table100%2/2
A
A= $req->pdata->{"keepPdata"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 130 | foreach my $k ( keys %{ $req->pdata } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 177 | ▶ | unless ( grep { $_ eq $k } @$tmp ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 165 | $self->logger->debug("Removing $k from pdata"); | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | 165 | delete $req->pdata->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 130 | my $user_log = $req->{sessionInfo}->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 130 | my $auth_module = $req->{sessionInfo}->{_auth}; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 130 | my $ipAddr = $req->{sessionInfo}->{ipAddr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 130 | ▶ | if ($user_log) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 130 | $self->auditLog( | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | message => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | "User " . $user_log . " connected from $auth_module ($ipAddr)" | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | code => "LOGIN", | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | user => $user_log, | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 130 | ▶ | if (@$tmp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 6 | $self->logger->debug( 'Add ' . join( ',', @$tmp ) . ' in keepPdata' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | $req->pdata->{keepPdata} = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 130 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 66 | ▶ | sub checkLogout { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkLogout: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 66 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | 66 | ▶ | if ( defined $req->param('logout') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 30 | $req->data->{nofail} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | $req->steps( | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 30 | [ @{ $self->beforeLogout }, 'authLogout', 'deleteSession' ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 66 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 436 | ▶ | sub checkUnauthLogout { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkUnauthLogout: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 436 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 436 | ▶ | if ( defined $req->param('logout') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 28 | $self->_unauthLogout($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | 28 | $req->steps( [ 'controlUrl', [ returnPE => PE_LOGOUT_OK ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 436 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 172 | ▶ | sub returnPE { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
returnPE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 172 | my ( $self, $req, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 172 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | ▶ | sub eventLogout { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eventLogout: called CC=3 SCAR=16.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | my ( $self, $req, $msg ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | bless $req, 'Lemonldap::NG::Portal::Main::Request'; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | $self->logger->debug("Receive a logout event"); | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | $self->processHook( $req, 'eventLogout', $msg ); | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | ▶ | if ( $msg->{id} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $self->logger->debug(" -> logout asked for $msg->{id}"); | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ( my $session = HANDLER->retrieveSession( $req, $msg->{id} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $req->sessionInfo( $req->userData($session) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $req->id( $session->{_session_id} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $req->pdata( {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | $self->do( $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | [ @{ $self->beforeLogout }, 'authLogout', 'deleteSession' ], | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->logger->debug('Session not found'); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $self->_unauthLogout($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | $self->logger->debug('Logout event without id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | $self->_unauthLogout($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 268 | ▶ | sub checkCancel { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkCancel: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 268 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 268 | ▶ | if ( $req->param('cancel') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | $self->logger->debug('Cancel called, run authCancel calls'); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | $req->mustRedirect(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | $req->steps( [ @{ $self->authCancel }, [ returnPE => PE_OK ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 267 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 40 | ▶ | sub authLogout { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authLogout: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 40 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 40 | my $res = $self->_authentication->authLogout($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 40 | $self->logger->debug('Cleaning pdata'); | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 40 | ▶ | my $tmp = $req->pdata->{keepPdata} //= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req->pdata->{"keepPdata"} //= []
MC/DC0%0/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table50%1/2
A
A= $req->pdata->{"keepPdata"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 40 | foreach my $k ( keys %{ $req->pdata } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | delete $req->pdata->{$k} unless ( grep { $_ eq $k } @$tmp ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 40 | ▶ | $req->pdata->{keepPdata} = $tmp if @$tmp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 40 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Delete the current SSO session | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Callers holding a storage identifier instead of a session one may ask for it | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # using [ 'deleteSession', rawSessionId => 1 ] as step | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 40 | ▶ | sub deleteSession { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteSession: called CC=20 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 40 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 40 | ▶ | if ( my $id = $req->id || $req->userData->{_session_id} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$req->id || $req->userData->{'_session_id'}
MC/DC0%0/2
$req->id || $req->userData->{'_session_id'}
$req->id
$req->userData->{'_session_id'}
Truth table66%2/3
A || B
A= $req->idB= $req->userData->{'_session_id'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | my $apacheSession = $self->getApacheSession( $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 40 | ▶ | ( $args{rawSessionId} ? ( hashStore => 0 ) : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 40 | ▶ | unless ($apacheSession) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->logger->debug("Session $id already deleted"); | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 40 | ▶ | unless ( $self->_deleteSession( $req, $apacheSession ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | $self->logger->error("Unable to delete session $id"); | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | $self->logger->error( $apacheSession->error ); | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | return PE_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 39 | $self->logger->debug("Session $id deleted from global storage"); | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Merge logoutServices from user context (for example CAS logoutServices | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # url) and from global configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 39 | ▶ | if ( $self->conf->{logoutServices} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
MC/DC50%1/2
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
$self->conf->{"logoutServices"}
%{$self->conf->{"logoutServices"};}
Truth table66%2/3
A and B
A= $self->conf->{"logoutServices"}B= %{$self->conf->{"logoutServices"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 39 | and %{ $self->conf->{logoutServices} } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # Initialize logoutServices (if not already done) | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | ▶ | $req->data->{logoutServices} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req->data->{"logoutServices"} ||= {}
MC/DC0%0/1
$req->data->{"logoutServices"} ||= {}
$req->data->{"logoutServices"}
Truth table50%1/2
A
A= $req->data->{"logoutServices"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | $req->data->{logoutServices} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | %{ $req->data->{logoutServices} }, | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | %{ $self->conf->{logoutServices} } | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # Collect logout services and build hidden iFrames | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 39 | ▶ | if ( $req->data->{logoutServices} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
MC/DC50%1/2
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
$req->data->{"logoutServices"}
%{$req->data->{"logoutServices"};}
Truth table66%2/3
A and B
A= $req->data->{"logoutServices"}B= %{$req->data->{"logoutServices"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | and %{ $req->data->{logoutServices} } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | $self->logger->debug("Create iFrames to forward logout to services"); | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | $req->info( | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | $self->loadTemplate( | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | $req, 'simpleInfo', | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | params => { trspan => 'logoutFromOtherApp' } | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | foreach ( keys %{ $req->data->{logoutServices} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | my $logoutServiceUrl = $req->data->{logoutServices}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | $self->logger->debug("Find logout service $_ ($logoutServiceUrl)"); | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | my $iframe = | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | qq'<iframe src="$logoutServiceUrl" alt="$_"' | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | . ' marginwidth="0" marginheight="0" scrolling="no"' | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | . ' class="hiddenFrame" width="0" height="0"' | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | . ' frameborder="0"></iframe>'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | $req->info($iframe); | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # Redirect on logout page if no other target defined | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | if ( !$req->urldc and !$req->postUrl ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$req->urldc or $req->postUrl
MC/DC0%0/2
$req->urldc or $req->postUrl
$req->urldc
$req->postUrl
Truth table33%1/3
A or B
A= $req->urldcB= $req->postUrl
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | $self->logger->debug('No other target defined, redirect on logout'); | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | $req->urldc( $self->buildUrl( $req->portal, { logout => 1 } ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 39 | $req->userData( {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # Redirect or Post if asked by authLogout | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 39 | ▶ | if ( $req->postUrl ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $req->steps( ['autoPost'] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 39 | ▶ | if ( $req->urldc and $req->urldc ne $req->portal ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$req->urldc and $req->urldc ne $req->portal
MC/DC50%1/2
$req->urldc and $req->urldc ne $req->portal
$req->urldc
$req->urldc ne $req->portal
Truth table66%2/3
A and B
A= $req->urldcB= $req->urldc ne $req->portal
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | $req->steps( [] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | return PE_REDIRECT; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # If logout redirects to another URL, just remove next steps for the | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # request so autoRedirect will be called | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 38 | ▶ | if ( $req->{urldc} and $req->{urldc} ne $req->portal ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
MC/DC0%0/2
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
$req->{"urldc"}
$req->{"urldc"} ne $req->portal
Truth table33%1/3
A and B
A= $req->{"urldc"}B= $req->{"urldc"} ne $req->portal
| |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $req->steps( [] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # You can use the _continueLogout variable to continue the current flow | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # after deleteSession | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 38 | ▶ | return PE_OK if $req->data->{_continueLogout}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # Else display "error" | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 38 | return PE_LOGOUT_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Check value to detect XSS attack | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # @param name Parameter name | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # @param value Parameter value | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # @return 1 if attack detected, 0 else | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 79 | ▶ | sub checkXSSAttack { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkXSSAttack: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 79 | my ( $self, $name, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # Empty values are not bad | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 79 | ▶ | return 0 unless $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # Test value | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 75 | $value =~ s/\%25/\%/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 75 | ▶ | if ( $value =~ m/(?:\0|<|'|"|`|\%(?:00|3C|22|27))/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | "XSS attack detected (param: $name | value: $value)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | return $self->conf->{checkXSS}; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 75 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # Relaxed version that doesn't look at URL escaped character | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # This is meant to be used for checking urldc until we find a better solution | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 67 | ▶ | sub checkXSSAttackUrldc { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkXSSAttackUrldc: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 67 | my ( $self, $name, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # Empty values are not bad | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 67 | ▶ | return 0 unless $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # Test value | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 33 | ▶ | if ( $value =~ m/(?:\0|<|'|"|`)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $self->userLogger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | "XSS attack detected (param: $name | value: $value)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return $self->conf->{checkXSS}; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 33 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # Second block: auth process (call auth or userDB object) | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # ------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 428 | ▶ | sub extractFormInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractFormInfo: called CC=8 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 428 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 428 | ▶ | return PE_ERROR unless ( $self->_authentication ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 428 | my $ret = $self->_authentication->extractFormInfo($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | 428 | ▶ | if ( $ret == PE_OK and not( $req->user or $req->continue ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$ret == 0 and not $req->user || $req->continue
$req->user || $req->continue
MC/DC0%0/3
$ret == 0 and not $req->user || $req->continue
$ret == 0
$req->user
$req->continue
Truth table75%3/4
A and not(B || C)
A= $ret == 0B= $req->userC= $req->continue
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | 'Authentication module succeed but has not set $req->user'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | return PE_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ▶ | elsif ( $ret == PE_FIRSTACCESS | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
MC/DC100%2/2
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
$ret == 9
$req->cookies->{$self->conf->{"cookieName"}}
Truth table100%3/3
A and B
A= $ret == 9B= $req->cookies->{$self->conf->{"cookieName"}}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | and $req->cookies->{ $self->conf->{cookieName} } ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | $req->addCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | $self->genDomainCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | name => $self->conf->{cookieName}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | value => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | secure => $self->conf->{securedCookie}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 32 | expires => 'Wed, 21 Oct 2015 00:00:00 GMT' | |||||||||||||||||||||||||||||||||||||||||||||
| 522 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 32 | ▶ | if ( $self->conf->{portalErrorOnExpiredSession} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 32 | $ret = PE_SESSIONEXPIRED; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 428 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 156 | ▶ | sub getUser { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getUser: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 156 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 156 | ▶ | return PE_ERROR unless ( $self->_userDB ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 156 | return $self->_userDB->getUser( $req, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | sub findUser { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findUser: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | return PE_ERROR unless ( $self->_userDB ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | return $self->_userDB->findUser( $req, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 134 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 134 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | 134 | my $ret = $req->authResult( $self->_authentication->authenticate($req) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | 134 | $self->logger->debug( " -> authResult = " . $req->authResult ); | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | 134 | ▶ | return $ret if $ret == PE_OK; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # Store failed login into history | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | $req->steps( [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 'setSessionInfo', 'setMacros', | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 'setPersistentSessionInfo', 'storeHistory', | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | @{ $self->afterData }, [ returnPE => PE_BADCREDENTIALS ], | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # Ignore result, process will end at least with PE_BADCREDENTIALS | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | my $tmp = $self->process($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | ▶ | $ret = $tmp if ( $tmp == PE_WAIT ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # Third block: Session data providing | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # ----------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 134 | ▶ | sub setAuthSessionInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setAuthSessionInfo: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 134 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 568 | 134 | $req->{sessionInfo}->{_lastAuthnUTime} = time(); | |||||||||||||||||||||||||||||||||||||||||||||
| 569 | 134 | my $ret = $self->_authentication->setAuthSessionInfo($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 570 | 134 | ▶ | if ( $ret == PE_OK | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}
MC/DC0%0/2
$ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}
$ret == 0
not defined $req->sessionInfo->{"authenticationLevel"}
Truth table33%1/3
A and not(B)
A= $ret == 0B= not defined $req->sessionInfo->{"authenticationLevel"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | and not( defined $req->sessionInfo->{authenticationLevel} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $self->logger->error('Authentication level is not set by auth module'); | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 134 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 137 | ▶ | sub setSessionInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setSessionInfo: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 137 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # Set _user | ||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 137 | ▶ | $req->{sessionInfo}->{_user} //= $req->user; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$req->{"sessionInfo"}{"_user"} //= $req->user
MC/DC0%0/2
$req->{"sessionInfo"}{"_user"} //= $req->user
$req->{"sessionInfo"}{"_user"}
$req->user
Truth table33%1/3
A //= B
A= $req->{"sessionInfo"}{"_user"}B= $req->user
| |||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # Get the current user module | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 137 | $req->{sessionInfo}->{_auth} = $self->getModule( $req, "auth" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 586 | 137 | $req->{sessionInfo}->{_userDB} = $self->getModule( $req, "user" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # Store IP address from remote address or X-FORWARDED-FOR header | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 137 | $req->{sessionInfo}->{ipAddr} = $req->address; | |||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # Date and time | ||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 137 | ▶ | if ( $self->conf->{updateSession} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | $req->{sessionInfo}->{_updateTime} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | strftime( "%Y%m%d%H%M%S", localtime() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 137 | ▶ | $req->{sessionInfo}->{_utime} ||= time(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$req->{"sessionInfo"}{"_utime"} ||= &CORE::GLOBAL::time()
MC/DC0%0/2
$req->{"sessionInfo"}{"_utime"} ||= &CORE::GLOBAL::time()
$req->{"sessionInfo"}{"_utime"}
&CORE::GLOBAL::time()
Truth table33%1/3
A ||= B
A= $req->{"sessionInfo"}{"_utime"}B= &CORE::GLOBAL::time()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | $req->{sessionInfo}->{_startTime} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 137 | strftime( "%Y%m%d%H%M%S", localtime() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | $req->{sessionInfo}->{_lastSeen} = time() | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 137 | ▶ | if $self->conf->{timeoutActivity}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # Currently selected language | ||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 137 | $req->{sessionInfo}->{_language} = $self->getLanguage($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # Store URL origin in session | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 137 | $req->{sessionInfo}->{_url} = $req->{urldc}; | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # Share sessionInfo with underlying handler (needed for safe jail) | ||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 137 | $req->userData( $req->sessionInfo ); | |||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # Call UserDB setSessionInfo | ||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 137 | return $self->_userDB->setSessionInfo($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 138 | ▶ | sub setMacros { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setMacros: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 138 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 619 | 138 | foreach ( sort keys %{ $self->_macros } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 620 | $req->{sessionInfo}->{$_} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 552 | $self->_macros->{$_}->( $req, $req->sessionInfo ); | |||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 138 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 136 | ▶ | sub setGroups { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setGroups: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 136 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 628 | 136 | return $self->_userDB->setGroups($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 133 | ▶ | sub setPersistentSessionInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setPersistentSessionInfo: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 133 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 133 | my $key = $req->{sessionInfo}->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 133 | ▶ | return PE_OK unless ( $key and length($key) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$key and length $key
MC/DC0%0/2
$key and length $key
$key
length $key
Truth table33%1/3
A and B
A= $keyB= length $key
| |||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 133 | my $persistentSession = $self->getPersistentSession($key); | |||||||||||||||||||||||||||||||||||||||||||||
| 639 | 133 | ▶ | if ($persistentSession) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 133 | $self->logger->debug("Persistent session found for $key"); | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 133 | foreach my $k ( keys %{ $persistentSession->data } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # Do not restore some parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 531 | ▶ | next if $k =~ /^_(?:utime|session_(?:u?id|kind))$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | $self->logger->debug("Restore persistent parameter $k"); | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | $req->{sessionInfo}->{$k} = $persistentSession->data->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 133 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 137 | ▶ | sub setLocalGroups { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setLocalGroups: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 137 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | 137 | ▶ | $req->{sessionInfo}->{groups} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->{"sessionInfo"}{"groups"} //= ""
MC/DC100%1/1
$req->{"sessionInfo"}{"groups"} //= ""
$req->{"sessionInfo"}{"groups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"groups"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 137 | ▶ | $req->{sessionInfo}->{hGroups} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->{"sessionInfo"}{"hGroups"} //= {}
MC/DC100%1/1
$req->{"sessionInfo"}{"hGroups"} //= {}
$req->{"sessionInfo"}{"hGroups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"hGroups"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 137 | foreach ( sort keys %{ $self->_groups } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 657 | 411 | ▶ | if ( $self->_groups->{$_}->( $req, $req->sessionInfo ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | $req->{sessionInfo}->{groups} .= | ||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 121 | $self->conf->{multiValuesSeparator} . $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 660 | 121 | $req->{sessionInfo}->{hGroups}->{$_}->{name} = $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||
| 664 | # Clear values separator at the beginning | ||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 137 | ▶ | if ( $req->{sessionInfo}->{groups} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 666 | $req->{sessionInfo}->{groups} =~ | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 116 | s/^$self->{conf}->{multiValuesSeparator}//o; | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 137 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 132 | ▶ | sub store { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 132 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # Now, user is authenticated => inform handler | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 132 | $req->userData( $req->sessionInfo ); | |||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # Create second session for unsecure cookie | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 132 | ▶ | if ( $self->conf->{securedCookie} == 2 and !$req->refresh ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->conf->{"securedCookie"} == 2 and not $req->refresh
MC/DC50%1/2
$self->conf->{"securedCookie"} == 2 and not $req->refresh
$self->conf->{"securedCookie"} == 2
not $req->refresh
Truth table66%2/3
A and not(B)
A= $self->conf->{"securedCookie"} == 2B= not $req->refresh
| |||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | my %infos = %{ $req->{sessionInfo} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | $infos{_updateTime} = strftime( "%Y%m%d%H%M%S", localtime() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | $self->logger->debug("Set _updateTime with $infos{_updateTime}"); | |||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | $infos{_httpSessionType} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 1 | my $session2 = $self->getApacheSession( undef, info => \%infos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | $self->logger->debug("Create second session for unsecured cookie"); | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | $req->{sessionInfo}->{_httpSession} = $session2->id; | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | $self->logger->debug( " -> Cookie value: " . $session2->id ); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # Fill session | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 132 | my $infos = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 693 | 132 | foreach my $k ( sort keys %{ $req->{sessionInfo} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | 2659 | ▶ | next unless defined $req->{sessionInfo}->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 2412 | my $displayValue = $req->{sessionInfo}->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||
| 696 | 2412 | ▶ | $displayValue = '****' if isHiddenAttr( $self->conf, $k ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 2412 | $self->logger->debug("Store $displayValue in session key $k"); | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2412 | ▶ | $self->_dump($displayValue) if ref($displayValue); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 2412 | $infos->{$k} = $req->{sessionInfo}->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # Main session | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | my $session = $self->getApacheSession( | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | $req->id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | hashStore => $req->data->{hashStore}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | force => $req->{force}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 132 | info => $infos | |||||||||||||||||||||||||||||||||||||||||||||
| 708 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 132 | ▶ | return PE_APACHESESSIONERROR unless $session; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # Update current request | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 131 | $req->id( $session->id ); | |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 131 | ▶ | unless ( $self->_sfEngine->searchForAuthorized2Fmodules($req) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 129 | $self->logger->debug( | |||||||||||||||||||||||||||||||||||||||||||||
| 715 | "No 2F module authorized -> Update current request"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 129 | $req->{sessionInfo}->{_session_id} = $session->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 129 | $req->{sessionInfo}->{_session_kind} = $session->{kind}; | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # Compute unsecured cookie value if needed | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 131 | ▶ | if ( $self->conf->{securedCookie} == 3 and !$req->refresh ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"securedCookie"} == 3 and not $req->refresh
MC/DC0%0/2
$self->conf->{"securedCookie"} == 3 and not $req->refresh
$self->conf->{"securedCookie"} == 3
not $req->refresh
Truth table33%1/3
A and not(B)
A= $self->conf->{"securedCookie"} == 3B= not $req->refresh
| |||||||||||||||||||||||||||||||||||||||||||||||
| 722 | $req->{sessionInfo}->{_httpSession} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $self->conf->{cipher}->encryptHex( $req->id, "http" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 724 | $self->logger->debug( " -> Compute unsecured cookie value : " | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | . $req->{sessionInfo}->{_httpSession} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 131 | $req->refresh(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 728 | 131 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 129 | ▶ | sub buildCookie { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
buildCookie: called CC=7 SCAR=20.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 129 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | 129 | ▶ | if ( $req->id ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 734 | $req->addCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 735 | $self->genDomainCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 737 | name => $self->conf->{cookieName}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | value => $req->id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 739 | secure => $self->conf->{securedCookie}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | $self->conf->{cookieExpiration} | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | ? ( max_age => $self->conf->{cookieExpiration} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 129 | ▶ | : (), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 744 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 129 | ▶ | if ( $self->conf->{securedCookie} >= 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | $req->addCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | $self->genDomainCookie( | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | name => $self->conf->{cookieName} . "http", | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | value => $req->{sessionInfo}->{_httpSession}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | secure => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | $self->conf->{cookieExpiration} | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | ? ( max_age => $self->conf->{cookieExpiration} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 1 | ▶ | : (), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | my $ref = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 129 | %{ $req->{sessionInfo} } | |||||||||||||||||||||||||||||||||||||||||||||
| 761 | ? $req->{sessionInfo} | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 129 | ▶ | : $req->userData | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 129 | $req->data->{newAuth} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 129 | my $whatToTrace = $ref->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 767 | 129 | ▶ | if ( !$whatToTrace ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 768 | $self->logger->error( "Could not obtain main identifier (" | ||||||||||||||||||||||||||||||||||||||||||||||
| 769 | . $self->conf->{whatToTrace} | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | . ") of user. Aborting authentication" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | return PE_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||
| 775 | $self->auditLog( | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 777 | message => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | "User $whatToTrace " | ||||||||||||||||||||||||||||||||||||||||||||||
| 779 | . " successfully authenticated at level $ref->{authenticationLevel}" | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | code => "AUTHENTICATED", | ||||||||||||||||||||||||||||||||||||||||||||||
| 782 | user => $whatToTrace, | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | level => $ref->{authenticationLevel}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 129 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 785 | 129 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 131 | ▶ | sub secondFactor { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
secondFactor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 131 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | 131 | return $self->_sfEngine->run($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 131 | ▶ | sub storeHistory { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
storeHistory: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 131 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 795 | 131 | ▶ | if ( $self->conf->{loginHistoryEnabled} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | $self->registerLogin($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 131 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||
| 801 | # This method returns the domain for a new cookie | ||||||||||||||||||||||||||||||||||||||||||||||
| 802 | # In modern browsers: | ||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # - an empty value means the cookie is only valid on the portal itself | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | # - in other situations, the cookie is sent to all subdomains | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # and a leading dot is added for compatibility | ||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 255 | ▶ | sub getCookieDomain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCookieDomain: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 255 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 255 | ▶ | if ( my $domain = $self->conf->{domain} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 254 | ▶ | if ( $domain eq '#PORTALDOMAIN#' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 3 | my $host = URI->new( $req->portal )->host; | |||||||||||||||||||||||||||||||||||||||||||||
| 812 | 3 | return $host =~ s/^([^\.]*)//r; | |||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 814 | elsif ( $domain eq '#PORTAL#' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1 | my $host = URI->new( $req->portal )->host; | |||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 | return ".$host"; | |||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 818 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 250 | return $domain =~ s/^(?!\.)/./r; | |||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 454 | 1; | |||||||||||||||||||||||||||||||||||||||||||||