From 21d3efcc879261680e10310e67eeed7d8b9854c2 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Tue, 2 Aug 2016 13:52:29 +0000 Subject: [PATCH] #1044 in progress --- .../lib/Lemonldap/NG/Handler/Main/Run.pm | 4 ++-- .../lib/Lemonldap/NG/Handler/PSGI/Base.pm | 4 ++-- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 1 + .../lib/Lemonldap/NG/Portal/Main/Init.pm | 8 +++----- .../lib/Lemonldap/NG/Portal/Main/Menu.pm | 2 +- .../lib/Lemonldap/NG/Portal/Main/Process.pm | 8 ++++---- .../lib/Lemonldap/NG/Portal/Plugins/Notifications.pm | 12 ++++++++++-- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm index c052f1ce2..93dfae354 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm @@ -127,7 +127,7 @@ sub run { $class->set_user( $session->{ $class->tsv->{whatToTrace} } ); # AUTHORIZATION - return $class->forbidden($session) + return ( $class->forbidden($session), $session ) unless ( $class->grant( $session, $uri, $cond ) ); $class->updateStatus( 'OK', $session->{ $class->tsv->{whatToTrace} } ); @@ -155,7 +155,7 @@ sub run { $class->postOutputFilter( $session, $uri ); $class->postInputFilter( $session, $uri ); - return $class->OK; + return ( $class->OK, $session ); } elsif ( $protection == $class->UNPROTECT ) { diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/PSGI/Base.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/PSGI/Base.pm index 0668d4fa2..22b2d400e 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/PSGI/Base.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/PSGI/Base.pm @@ -95,9 +95,9 @@ sub status { # response is 200. sub _authAndTrace { my ( $self, $req, $noCall ) = @_; - my $res = $self->api->run( $req, $self->{rule} ); + my ( $res, $session ) = $self->api->run( $req, $self->{rule} ); $self->portal( $self->api->tsv->{portal}->() ); - $req->userData( $self->api->datas ) if ( $self->api->datas ); + $req->userData($session) if ($session); if ( $res < 300 ) { if ($noCall) { diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm index d41831a70..239eb94c1 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -368,6 +368,7 @@ sub buildHiddenForm { # Return skin name # @return skin name +# TODO: create property for skinRule sub getSkin { my ( $self, $req ) = @_; 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 a5977cbd2..2a9b1b356 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm @@ -224,9 +224,8 @@ sub reloadConf { if ( $self->conf->{$type} ) { for my $name ( sort keys %{ $self->conf->{$type} } ) { my $sub = - HANDLER->tsv->{jail}->jail_reval( "sub{return(" - . HANDLER->substitute( $self->conf->{$type}->{$name} ) - . ")}" ); + HANDLER->buildSub( + HANDLER->substitute( $self->conf->{$type}->{$name} ) ); if ($sub) { $self->{"_$type"}->{$name} = $sub; } @@ -241,8 +240,7 @@ sub reloadConf { } } $self->{_jsRedirect} = - HANDLER->tsv->{jail}->jail_reval( - "sub{return " . HANDLER->substitute( $self->conf->{jsRedirect} ) . "}" ) + HANDLER->buildSub( HANDLER->substitute( $self->conf->{jsRedirect} ) ) or $self->lmLog( 'jsRedirect returns an error: ' . HANDLER->tsv->{jail}->error, 'error' ); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm index 425250e5e..c3b2c1949 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm @@ -21,7 +21,7 @@ has menuModules => ( $_[0] ->p->lmLog( "Evaluate condition $cond for module $_", 'debug' ); my $tmp = - $_[0]->{p}->HANDLER->tsv->{jail}->jail_reval("sub{return $cond}"); + $_[0]->{p}->HANDLER->buildSub($cond); push @res, [ $_, $tmp ] if ($tmp); } return \@res; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm index 98fc0139d..d7d866cf5 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm @@ -46,7 +46,7 @@ sub restoreArgs { sub importHandlerDatas { my ( $self, $req ) = @_; - $req->{sessionInfo} = HANDLER->datas; + $req->{sessionInfo} = $req->userData; $req->id( $req->sessionInfo->{_session_id} ); $req->user( $req->sessionInfo->{ $self->conf->{whatToTrace} } ); PE_OK; @@ -279,7 +279,7 @@ sub setSessionInfo { $req->{sessionInfo}->{_url} = $req->{urldc}; # Share sessionInfo with underlying handler (needed for safe jail) - HANDLER->datas( $req->{sessionInfo} ); + $req->userData( $req->{sessionInfo} ); # Call UserDB setSessionInfo return $self->_userDB->setSessionInfo($req); @@ -290,7 +290,7 @@ sub setSessionInfo { sub setMacros { my ( $self, $req ) = @_; foreach ( sort keys %{ $self->_macros } ) { - $req->{sessionInfo}->{$_} = $self->_macros->{$_}->(); + $req->{sessionInfo}->{$_} = $self->_macros->{$_}->( $req->sessionInfo ); } PE_OK; } @@ -329,7 +329,7 @@ sub setPersistentSessionInfo { sub setLocalGroups { my ( $self, $req ) = @_; foreach ( sort keys %{ $self->_groups } ) { - if ( $self->_groups->{$_}->() ) { + if ( $self->_groups->{$_}->( $req->sessionInfo ) ) { $req->{sessionInfo}->{groups} .= $self->conf->{multiValuesSeparator} . $_; $req->{sessionInfo}->{hGroups}->{$_}->{name} = $_; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm index 87edf4131..dba7e0cce 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm @@ -226,7 +226,7 @@ sub getNotifBack { or return $self->sendError( $req, 'Unable to decrypt', 500 ); # Verify that session exists - $self->p->HANDLER->retrieveSession($id) + $req->userData( $self->p->HANDLER->retrieveSession($id) ) or return $self->sendError( $req, 'Unknown session', 401 ); # Restore datas @@ -283,6 +283,9 @@ sub getNotifBack { # Current pending notification has not been found in # request $result = $fileResult = 0; + $self->lmLog( + 'Current pending notification has not been found', + 'debug' ); next; } @@ -308,17 +311,22 @@ sub getNotifBack { # One pending notification has been found and not accepted, # restart process to display pending notifications # TODO: is it a good idea to launch all 'afterDatas' subs ? + $self->lmLog( + 'Pending notification has been found and not accepted', + 'debug' ); return $self->p->do( $req, $self->p->afterDatas ); } - # All pending notifications has been accepted, restore cookies and + # All pending notifications have been accepted, restore cookies and # launch 'controlUrl' to restore "urldc" using do() + $self->lmLog( 'All pending notifications have been accepted', 'debug' ); $self->rebuildCookies($req); $self->p->do( $req, ['controlUrl'] ); } else { # No notifications checked here, this entry point must not be called. # Redirecting to portal + $self->lmLog( 'No notifications checked', 'debug' ); $req->mustRedirect(1); $self->p->do( $req, [] ); }