##@file # SSL authentication backend file ##@class # SSL authentication backend class package Lemonldap::NG::Portal::AuthSSL; use strict; use Lemonldap::NG::Portal::Simple; use Lemonldap::NG::Portal::AuthNull; our $VERSION = '1.9.1'; our @ISA = qw(Lemonldap::NG::Portal::AuthNull); ## @apmethod int authInit() # Check if SSL environment variables are set. # @return Lemonldap::NG::Portal constant sub authInit { my $self = shift; $self->{SSLVar} ||= 'SSL_CLIENT_S_DN_Email'; PE_OK; } ## @apmethod int extractFormInfo() # Read username in SSL environment variables, or return an error # @return Lemonldap::NG::Portal constant sub extractFormInfo { my $self = shift; my $user = $self->https ? $ENV{ $self->{SSLVar} } : 0; if ($user) { $self->{user} = $user; return PE_OK; } elsif ( $ENV{SSL_CLIENT_S_DN} ) { $self->_sub( 'userError', "$self->{SSLVar} was not found in user certificate" ); return PE_BADCERTIFICATE; } else { $self->_sub( 'userError', 'No certificate found' ); return PE_CERTIFICATEREQUIRED; } } ## @apmethod int setAuthSessionInfo() # Set _user and authenticationLevel. # @return Lemonldap::NG::Portal constant sub setAuthSessionInfo { my $self = shift; # Store user certificate login for basic rules $self->{sessionInfo}->{'_user'} = $self->{'user'}; $self->{sessionInfo}->{authenticationLevel} = $self->{SSLAuthnLevel}; PE_OK; } ## @apmethod int authenticate() # Just test that SSL authentication has been done: job is done in # extractFormInfo() # @return Lemonldap::NG::Portal constant sub authenticate { my $self = shift; return ( $self->{user} and $ENV{ $self->{SSLVar} } ) ? PE_OK : PE_ERROR; } ## @method string getDisplayType # @return display type sub getDisplayType { return "logo"; } 1; __END__ =head1 NAME =encoding utf8 Lemonldap::NG::Portal::AuthSSL - Perl extension for building Lemonldap::NG compatible portals with SSL authentication. =head1 SYNOPSIS With Lemonldap::NG::Portal::SharedConf, set authentication field to "SSL" in configuration database. With Lemonldap::NG::Portal::Simple: use Lemonldap::NG::Portal::Simple; my $portal = new Lemonldap::NG::Portal::Simple( domain => 'example.com', globalStorage => 'Apache::Session::MySQL', globalStorageOptions => { DataSource => 'dbi:mysql:database', UserName => 'db_user', Password => 'db_password', TableName => 'sessions', }, ldapServer => 'ldap.domaine.com', securedCookie => 1, authentication => 'SSL', # SSLVar: field to search in client certificate # default: SSL_CLIENT_S_DN_Email the mail address SSLVar => 'SSL_CLIENT_S_DN_CN', ); if($portal->process()) { # Write here the menu with CGI methods. This page is displayed ONLY IF # the user was not redirected here. print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) print "..."; # or redirect the user to the menu print $portal->redirect( -uri => 'https://portal/menu'); } else { # If the user enters here, IT MEANS THAT YOUR SSL PARAMETERS ARE BAD print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) print "