2016-06-28 22:47:47 +02:00
|
|
|
# Base class for auth modules that call other auth modules (Choice,...)
|
|
|
|
#
|
|
|
|
# It fakes portal object to catch entry points and load them only if underlying
|
|
|
|
# auth module is activated
|
2016-06-29 21:34:36 +02:00
|
|
|
package Lemonldap::NG::Portal::Lib::Wrapper;
|
2016-06-28 22:47:47 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2016-06-28 23:27:57 +02:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
|
2016-06-28 22:47:47 +02:00
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
2018-02-19 22:11:43 +01:00
|
|
|
extends 'Lemonldap::NG::Portal::Main::Auth';
|
2016-06-28 22:47:47 +02:00
|
|
|
|
|
|
|
has availableModules => ( is => 'rw', default => sub { {} } );
|
|
|
|
|
2016-06-28 23:27:57 +02:00
|
|
|
# Wrappers for portal entry points: entry points are enabled only for active
|
|
|
|
# authentication module
|
|
|
|
#
|
|
|
|
# Note that "beforeAuth" can't be used here and must be wrapped in auth
|
|
|
|
# module
|
|
|
|
#
|
2018-07-05 22:56:16 +02:00
|
|
|
# Note also that auth module must store in $req->data->{enabledMods} a ref
|
2016-06-28 23:27:57 +02:00
|
|
|
# to each enabled underlying auth modules
|
2018-07-05 22:56:16 +02:00
|
|
|
sub betweenAuthAndData { '_betweenAuthAndData' }
|
|
|
|
sub afterData { '_afterData' }
|
2016-06-28 23:27:57 +02:00
|
|
|
sub forAuthUser { '_forAuthUser' }
|
|
|
|
sub beforeLogout { '_beforeLogout' }
|
|
|
|
|
2018-07-05 22:56:16 +02:00
|
|
|
sub _betweenAuthAndData { _wrapEntryPoint( @_, 'betweenAuthAndData' ); }
|
|
|
|
sub _afterData { _wrapEntryPoint( @_, 'afterData' ); }
|
2018-06-20 22:29:48 +02:00
|
|
|
sub _forAuthUser { _wrapEntryPoint( @_, 'forAuthUser', 1 ); }
|
|
|
|
sub _beforeLogout { _wrapEntryPoint( @_, 'beforeLogout', 1 ); }
|
2016-06-28 23:27:57 +02:00
|
|
|
|
|
|
|
sub _wrapEntryPoint {
|
2018-06-20 22:29:48 +02:00
|
|
|
my ( $self, $req, $name, $connected ) = @_;
|
|
|
|
my @t;
|
|
|
|
if ($connected) {
|
|
|
|
if ( my $mod = $req->userData->{ $self->sessionKey } ) {
|
|
|
|
if ( $self->modules->{$mod} ) {
|
|
|
|
@t = ( $self->modules->{$mod} );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->userLogger->error(
|
|
|
|
"Bad $self->{sessionKey} value in session ($name)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->userLogger->warn(
|
|
|
|
"Missing $self->{sessionKey} key in session");
|
|
|
|
}
|
|
|
|
}
|
2018-07-05 22:56:16 +02:00
|
|
|
elsif ( ref $req->data->{ "enabledMods" . $self->type } ) {
|
|
|
|
@t = @{ $req->data->{ "enabledMods" . $self->type } };
|
2018-06-21 13:58:42 +02:00
|
|
|
}
|
2018-06-20 22:29:48 +02:00
|
|
|
else {
|
2018-06-21 13:58:42 +02:00
|
|
|
$self->logger->debug(
|
|
|
|
"Unable to find enabledMods$self->{type} in this context: $name");
|
2018-06-20 22:29:48 +02:00
|
|
|
}
|
|
|
|
foreach (@t) {
|
2016-06-28 23:27:57 +02:00
|
|
|
if ( $_->can($name) ) {
|
|
|
|
|
|
|
|
# Launch sub and break loop if result isn't PE_OK (==0)
|
2018-06-20 22:29:48 +02:00
|
|
|
if ( my $sub = $_->$name() ) {
|
|
|
|
return $_->$sub($req);
|
2016-06-28 23:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-29 21:34:36 +02:00
|
|
|
# loadPlugin() fakes portal loadPlugin: it loads module but does not load
|
|
|
|
# entry points since they will be launched by ^ methods
|
2016-06-28 22:56:38 +02:00
|
|
|
sub loadPlugin {
|
2016-06-28 22:47:47 +02:00
|
|
|
my ( $self, $name, $module ) = @_;
|
2018-06-20 22:29:48 +02:00
|
|
|
my $obj = $self->p->can('loadModule')->( $self->p, $module );
|
2016-06-29 21:34:36 +02:00
|
|
|
( $obj and $obj->init ) or return 0;
|
2016-06-28 22:47:47 +02:00
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub AUTOLOAD {
|
2016-06-28 23:27:57 +02:00
|
|
|
no strict;
|
2016-06-28 22:47:47 +02:00
|
|
|
|
|
|
|
# Unknown methods are tried with real portal
|
|
|
|
my $self = shift;
|
|
|
|
my $sub = $AUTOLOAD;
|
|
|
|
$sub =~ s/.*:://;
|
|
|
|
if ( $self->p->can($sub) ) {
|
|
|
|
return $self->p->$sub(@_);
|
|
|
|
}
|
2018-07-05 22:05:24 +02:00
|
|
|
require Carp;
|
|
|
|
Carp::confess "Unknown method $sub";
|
2016-06-28 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|