2016-01-25 19:03:46 +01:00
|
|
|
package Lemonldap::NG::Handler::PSGI::Router;
|
|
|
|
|
2021-01-23 18:57:24 +01:00
|
|
|
use strict;
|
2016-01-25 19:03:46 +01:00
|
|
|
use Mouse;
|
2017-02-11 08:47:22 +01:00
|
|
|
require Lemonldap::NG::Handler::PSGI::Main;
|
2016-01-25 19:03:46 +01:00
|
|
|
|
2017-02-11 08:47:22 +01:00
|
|
|
extends 'Lemonldap::NG::Handler::Lib::PSGI',
|
2016-01-25 19:03:46 +01:00
|
|
|
'Lemonldap::NG::Common::PSGI::Router';
|
|
|
|
|
2021-01-23 18:57:24 +01:00
|
|
|
our $VERSION = '2.0.11';
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
sub init {
|
2017-02-11 08:47:22 +01:00
|
|
|
$_[0]->api('Lemonldap::NG::Handler::PSGI::Main');
|
2016-04-04 10:39:26 +02:00
|
|
|
my $tmp = ( $_[0]->Lemonldap::NG::Common::PSGI::Router::init( $_[1] )
|
2017-02-11 08:47:22 +01:00
|
|
|
and $_[0]->Lemonldap::NG::Handler::Lib::PSGI::init( $_[1] ) );
|
2016-01-25 19:03:46 +01:00
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
=encoding utf8
|
|
|
|
|
|
|
|
Lemonldap::NG::Handler::PSGI::Router - Base library for protected REST APIs of
|
|
|
|
Lemonldap::NG.
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
package My::PSGI;
|
|
|
|
|
|
|
|
use base Lemonldap::NG::Handler::PSGI::Router;
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self,$args) = @_;
|
|
|
|
$self->protection('manager');
|
|
|
|
# See Lemonldap::NG::Common::PSGI::Router for more
|
|
|
|
|
|
|
|
# Declare REST routes (could be HTML templates or methods)
|
|
|
|
$self->addRoute ( 'index.html', undef, ['GET'] )
|
|
|
|
->addRoute ( books => { ':book' => 'booksMethod' }, ['GET', 'POST'] );
|
|
|
|
|
|
|
|
# Default route (ie: PATH_INFO == '/')
|
|
|
|
$self->defaultRoute('index.html');
|
|
|
|
|
|
|
|
# Return a boolean. If false, then error message has to be stored in
|
|
|
|
# $self->error
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub booksMethod {
|
|
|
|
my ( $self, $req, @otherPathInfo ) = @_;
|
|
|
|
|
2018-08-13 14:00:21 +02:00
|
|
|
# Will be called only if authorized
|
2016-01-25 19:03:46 +01:00
|
|
|
my $userId = $self->userId;
|
|
|
|
my $book = $req->params('book');
|
|
|
|
my $method = $req->method;
|
|
|
|
...
|
|
|
|
$self->sendJSONresponse(...);
|
|
|
|
}
|
|
|
|
|
|
|
|
This package could then be called as a CGI, using FastCGI,...
|
|
|
|
|
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use My::PSGI;
|
|
|
|
use Plack::Handler::FCGI; # or Plack::Handler::CGI
|
|
|
|
|
|
|
|
Plack::Handler::FCGI->new->run( My::PSGI->run() );
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This package provides base class for Lemonldap::NG protected REST API.
|
|
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
|
|
|
|
See L<Lemonldap::NG::Common::PSGI> for logging methods, content sending,...
|
|
|
|
|
|
|
|
=head2 Accessors
|
|
|
|
|
|
|
|
See L<Lemonldap::NG::Common::PSGI::Router> for inherited accessors.
|
|
|
|
|
|
|
|
=head3 protection
|
|
|
|
|
|
|
|
Level of protection. It can be one of:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item 'none': no protection
|
|
|
|
|
|
|
|
=item 'authenticate': all authenticated users are granted
|
|
|
|
|
|
|
|
=item 'manager': access is granted following Lemonldap::NG rules
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head2 Running methods
|
|
|
|
|
|
|
|
=head3 user
|
|
|
|
|
2018-07-05 22:56:16 +02:00
|
|
|
Returns user session data. If empty (no protection), returns:
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
{ _whatToTrace => 'anonymous' }
|
|
|
|
|
|
|
|
But if page is protected by server (Auth-Basic,...), it will return:
|
|
|
|
|
|
|
|
{ _whatToTrace => $REMOTE_USER }
|
|
|
|
|
|
|
|
=head3 UserId
|
|
|
|
|
|
|
|
Returns user()->{'_whatToTrace'}.
|
|
|
|
|
|
|
|
=head3 group
|
|
|
|
|
|
|
|
Returns a list of groups to which user belongs.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
L<http://lemonldap-ng.org/>, L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Handler>,
|
|
|
|
L<Plack>, L<PSGI>, L<Lemonldap::NG::Common::PSGI::Router>,
|
2019-04-03 14:15:16 +02:00
|
|
|
L<Lemonldap::NG::Common::PSGI::Request>, L<HTML::Template>,
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
=head1 AUTHORS
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
2017-01-04 21:31:36 +01:00
|
|
|
=item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
2017-11-11 14:06:23 +01:00
|
|
|
L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
2021-08-12 16:05:42 +02:00
|
|
|
L<https://lemonldap-ng.org/download>
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2017-01-04 21:31:36 +01:00
|
|
|
See COPYING file for details.
|
2016-01-25 19:03:46 +01:00
|
|
|
|
|
|
|
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 L<http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
=cut
|