diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm index 9040bc417..8384ea8c4 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm @@ -85,7 +85,11 @@ sub storeEnvAndCheckGateway { $self->logger->debug( "Gateway mode requested, redirect without authentication"); $req->response( [ 302, [ Location => $service ], [] ] ); - $req->pdata( {} ); + for my $s ( $self->ipath, $self->ipath . 'Path' ) { + $self->logger->debug("Removing $s from pdata") + if delete $req->pdata->{$s}; + } + return PE_SENDRESPONSE; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm index c6bb1856e..c0a356cfa 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm @@ -140,24 +140,24 @@ sub init { # psgi.js ->addUnauthRoute( 'psgi.js' => 'sendJs', ['GET'] ) - ->addAuthRoute( 'psgi.js' => 'sendJs', ['GET'] ) + ->addAuthRoute( 'psgi.js' => 'sendJs', ['GET'] ) # portal.css ->addUnauthRoute( 'portal.css' => 'sendCss', ['GET'] ) - ->addAuthRoute( 'portal.css' => 'sendCss', ['GET'] ) + ->addAuthRoute( 'portal.css' => 'sendCss', ['GET'] ) # lmerror ->addUnauthRoute( lmerror => { ':code' => 'lmError' }, ['GET'] ) - ->addAuthRoute( lmerror => { ':code' => 'lmError' }, ['GET'] ) + ->addAuthRoute( lmerror => { ':code' => 'lmError' }, ['GET'] ) # Core REST API - ->addUnauthRoute( ping => 'pleaseAuth', ['GET'] ) + ->addUnauthRoute( ping => 'pleaseAuth', ['GET'] ) ->addAuthRoute( ping => 'authenticated', ['GET'] ) # Refresh session ->addAuthRoute( refresh => 'refresh', ['GET'] ) - ->addAuthRoute( '*' => 'corsPreflight', ['OPTIONS'] ) + ->addAuthRoute( '*' => 'corsPreflight', ['OPTIONS'] ) ->addUnauthRoute( '*' => 'corsPreflight', ['OPTIONS'] ) # Logout @@ -356,11 +356,18 @@ sub reloadConf { # Clean $req->pdata after authentication push @{ $self->endAuth }, sub { - unless ( $_[0]->pdata->{keepPdata} ) { - $self->logger->debug('Cleaning pdata'); - $_[0]->pdata( {} ); - $self->userLogger->notice( $_[0]->user . ' connected' ) - if $_[0]->user; + my $tmp = $_[0]->pdata->{keepPdata} //= []; + foreach my $k ( keys %{ $_[0]->pdata } ) { + unless ( grep { $_ eq $k } @$tmp ) { + $self->logger->debug("Removing $k from pdata"); + delete $_[0]->pdata->{$k}; + } + } + $self->userLogger->notice( $_[0]->user . ' connected' ) if $_[0]->user; + if (@$tmp) { + $self->logger->debug( + 'Add ' . join( ',', @$tmp ) . ' in keepPdata' ); + $_[0]->pdata->{keepPdata} = $tmp; } return PE_OK; }; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Issuer.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Issuer.pm index f9ebdc31b..0f69adc42 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Issuer.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Issuer.pm @@ -34,9 +34,10 @@ has _ott => ( is => 'rw', lazy => 1, default => sub { - my $ott = $_[0]->{p}->loadModule('::Lib::OneTimeToken'); - my $timeout = $_[0]->{conf}->{issuersTimeout} // $_[0]->{conf}->{formTimeout}; - $ott->timeout( $timeout ); + my $ott = $_[0]->{p}->loadModule('::Lib::OneTimeToken'); + my $timeout = $_[0]->{conf}->{issuersTimeout} + // $_[0]->{conf}->{formTimeout}; + $ott->timeout($timeout); return $ott; } ); @@ -86,7 +87,9 @@ sub _redirect { $self->logger->debug('Processing _redirect'); $ir = $req->pdata->{ $self->ipath } ||= $self->storeRequest($req); $req->pdata->{ $self->ipath . 'Path' } = \@path; - $req->pdata->{keepPdata} = 1; + $self->logger->debug( + 'Add ' . $self->ipath . ', ' . $self->ipath . 'Path in keepPdata' ); + push @{ $req->pdata->{keepPdata} }, $self->ipath, $self->ipath . 'Path'; $req->{urldc} = $self->conf->{portal} . '/' . $self->path; } else { @@ -111,8 +114,7 @@ sub _redirect { # Restore urldc if auth doesn't need to dial with browser $self->restoreRequest( $req, $ir ); - delete $req->pdata->{ $self->ipath }; - delete $req->pdata->{ $self->ipath . 'Path' }; + $self->cleanPdata($req); return $self->run( @_, @path ); } : () @@ -135,8 +137,9 @@ sub _forAuthUser { # Clean pdata: keepPdata has been set, so pdata must be cleaned here $self->logger->debug('Cleaning pdata'); - $req->pdata( {} ); - $req->urlNotBase64(1) if ( ref($self) =~ /::CAS$/ ); + $self->cleanPdata($req); + + $req->maybeNotBase64(1) if ( ref($self) =~ /::CAS$/ ); $req->mustRedirect(1); return $self->p->do( $req, @@ -151,6 +154,27 @@ sub _forAuthUser { ); } +sub cleanPdata { + my ( $self, $req ) = @_; + for my $s ( $self->ipath, $self->ipath . 'Path' ) { + if ( $req->pdata->{$s} ) { + $self->logger->debug("Removing $s key from pdata"); + delete $req->pdata->{$s}; + } + } + if ( $req->pdata->{keepPdata} and ref $req->pdata->{keepPdata} ) { + @{ $req->pdata->{keepPdata} } = + grep { + $_ ne $self->ipath + and $_ ne $self->ipath . 'Path' + ? 1 + : ( $self->logger->debug("Removing $_ from keepPdata") and 0 ) + } @{ $req->pdata->{keepPdata} }; + delete $req->pdata->{keepPdata} + unless ( @{ $req->pdata->{keepPdata} } ); + } +} + sub storeRequest { my ( $self, $req ) = @_; $self->logger->debug('Store issuer request'); @@ -191,7 +215,7 @@ qq'