Lemonldap::NG::Handler::PSGI::Router(3pm)

Lemonldap::NG::Handler::PSGI::Router3pm

Base library for protected rest apis of lemonldap::ng.

Usage

  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 ) = @_;
    # Will be called only if authorized
    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() );

Overview

This package provides base class for Lemonldap::NG protected REST API.

Methods

See Lemonldap::NG::Common::PSGI for logging methods, content sending,...

Accessors

See Lemonldap::NG::Common::PSGI::Router for inherited accessors.

protection

Level of protection. It can be one of:

'none': no protection
'authenticate': all authenticated users are granted
'manager': access is granted following Lemonldap::NG rules

Running methods

user

Returns user session data. If empty (no protection), returns:

  { _whatToTrace => 'anonymous' }

But if page is protected by server (Auth-Basic,...), it will return:

  { _whatToTrace => $REMOTE_USER }

UserId

Returns user()->{'_whatToTrace'}.

group

Returns a list of groups to which user belongs.

Bug report

Use OW2 system to report bug or ask for features: <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>

Download

Lemonldap::NG is available at <https://lemonldap-ng.org/download>

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

Authors

LemonLDAP::NG team <http://lemonldap-ng.org/team>

From liblemonldap-ng-handler-perl 2.21.2+ds-1+deb13u3 in Debian 13 (Trixie). Parsed by carta from the page's man source.