lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Wrapper.pm

70 lines
1.9 KiB
Perl
Raw Normal View History

# 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
package Lemonldap::NG::Portal::Auth::Wrapper;
use strict;
use Mouse;
2016-06-28 23:27:57 +02:00
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Portal::Auth::Base';
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
#
# Note also that auth module must store in $req->datas->{enabledMods} a ref
# to each enabled underlying auth modules
sub betweenAuthAndDatas { '_betweenAuthAndDatas' }
sub afterDatas { '_afterDatas' }
sub forAuthUser { '_forAuthUser' }
sub beforeLogout { '_beforeLogout' }
sub _betweenAuthAndDatas { _wrapEntryPoint( @_, 'betweenAuthAndDatas' ); }
sub _afterDatas { _wrapEntryPoint( @_, 'afterDatas' ); }
sub _forAuthUser { _wrapEntryPoint( @_, 'forAuthUser' ); }
sub _beforeLogout { _wrapEntryPoint( @_, 'beforeLogout' ); }
sub _wrapEntryPoint {
my ( $self, $req, $name ) = @_;
foreach ( @{ $req->datas->{enabledMods} } ) {
if ( $_->can($name) ) {
# Launch sub and break loop if result isn't PE_OK (==0)
if ( my $r = $_->$name($req) ) {
return $r;
}
}
}
return PE_OK;
}
# loadModule() fakes portal loadModule()
sub loadPlugin {
my ( $self, $name, $module ) = @_;
my $obj = $self->p->can('loadPlugin')->( $self, $module );
return $obj;
}
sub AUTOLOAD {
2016-06-28 23:27:57 +02:00
no strict;
# Unknown methods are tried with real portal
my $self = shift;
my $sub = $AUTOLOAD;
$sub =~ s/.*:://;
if ( $self->p->can($sub) ) {
return $self->p->$sub(@_);
}
die "Unknown method $sub";
}
1;