You can now write a custom portal plugin that will hook in the authentication process:
beforeAuth
: method called before authentication processbetweenAuthAndData
: method called after authentication and before setting “sessionInfo” provisionningafterData
: method called after “sessionInfo” provisionningendAuth
: method called when session is validated (after cookie build)authCancel
: method called when user click on “cancel” during auth processforAuthUser
: method called for already authenticated usersbeforeLogout
: method called before logoutThe plugin can also define new routes and call actions on them.
See also Lemonldap::NG::Portal::Main::Plugin
man page.
Create for example the MyPlugin module:
vi /usr/share/perl5/Lemonldap/NG/Portal/MyPlugin.pm
package Lemonldap::NG::Portal::MyPlugin; use Mouse; use Lemonldap::NG::Portal::Main::Constants; extends 'Lemonldap::NG::Portal::Main::Plugin'; use constant beforeAuth => 'verifyIP'; sub init { my ($self) = @_; $self->addUnauthRoute( mypath => 'hello', [ 'GET', 'PUT' ] ); $self->addAuthRoute( mypath => 'welcome', [ 'GET', 'PUT' ] ); return 1; } sub verifyIP { my ($self, $req) = @_; return PE_ERROR if($req->address !~ /^10/); return PE_OK; } sub hello { my ($self, $req) = @_; ... return $self->p->sendJSONresponse($req, { hello => 1 }); } sub welcome { my ($self, $req) = @_; my $userid = $req->user; $self->p->logger->debug("Call welcome for $userid"); ... return $self->p->sendHtml($req, 'template', params => { WELCOME => 1 }); } 1;
Declare the plugin in lemonldap-ng.ini:
vi /etc/lemonldap-ng/lemonldap-ng.ini
[portal] customPlugins = Lemonldap::NG::Portal::MyPlugin ;customPlugins = Lemonldap::NG::Portal::MyPlugin1, Lemonldap::NG::Portal::MyPlugin2, ...