Table of Contents

Protéger une application

Présentation

Une application peut connaître l'utilisateur connecté en utilisant :

Pour obtenir plus d'information sur l'utilisateur (nom, adresse de courriel, etc...), il faut lire les en-têtes HTTP.

If your application is based on Perl CGI package, you can simply replace CGI by Lemonldap::NG::Handler::CGI

Exemple de code

Exemples avec un en-tête configuré nommé 'Auth-User':

Perl

print "Connected user: ".$ENV{HTTP_AUTH_USER};

PHP

print "Connected user: ".$_SERVER["HTTP_AUTH_USER"];

CGI aito-protégée Perl

LL::NG now uses FastCGI instead of CGI, but you still can write your own protected CGI.

First create a PSGI module based on Lemonldap::NG::Handler:

  package My::PSGI;
 
  use base Lemonldap::NG::Handler;
 
  sub init {
    my ($self,$args) = @_;
    $self->protection('manager');
    # See Lemonldap::NG::Common::PSGI for more
    ...
    # Return a boolean. If false, then error message has to be stored in
    # $self->error
    return 1;
  }
 
  sub handler {
    my ( $self, $req ) = @_;
 
    # Will be called only if authorisated
    my $userId = $self->userId;
    ...
    $self->sendJSONresponse(...);
  }

Then call this module in a CGI script:

  #!/usr/bin/env perl
 
  use My::PSGI;
  use Plack::Handler::FCGI; # or Plack::Handler::CGI
 
  Plack::Handler::FCGI->new->run( My::PSGI->run() );

The protection parameter must be set when calling the init() method: