From 1da367576ebe1ebd0353a65b10690e56d6ac936b Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 6 Jul 2018 16:07:25 +0200 Subject: [PATCH] Reinitialize choice when module failed (#1461) --- .../lib/Lemonldap/NG/Handler/Lib/Status.pm | 1 + .../lib/Lemonldap/NG/Portal/Auth/Choice.pm | 12 +++++++++--- .../lib/Lemonldap/NG/Portal/Main/Constants.pm | 2 +- .../lib/Lemonldap/NG/Portal/UserDB/Choice.pm | 12 +++++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/Status.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/Status.pm index 1bab6cd89..981685cb7 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/Status.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/Status.pm @@ -22,6 +22,7 @@ our $page_title = 'Lemonldap::NG statistics'; # @return Constant hash used to convert error codes into string. sub portalTab { return { + -5 => 'PORTAL_IDPCHOICE', -4 => 'PORTAL_SENDRESPONSE', -3 => 'PORTAL_INFO', -2 => 'PORTAL_REDIRECT', diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm index 0c464c3db..6234fca3f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm @@ -23,17 +23,23 @@ sub extractFormInfo { } return PE_FIRSTACCESS; } - return $req->data->{enabledMods0}->[0]->extractFormInfo($req); + my $res = $req->data->{enabledMods0}->[0]->extractFormInfo($req); + delete $req->pdata->{_choice} if ( $res > 0 ); + return $res; } sub authenticate { - return $_[1]->data->{enabledMods0}->[0]->authenticate( $_[1] ); + my $res = $_[1]->data->{enabledMods0}->[0]->authenticate( $_[1] ); + delete $_[1]->pdata->{_choice} if ( $res > 0 ); + return $res; } sub setAuthSessionInfo { my ( $self, $req ) = @_; $self->checkChoice($req) unless ( $req->data->{enabledMods0} ); - return $req->data->{enabledMods0}->[0]->setAuthSessionInfo($req); + my $res = $req->data->{enabledMods0}->[0]->setAuthSessionInfo($req); + delete $_[1]->pdata->{_choice} if ( $res > 0 ); + return $res; } sub authLogout { diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm index bc0642e6d..c1140eeaf 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm @@ -10,6 +10,7 @@ use constant { # Portal errors # Developers warning, do not use PE_INFO, it's reserved to autoRedirect. + PE_IDPCHOICE => -5, PE_SENDRESPONSE => -4, PE_INFO => -3, PE_REDIRECT => -2, @@ -90,7 +91,6 @@ use constant { PE_U2FFAILED => 83, PE_UNAUTHORIZEDPARTNER => 84, PE_RENEWSESSION => 85, - PE_IDPCHOICE => 86, }; # EXPORTER PARAMETERS diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm index 0291f5b57..33559058f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm @@ -19,16 +19,22 @@ sub init { sub getUser { my ( $self, $req, %args ) = @_; $self->checkChoice($req) or return PE_FIRSTACCESS; - return $req->data->{enabledMods1}->[0]->getUser( $req, %args ); + my $res = $req->data->{enabledMods1}->[0]->getUser( $req, %args ); + delete $req->pdata->{_choice} if ( $res > 0 ); + return $res; } sub setSessionInfo { - return $_[1]->data->{enabledMods1}->[0]->setSessionInfo( $_[1] ); + my $res = $_[1]->data->{enabledMods1}->[0]->setSessionInfo( $_[1] ); + delete $_[1]->pdata->{_choice} if ( $res > 0 ); + return $res; } sub setGroups { $_[0]->checkChoice( $_[1] ); - return $_[1]->data->{enabledMods1}->[0]->setGroups( $_[1] ); + my $res = $_[1]->data->{enabledMods1}->[0]->setGroups( $_[1] ); + delete $_[1]->pdata->{_choice} if ( $res > 0 ); + return $res; } 1;