2015-05-14 08:44:38 +02:00
|
|
|
package Lemonldap::NG::Handler::PSGI;
|
|
|
|
|
|
|
|
use 5.10.0;
|
|
|
|
use Mouse;
|
2016-03-17 23:19:44 +01:00
|
|
|
use Lemonldap::NG::Handler::PSGI::API;
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2016-01-31 23:53:23 +01:00
|
|
|
extends 'Lemonldap::NG::Handler::PSGI::Base', 'Lemonldap::NG::Common::PSGI';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2016-03-17 23:19:44 +01:00
|
|
|
our $VERSION = '2.0.0';
|
2015-12-25 11:46:11 +01:00
|
|
|
|
2016-01-25 06:54:55 +01:00
|
|
|
sub init {
|
2016-03-17 23:19:44 +01:00
|
|
|
$_[0]->api('Lemonldap::NG::Handler::PSGI::API') unless ( $_[0]->api );
|
2016-01-25 19:03:46 +01:00
|
|
|
my $tmp = $_[0]->Lemonldap::NG::Common::PSGI::init( $_[1] )
|
|
|
|
and $_[0]->Lemonldap::NG::Handler::PSGI::Base::init( $_[1] );
|
|
|
|
return $tmp;
|
2015-12-10 13:28:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
1;
|
2015-12-25 11:46:11 +01:00
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
=encoding utf8
|
|
|
|
|
2016-01-25 19:03:46 +01:00
|
|
|
Lemonldap::NG::Handler::PSGI - Base library for protected PSGI applications.
|
2015-12-25 11:46:11 +01:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
package My::PSGI;
|
|
|
|
|
|
|
|
use base Lemonldap::NG::Handler;
|
|
|
|
|
|
|
|
sub init {
|
2016-01-02 10:29:05 +01:00
|
|
|
my ($self,$args) = @_;
|
2015-12-25 11:46:11 +01:00
|
|
|
$self->protection('manager');
|
|
|
|
# See Lemonldap::NG::Common::PSGI for more
|
2016-01-25 19:03:46 +01:00
|
|
|
...
|
2015-12-25 11:46:11 +01:00
|
|
|
# Return a boolean. If false, then error message has to be stored in
|
|
|
|
# $self->error
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-11 07:00:35 +01:00
|
|
|
sub handler {
|
2016-01-25 19:03:46 +01:00
|
|
|
my ( $self, $req ) = @_;
|
2015-12-25 11:46:11 +01:00
|
|
|
|
|
|
|
# Will be called only if authorisated
|
|
|
|
my $userId = $self->userId;
|
|
|
|
...
|
|
|
|
$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
|
|
|
|
|
|
|
|
Returns user session datas. If empty (no protection), returns:
|
|
|
|
|
|
|
|
{ _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>,
|
|
|
|
L<Lemonldap::NG::Common::PSGI::Request>, L<HTML::Template>,
|
|
|
|
|
|
|
|
=head1 AUTHORS
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
|
|
|
|
|
|
|
=item François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt>
|
|
|
|
|
|
|
|
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
|
|
|
=item Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt>
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
|
|
|
L<http://jira.ow2.org>
|
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
2016-01-21 22:15:19 +01:00
|
|
|
=item Copyright (C) 2015-2016 by Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
2015-12-25 11:46:11 +01:00
|
|
|
|
2016-01-21 22:15:19 +01:00
|
|
|
=item Copyright (C) 2015-2016 by Clément Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
2015-12-25 11:46:22 +01:00
|
|
|
|
2015-12-25 11:46:11 +01:00
|
|
|
=back
|
|
|
|
|
|
|
|
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
|