Lemonldap::NG::Portal::Main::Plugin - Base class for Lemonldap::NG::Portal modules (plugins, authentication modules,...).
package Lemonldap::NG::Portal::My::Plugin; use Mouse; 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) = @_; ... return $self->p->sendHtml($req, 'template', params => { WELCOME => 1 }); }
Lemonldap::NG::Portal::Main::Plugin provides many methods to easily write Lemonldap::NG addons.
init() is called for each plugin. If a plugin initialization fails (init() returns 0), the portal responds a 500 status code for each request.
Custom plugins can be inserted in portal by declaring them in lemonldap-ng.ini file, section [portal], key customPlugins:
lemonldap-ng.ini
[portal]
customPlugins
[portal] customPlugins = ::My::Plugin1, ::My::Plugin2
Plugins must be valid packages well found in @INC.
@INC
Plugins can declare unauthRoutes/authRoutes during initialization (= /path/info). Methods declared in this way must be declared in the plugin class. They will be called with $req argument. $req is the HTTP request. (See Lemonldap::NG::Portal::Main::Request). These methods must return a valid PSGI response. You can also use sendJSONresponse() or sendHtml() methods (see Lemonldap::NG::Common::PSGI).
Example:
sub init { my ($self) = @_; $self->addUnauthRoute( mypath => 'hello', [ 'GET', 'PUT' ] ); $self->addAuthRoute( mypath => 'welcome', [ 'GET', 'PUT' ] ); return 1; } sub hello { my ($self, $req) = @_; ... return $self->p->sendJSONresponse($req, { hello => 1 }); } sub welcome { my ($self, $req) = @_; ... return $self->p->sendHtml($req, 'template', params => { WELLCOME => 1 }); }
If you want to get a "protected application" behavior, you can use addAuthRouteWithRedirect. This methods calls addAuthRoute with given arguments and build a "unAuth" route that build a redirection after authentication.
A plugin which wants to be inserted in authentication process has to declare constants set with method name to run. Following entry points are available.
beforeAuth
betweenAuthAndData
sessionInfo
afterData
endAuth
authCancel
forAuthUser
beforeLogout
Note: methods inserted so must return a PE_* constant. See Lemonldap::NG::Portal::Main::Constants.
These entry points are not stored in $req->step but launched on the fly:
$req->step
afterSub
use constant afterSub => { getUser => 'mysub', } sub mysub { my ( $self ,$req ) = @_; # Do something return PE_OK; }
aroundSub
use constant aroundSub => { getUser => 'mysub', }; sub mysub { my ( $self, $sub, $req ) = @_; # Do something before my $ret = $sub->($req); # Do something after return $ret; }
Do not launch "getUser" but use the given $sub. This permits multiple plugins to use "aroundSub" in the same time.
$sub
hook
use constant hook => { oidcGenerateIDToken => 'addClaimToIDToken' }; sub addClaimToIDToken { my ( $self, $req, $payload, $rp ) = @_; $payload->{"id_token_hook"} = 1; return PE_OK; }
Logging is provided by $self->logger and $self->userLogger. The following rules must be applied:
http://lemonldap-ng.org
Use OW2 system to report bug or ask for features: https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues
Lemonldap::NG is available at http://forge.objectweb.org/project/showfiles.php?group_id=274
See COPYING file for details.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
To install Lemonldap::NG::Portal, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lemonldap::NG::Portal
CPAN shell
perl -MCPAN -e shell install Lemonldap::NG::Portal
For more information on module installation, please visit the detailed CPAN module installation guide.