From a82939ee4b15f4ccea72c203802ce21bcc2cdcdf Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Wed, 3 Oct 2018 22:22:15 +0200 Subject: [PATCH] WIP - Append PortalForceAuthn plugin (#1507) --- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 15 ++++++++++++++ .../NG/Portal/Plugins/PortalForceAuthn.pm | 13 ++++++++---- .../templates/bootstrap/updatesession.tpl | 20 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 lemonldap-ng-portal/site/templates/bootstrap/updatesession.tpl 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 79254092a..da1e9d7d0 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -217,6 +217,21 @@ sub display { ); } + elsif ( $req->error == PE_MUSTAUTHN ) { + $skinfile = 'updatesession'; + %templateParams = ( + MSG => 'PE87', + CONFIRMKEY => $self->stamp, + PORTAL => $self->conf->{portal}, + URL => $req->data->{_url}, + ( + $req->data->{customScript} + ? ( CUSTOM_SCRIPT => $req->data->{customScript} ) + : () + ), + ); + } + # 2.3 Case : user authenticated but an error was returned (bad url,...) elsif ( $req->noLoginDisplay diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/PortalForceAuthn.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/PortalForceAuthn.pm index ab13bf0e4..298983efa 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/PortalForceAuthn.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/PortalForceAuthn.pm @@ -3,7 +3,7 @@ package Lemonldap::NG::Portal::Plugins::PortalForceAuthn; use Data::Dumper; use strict; use Mouse; -use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_MUSTREAUTHN); +use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_MUSTAUTHN); our $VERSION = '2.0.0'; @@ -19,16 +19,21 @@ sub init {1} sub run { my ( $self, $req ) = @_; - my $portalURL = $self->conf->{portal}; - my $HTTP_HOST = $req->env->{HTTP_HOST}; + $self->logger->debug( "********* " . Dumper($req) ); + my $portalURL = $self->conf->{portal} || ''; + my $HTTP_HOST = $req->env->{HTTP_HOST} || ''; + my $referer = $req->env->{HTTP_REFERER} || ''; + $self->logger->debug( "Portal URL -> " . Dumper($portalURL) ); $self->logger->debug( "HTTP_HOST -> " . Dumper($HTTP_HOST) ); + if ( $req->env->{HTTP_HOST} and $portalURL =~ qr#\Q$HTTP_HOST# ) { my $delta = time() - $req->{sessionInfo}->{_utime}; $self->logger->debug( "Delta with last Authn -> " . $delta ); + $delta <= $self->conf->{portalForceAuthnInterval} ? return PE_OK - : return PE_MUSTREAUTHN; + : return PE_MUSTAUTHN; } } diff --git a/lemonldap-ng-portal/site/templates/bootstrap/updatesession.tpl b/lemonldap-ng-portal/site/templates/bootstrap/updatesession.tpl new file mode 100644 index 000000000..da9b8ead2 --- /dev/null +++ b/lemonldap-ng-portal/site/templates/bootstrap/updatesession.tpl @@ -0,0 +1,20 @@ + + +
+ +
">
+ +
+ "> + "> +
+ +
+
+ +
+ +