Apache2-AuthZSympa

 view release on metacpan or  search on metacpan

lib/Apache2/AuthNSympa.pm  view on Meta::CPAN

package Apache2::AuthNSympa;

use warnings;
use strict;
use mod_perl2; 

BEGIN{
    require Apache2::Const;
    require Apache2::Access;
    require Apache2::SubRequest;
    require Apache2::RequestRec;
    require Apache2::RequestUtil;
    require Apache2::Response;
    require Apache2::Log;
    use APR::Const    -compile => qw(SUCCESS);
    Apache2::Const->import(-compile => 'HTTP_UNAUTHORIZED','OK', 'AUTH_REQUIRED', 'HTTP_INTERNAL_SERVER_ERROR','DECLINED');
    require SOAP::Lite;
    require Cache::Memcached;
    use Digest::MD5  qw(md5_hex);
}
=head1 NAME

Apache2::AuthNSympa - Authen module using sympa mailing lists server to authenticate

=head1 HOMEPAGE

L<http://sourcesup.cru.fr/projects/authsympa/>

=head1 VERSION

Version 0.5.0

=cut

our $VERSION = '0.5.0';

=head1 SYNOPSIS

Because it's difficult to have an up to date authentication backend, this module aims to authenticate against Sympa mailing lists server.

Sympa mailing lists server has got its own authentication system and can be queried over a SOAP interface.

It is based on a basic HTTP authentication (popup on client side). Once the user has authenticated, the REMOTE_USER environnement var contains the user email address. The authentication module implements a SOAP client that validates user credentials ...
Sample httpd.conf example:

    <Directory "/var/www/somwehere">
    AuthName SympaAuth
    AuthType Basic
    PerlSetVar SympaSoapServer http://mysympa.server/soap
    PerlSetVar MemcachedServer 10.219.213.24:11211
    PerlSetVar CacheExptime 3600 # in seconds, default 1800

    PerlAuthenHandler Apache2::AuthNSympa
    require valid-user

    </Directory>

=cut
sub handler {
    my $r = shift;
    
    ## Location Variables to connect to the good server
    my $SympaSoapServer = $r->dir_config('SympaSoapServer') || "localhost"; ## url of sympa soap server
    my $cacheserver = $r->dir_config('MemcachedServer') || "127.0.0.1:11211"; ## cache server
    my $exptime = $r->dir_config('CacheExptime') || 1800; ## 30 minutes of cache
    my $mail_user;
    my $response;
    my $result;
    my $AuthenType = "";
    my $auth_type = lc($r->auth_type());
    my $requires = $r->requires;
    my $location = $r->location();

    # verify if require valid-user is present, if not, authentication is not for this module
    for my $entry (@$requires){
	my $requirement = $entry->{requirement};
	if ($requirement eq 'valid-user' && $auth_type eq 'basic'){
	    $AuthenType = 'Sympa';
	    $r->log->debug("Apache2::AuthNSympa : require type '$requirement' for $location ","Sympa");
	    last;
	}else{
	    $r->log->debug("Apache2::AuthNSympa : require type '$requirement' for $location ","other");
	    next;
	}
    }

    if ($AuthenType ne "Sympa"){
	return Apache2::Const::OK;
    };
    

    ## instanciation of a new Soap::Lite object
    my $soap;
    my $soap_session;
    my $soap_res;
    my $soap_error=0;
    unless($soap = new SOAP::Lite()){
	$r->log_error("Apache2::AuthNSympa : Unable to create SOAP::Lite object while accessing $location");
	return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
    }

    ## if there is an error during soap request. $soap_error will be instanciated
    $soap->uri('urn:sympasoap');

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.949 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )