« blib/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/CrowdSec.pm »
| 1 | package Lemonldap::NG::Portal::Plugins::GlobalLogout; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use JSON qw(from_json to_json); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Lemonldap::NG::Common::Session 'id2storage'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | PE_OK | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | PE_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | PE_NOTOKEN | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | PE_TOKENEXPIRED | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | PE_SENDRESPONSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | PE_SLO_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | extends qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | Lemonldap::NG::Portal::Main::Plugin | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Lemonldap::NG::Portal::Lib::OtherSessions | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # INTERFACE | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use constant beforeLogout => 'run'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # INITIALIZATION | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | has rule => ( is => 'rw', default => sub { 0 } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | has ott => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | my $ott = | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $ott->timeout( $_[0]->conf->{formTimeout} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | return $ott; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $self->addAuthRoute( globallogout => 'globalLogout', [ 'POST', 'GET' ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Parse activation rule | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $self->rule( | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $self->p->buildRule( $self->conf->{globalLogoutRule}, 'globalLogout' ) | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | return 0 unless $self->rule; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # RUNNING METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Look for user active SSO sessions and suggest to close them | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=11 SCAR=31.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Skip if called from _triggerBackChannelLogout to avoid recursion | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | return PE_OK if $req->data->{_globalLogoutBCL}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $user = $req->userData->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Check activation rule | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | unless ( $self->rule->( $req, $req->userData ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->userLogger->info("GlobaLogout not allowed for $user"); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Looking for active sessions | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my $sessions = $self->activeSessions($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my $nbr = @{$sessions}; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | $self->logger->debug("GlobalLogout: $nbr session(s) found") if $nbr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | return PE_OK unless ( $nbr > 1 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Force GlobalLogout if timer is disabled | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | if ( $req->param('confirm') && $req->param('confirm') == 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$req->param("confirm") and $req->param("confirm") == 1 or not $self->conf->{"globalLogoutTimer"}
$req->param("confirm") and $req->param("confirm") == 1
MC/DC0%0/3
$req->param("confirm") and $req->param("confirm") == 1 or not $self->conf->{"globalLogoutTimer"}
$req->param("confirm")
$req->param("confirm") == 1
not $self->conf->{"globalLogoutTimer"}
Truth table20%1/5
A and B or not(C)
A= $req->param("confirm")B= $req->param("confirm") == 1C= not $self->conf->{"globalLogoutTimer"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | || !$self->conf->{globalLogoutTimer} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | my $msg = | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $self->conf->{globalLogoutTimer} | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | ? 'GlobalLogout: confirm parameter detected' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | : 'GlobalLogout: timer disabled'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $self->logger->debug($msg); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->userLogger->info("GlobalLogout: force global logout for $user"); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $nbr = $self->removeOtherActiveSessions( $req, $sessions ); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->userLogger->info("$nbr remaining session(s) removed"); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Return PE_SLO_ERROR if BCL failed, PE_OK otherwise | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $req->error || PE_OK; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$req->error || 0
MC/DC0%0/1
$req->error || 0
$req->error
Truth table0%0/2
A
A= $req->error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Prepare token | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | my $token = $self->ott->createToken( { | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | user => $user, | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sessions => to_json($sessions) | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Prepare form | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $self->logger->debug("Prepare global logout confirmation"); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | my $tmp = $self->p->sendHtml( | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 'globallogout', | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | params => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | FORM_ACTION => | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | $self->p->relativeUrl( $req, 'globallogout', { all => 1 } ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | SESSIONS => $sessions, | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | TOKEN => $token, | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | LOGIN => $user, | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | CUSTOMPRM => $self->conf->{globalLogoutCustomParam} | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | $req->response( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | $req->wantJSON | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ? $self->sendJSONresponse( $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { globalLogout => $nbr, confirmationRequired => 1 } ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | : $tmp | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | return PE_SENDRESPONSE; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub globalLogout { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
globalLogout: called CC=16 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $res = PE_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | if ( $req->param('all') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | if ( my $token = $req->param('token') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | if ( $token = $self->ott->getToken($token) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | my $storeId = | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $self->conf->{hashedSessionStore} | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ? id2storage( $req->userData->{_session_id} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | : $req->userData->{_session_id}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Read active sessions from token | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | my $sessions = eval { from_json( $token->{sessions} ) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | "GlobalLogout: bad encoding in OTT ($@)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $res = PE_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | my $as; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | my $user = $token->{user}; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | my $req_user = | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | $req->userData->{ $self->{conf}->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | if ( $req_user eq $user ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my $bclFailed = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | foreach (@$sessions) { | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # searchOn() returns sessions indexed by their | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # storage ID, then it is required to set hashStore | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # to 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $as = $self->p->getApacheSession( | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $_->{id}, hashStore => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->userLogger->info( | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | "GlobalLogout: session $_->{id} expired"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | unless ( $storeId eq $_->{id} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $self->userLogger->info( | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | "Remove \"$user\" session: $_->{id}"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Trigger back-channel logout before removal | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $req->data->{_globalLogoutBCL} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | my $bclRes = | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | $self->p->_triggerBackChannelLogout( $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $as->data ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | delete $req->data->{_globalLogoutBCL}; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | $bclFailed = 1 if $bclRes != PE_OK; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | $as->remove; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | $res = PE_SLO_ERROR if $bclFailed; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->userLogger->warn( | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | "GlobalLogout called with an invalid token: $req_user is NOT $user" | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $res = PE_TOKENEXPIRED; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->userLogger->error( | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | "GlobalLogout called with an expired token"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $res = PE_TOKENEXPIRED; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->userLogger->error('GlobalLogout called without token'); | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $res = PE_NOTOKEN; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Return error for blocking errors (not PE_SLO_ERROR) | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | return $self->p->doPE( $req, $res ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$res and $res != 56
MC/DC0%0/2
$res and $res != 56
$res
$res != 56
Truth table33%1/3
A and B
A= $resB= $res != 56
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | if $res && $res != PE_SLO_ERROR; | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | $self->userLogger->info("$count remaining session(s) removed"); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Set error for display if BCL failed (non-blocking warning) | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | my $ret = $self->p->do( $req, [ 'authLogout', 'deleteSession' ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | return $ret if $ret; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $ret = PE_SLO_ERROR if $res == PE_SLO_ERROR; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $req->error($ret); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | sub activeSessions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
activeSessions: called CC=10 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my $activeSessions = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | my $sessions = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | my $user = $req->userData->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | my $customParam = $self->conf->{globalLogoutCustomParam} || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->conf->{'globalLogoutCustomParam'} || ''
MC/DC0%0/1
$self->conf->{'globalLogoutCustomParam'} || ''
$self->conf->{'globalLogoutCustomParam'}
Truth table50%1/2
A
A= $self->conf->{'globalLogoutCustomParam'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Try to retrieve sessions from sessions DB | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | if ($user) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | $self->logger->debug('Try to retrieve sessions from DB'); | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | my $moduleOptions = $self->conf->{globalStorageOptions} || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->conf->{'globalStorageOptions'} || {}
MC/DC0%0/1
$self->conf->{'globalStorageOptions'} || {}
$self->conf->{'globalStorageOptions'}
Truth table50%1/2
A
A= $self->conf->{'globalStorageOptions'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $moduleOptions->{backend} = $self->conf->{globalStorage}; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | $self->logger->debug("Looking for \"$user\" sessions..."); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | $sessions = | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | $self->module->searchOn( $moduleOptions, $self->conf->{whatToTrace}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $user ); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | $self->logger->debug('Skip non-SSO session(s)...'); | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | my $other = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | foreach ( keys %$sessions ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | unless ( $sessions->{$_}->{_session_kind} eq 'SSO' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | delete $sessions->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $other++; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | $self->logger->info("$other non-SSO session(s) skipped") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | if $other; | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | $self->logger->debug('Build an array ref with sessions info...'); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | @$activeSessions = | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | my $epoch; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | my $regex = '^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$'; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | if ( $_->{startTime} =~ /$regex/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $epoch = timelocal( $6, $5, $4, $3, $2 - 1, $1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | $_->{startTime} = $epoch; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | delete $_->{startTime}; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | if ( $_->{updateTime} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | if ( $_->{updateTime} =~ /$regex/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | $epoch = timelocal( $6, $5, $4, $3, $2 - 1, $1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | $_->{updateTime} = $epoch; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | delete $_->{updateTime}; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | sort { $b->{startTime} cmp $a->{startTime} } map { | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | id => $_, | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | customParam => $sessions->{$_}->{$customParam}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ipAddr => $sessions->{$_}->{ipAddr}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | authLevel => $sessions->{$_}->{authenticationLevel}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | startTime => $sessions->{$_}->{_startTime}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | updateTime => $sessions->{$_}->{_updateTime} | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | } keys %$sessions; | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | return $activeSessions; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub removeOtherActiveSessions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeOtherActiveSessions: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ( $self, $req, $sessions ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $bclFailed = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $as; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | my $storeId = | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | $self->conf->{hashedSessionStore} | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ? id2storage( $req->userData->{_session_id} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | : $req->userData->{_session_id}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | foreach (@$sessions) { | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # searchOn() returns sessions indexed by their storage ID, then | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # it is required to set hashStore to 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | unless ( $as = $self->p->getApacheSession( $_->{id}, hashStore => 0, ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $self->userLogger->info("GlobalLogout: session $_->{id} expired"); | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | unless ( $storeId eq $_->{id} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->userLogger->info( | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | "Remove \"$req->userData->{ $self->conf->{whatToTrace} }\" session: $_->{id}" | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Trigger back-channel logout before removal | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $req->data->{_globalLogoutBCL} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $bclRes = $self->p->_triggerBackChannelLogout( $req, $as->data ); | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | delete $req->data->{_globalLogoutBCL}; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $bclFailed = 1 if $bclRes != PE_OK; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $as->remove; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # Set error if BCL failed (non-blocking warning) | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $req->error(PE_SLO_ERROR) if $bclFailed; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||