From ca16584d8b226b6ecd903ac07308064e6658de68 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Sun, 3 Apr 2016 16:27:22 +0000 Subject: [PATCH] #595 in progress... --- .../lib/Lemonldap/NG/Portal/Auth/Demo.pm | 2 +- .../lib/Lemonldap/NG/Portal/Auth/_WebForm.pm | 3 ++- .../lib/Lemonldap/NG/Portal/Main.pm | 1 - .../lib/Lemonldap/NG/Portal/Main/Init.pm | 15 ++++++++++++--- .../lib/Lemonldap/NG/Portal/Main/Process.pm | 4 ++-- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 8 ++++---- .../lib/Lemonldap/NG/Portal/UserDB/Demo.pm | 7 +++++-- lemonldap-ng-portal/t/01-AuthDemo.t | 2 +- lemonldap-ng-portal/t/lmConf-1.js | 1 + lemonldap-ng-portal/t/test-lib.pm | 2 +- 10 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Demo.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Demo.pm index 7b3154740..b530ef5b1 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Demo.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Demo.pm @@ -26,7 +26,7 @@ sub init { "Using demonstration mode, go in Manager to edit the configuration", 'warn' ); - PE_OK; + 1; } ## @apmethod int authenticate() diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm index 21ef9a372..206b6ee24 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm @@ -7,10 +7,11 @@ package Lemonldap::NG::Portal::Auth::_WebForm; use strict; use Mouse; +use Lemonldap::NG::Portal::Main::Constants; our $VERSION = '2.0.0'; -extends Lemonldap::NG::Portal::Main::Auth; +extends 'Lemonldap::NG::Portal::Main::Auth'; ## @apmethod int authInit() # Does nothing. diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm index ba1b703cd..7a5e784cf 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm @@ -6,7 +6,6 @@ use Mouse; our $VERSION = '2.0.0'; extends( - 'Lemonldap::NG::Handler::PSGI::Try', 'Lemonldap::NG::Portal::Main::Init', 'Lemonldap::NG::Portal::Main::Run', ); 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 52c47d9d6..3136080cc 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm @@ -13,9 +13,13 @@ use Mouse; use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Handler::Main::Reload qw/keepConf/; use Lemonldap::NG::Portal::Main::Plugins; +use Regexp::Assemble; our $VERSION = '2.0.0'; +extends 'Lemonldap::NG::Handler::PSGI::Try', + 'Lemonldap::NG::Portal::Main::Plugins'; + use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API'; # Configuration storage @@ -30,6 +34,9 @@ has _userDB => ( is => 'rw' ); has _macros => ( is => 'rw' ); has _groups => ( is => 'rw' ); +# TrustedDomain regexp +has trustedDomains => ( is => 'rw' ); + # Lists to store plugins entry-points has beforeAuth => ( is => 'rw', @@ -80,7 +87,7 @@ sub init { sub reloadConf { my ($self) = @_; - my $conf = HANDLER->lmConf->{cfgNum}; + my $conf = HANDLER->lmConf; # Delete keys that will be generated foreach my $key ( @@ -135,10 +142,12 @@ sub reloadConf { and $self->{"_$type"}->init ); } $self->_authentication->authnLevel( - $self->conf->{ $self->conf->authentication . "AuthnLevel" } ); + $self->conf->{ $self->conf->{authentication} . "AuthnLevel" } ); # Initialize trusted domain regexp - if ( $self->conf->{trustedDomains} =~ /^\s*\*\s*$/ ) { + if ( $self->conf->{trustedDomains} + and $self->conf->{trustedDomains} =~ /^\s*\*\s*$/ ) + { $self->trustedDomains(qr#^https?://#); } else { 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 d7fd80d65..df72fb789 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm @@ -121,8 +121,8 @@ sub setSessionInfo { my ( $self, $req ) = @_; # Get the current user module - $req->{sessionInfo}->{_auth} = $self->getModule("auth"); - $req->{sessionInfo}->{_userDB} = $self->getModule("user"); + $req->{sessionInfo}->{_auth} = $self->getModule( $req, "auth" ); + $req->{sessionInfo}->{_userDB} = $self->getModule( $req, "user" ); # Store IP address from remote address or X-FORWARDED-FOR header $req->{sessionInfo}->{ipAddr} = $req->remote_ip; 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 c6ad2a7e2..2a08df4c5 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -66,19 +66,19 @@ sub pleaseAuth { sub login { my ( $self, $req ) = @_; - return $req->do( + return $self->do( $req, [ 'controlUrl', @{ $self->beforeAuth }, &authProcess, @{ $self->betweenAuthAndDatas }, - &sessionDatas, @{ $self->afterdatas }, + &sessionDatas, @{ $self->afterDatas }, ] ); } sub postLogin { my ( $self, $req ) = @_; - return $req->do( + return $self->do( $req, [ 'restoreArgs', 'controlUrl', @@ -91,7 +91,7 @@ sub postLogin { sub authenticatedRequest { my ( $self, $req ) = @_; - return $req->do( $req, $self->forAuthUser ); + return $self->do( $req, $self->forAuthUser ); } # RUNNING METHODS 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 14a8fb3c1..b716d4381 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm @@ -6,8 +6,11 @@ package Lemonldap::NG::Portal::UserDB::Demo; use strict; +use Mouse; use Lemonldap::NG::Portal::Main::Constants; +extends Lemonldap::NG::Portal::Main::Module; + our $VERSION = '2.0.0'; ## @apmethod int userDBInit() @@ -16,7 +19,7 @@ our $VERSION = '2.0.0'; sub init { my $self = shift; - unless ( $self->get_module('auth') =~ /^Demo/ ) { + unless ( $self->p->getModule( undef, 'auth' ) =~ /^Demo/ ) { $self->lmLog( "Use UserDBDemo only with AuthDemo", 'error' ); return PE_ERROR; } @@ -40,7 +43,7 @@ sub init { }, }; - PE_OK; + 1; } ## @apmethod int getUser() diff --git a/lemonldap-ng-portal/t/01-AuthDemo.t b/lemonldap-ng-portal/t/01-AuthDemo.t index ff100f805..06573f8a5 100644 --- a/lemonldap-ng-portal/t/01-AuthDemo.t +++ b/lemonldap-ng-portal/t/01-AuthDemo.t @@ -3,6 +3,6 @@ use strict; require 't/test-lib.pm'; -print STDERR Dumper(&client); +print STDERR Dumper(&client->_get('/')); done_testing( count() ); diff --git a/lemonldap-ng-portal/t/lmConf-1.js b/lemonldap-ng-portal/t/lmConf-1.js index fe9eecd9e..e0d786d87 100644 --- a/lemonldap-ng-portal/t/lmConf-1.js +++ b/lemonldap-ng-portal/t/lmConf-1.js @@ -51,6 +51,7 @@ "macros": { "_whatToTrace": "$_auth eq 'SAML' ? \"$_user\\@$_idpConfKey\" : \"$_user\"" }, + "notifications": 0, "portal": "http://auth.example.com/", "reloadUrls": {}, "userDB": "Demo", diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm index 2def5738a..5e154be4f 100644 --- a/lemonldap-ng-portal/t/test-lib.pm +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -16,7 +16,7 @@ ok( app => Lemonldap::NG::Portal::Main->run( { configStorage => { type => 'File', dirName => 't' }, - logLevel => 'warn', + logLevel => 'debug', cookieName => 'lemonldap', securedCookie => 0, https => 0,