From 8307161f0c42dac847517a655b3465cd6eb4f3a1 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Sat, 2 Jul 2016 08:51:00 +0000 Subject: [PATCH] Working on Choice (#595) --- .../lib/Lemonldap/NG/Portal/Auth/Choice.pm | 8 ++++---- .../lib/Lemonldap/NG/Portal/Lib/Choice.pm | 17 ++++++++++++----- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 2 +- .../lib/Lemonldap/NG/Portal/Main/Process.pm | 4 ++-- .../lib/Lemonldap/NG/Portal/Main/Request.pm | 2 +- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 4 ++-- .../lib/Lemonldap/NG/Portal/UserDB/Demo.pm | 1 - 7 files changed, 22 insertions(+), 16 deletions(-) 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 5300f9f89..a14c800e0 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm @@ -2,7 +2,7 @@ package Lemonldap::NG::Portal::Auth::Choice; use strict; use Mouse; -use Lemonldap::NG::Portal::Main::Constants qw(PE_FIRSTACCESS); +use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_FIRSTACCESS); extends 'Lemonldap::NG::Portal::Lib::Choice'; @@ -21,17 +21,17 @@ sub authenticate { } sub authForce { - $_[0]->checkChoice( $_[1] ); + $_[0]->checkChoice( $_[1] ) or return PE_OK; return $_[1]->datas->{enabledMods}->[0]->authForce( $_[1] ); } sub authLogout { - $_[0]->checkChoice( $_[1] ); + $_[0]->checkChoice( $_[1] ) or return PE_OK; return $_[1]->datas->{enabledMods}->[0]->authLogout( $_[1] ); } sub getDisplayType { - $_[0]->checkChoice( $_[1] ); + $_[0]->checkChoice( $_[1] ) or return PE_OK; return $_[1]->datas->{enabledMods}->[0]->getDisplayType( $_[1] ); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm index 1b1c25b8a..3ed5d5bb4 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm @@ -34,17 +34,21 @@ sub init { ); } else { - # error() is set by underlying module - return 0; + $self->lmLog("Choice: unable to load $name, disabling it: ".$self->error,'error'); + $self->error(''); } } + unless( keys %{$self->modules}) { + $self->error('Choice: no available modules found, aborting'); + return 0; + } return 1; } sub checkChoice { my ( $self, $req ) = @_; - return $req->sessionInfo->{_choice} if ( $req->sessionInfo->{_choice} ); - my $name = $req->param( $self->conf->{authChoiceParam} ) or return 0; + my $name = $req->sessionInfo->{_choice} || $req->param( $self->conf->{authChoiceParam} ) or return 0; + return $name if ( $req->datas->{enabledMods} ); unless ( defined $self->modules->{$name} ) { $self->lmLog( "Unknown choice '$name'", 'error' ); return 0; @@ -52,11 +56,14 @@ sub checkChoice { $req->sessionInfo->{_choice} = $name; $req->datas->{enabledMods} = [ $self->modules->{$name} ]; $self->p->_authentication->authnLevel("${name}AuthnLevel"); - return 1; + return $name; } sub name { my ( $self, $req, $type ) = @_; + unless($req) { + return 'Choice'; + } my $n = ref( $req->datas->{enableMods}->[0] ); $n =~ s/^Lemonldap::NG::Portal::(?:(?:UserDB|Auth)::)?//; return $n; 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 38eee3e0a..f3168361c 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -268,7 +268,7 @@ sub display { # Choose what form to display if not in a loop else { - my $displayType = $self->_authentication->getDisplayType(); + my $displayType = $self->_authentication->getDisplayType($req); $self->lmLog( "Display type $displayType ", 'debug' ); 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 17a1b4c47..ce18c20d7 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm @@ -120,7 +120,7 @@ sub checkLogout { sub authLogout { my ( $self, $req ) = @_; - return $self->_authentication->authLogout(@_); + return $self->_authentication->authLogout($req); } sub deleteSession { @@ -432,7 +432,7 @@ sub cookie { } sub _dump { - my($self, $variable) = @_; + my ( $self, $variable ) = @_; require Data::Dumper; $Data::Dumper::Indent = 0; $self->lmLog( "Dump: " . Data::Dumper::Dumper($variable), 'debug' ); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm index d4d6a90fa..b8370580f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm @@ -105,7 +105,7 @@ sub error_type { sub init { my ($self) = @_; - $self->{$_} = {} foreach(qw(datas customParameters));; + $self->{$_} = {} foreach(qw(datas customParameters sessionInfo));; $self->{$_} = [] foreach(qw(respCookies));; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index a84c1b493..2fac0d5c2 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -164,8 +164,8 @@ sub getModule { }->{$type} ) { - if ( $self->$mod->can('name') ) { - return $self->$mod->can('name')->($self->mod,$req,$type); + if ( my $sub = $self->$mod->can('name') ) { + return $sub->( $self->$mod, $req, $type ); } else { my $s = ref( $self->$mod ); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm index 60c640755..3d26e6237 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm @@ -21,7 +21,6 @@ sub init { unless ( $self->p->getModule( undef, 'auth' ) =~ /Demo/ ) { $self->p->error("Use UserDB::Demo only with Auth::Demo"); - return 0; } # Sample accounts from Doctor Who characters