PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|Authen|Simple|Apache.pm =

page 1 of 2



package Authen::Simple::Apache;

use strict;
use warnings;
use Authen::Simple::Adapter;

BEGIN {

    unless ( $INC{'mod_perl.pm'} ) {

        my $class = 'mod_perl';

        if ( exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} == 2 ) {
            $class = 'mod_perl2';
        }

        eval "require $class";
    }

    my @import = qw( OK HTTP_UNAUTHORIZED SERVER_ERROR );

    if ( $mod_perl::VERSION >= 1.999022 ) { # mod_perl 2.0.0 RC5
        require Apache2::RequestRec;
        require Apache2::RequestUtil;
        require Apache2::RequestIO;
        require Apache2::Log;
        require Apache2::Connection;
        require Apache2::Const;
        require Apache2::Access;
        Apache2::Const->import(@import);
     }
     elsif ( $mod_perl::VERSION >= 1.99 ) {
        require Apache::RequestRec;
        require Apache::RequestUtil;
        require Apache::RequestIO;
        require Apache::Log;
        require Apache::Connection;
        require Apache::Const;
        require Apache::Access;
        Apache::Const->import(@import);
    }
    else {
        require Apache;
        require Apache::Log;
        require Apache::Constants;
        Apache::Constants->import(@import);
    }
}

use constant MP2 => $mod_perl::VERSION >= 1.99 ? 1 : 0;

sub handler_mp1 ($$)     { &handle; }
sub handler_mp2 : method { &handle; }

*Authen::Simple::Adapter::handler = MP2 ? \&handler_mp2 : \&handler_mp1;

sub handle {
    my ( $class, $r ) = @_;

    my( $rc, $password ) = $r->get_basic_auth_pw;

    unless ( $rc == OK ) {
        return $rc;
    }

    my $username = MP2 ? $r->user : $r->connection->user;

    unless ( defined($username) && length($username) ) {
        $r->note_basic_auth_failure;
        $r->log->error("PerlAuthenHandler $class - No username was given.");
        return HTTP_UNAUTHORIZED;
    }

    unless ( defined($password) && length($password) ) {
        $r->note_basic_auth_failure;
        $r->log->error("PerlAuthenHandler $class - No password was given.");
        return HTTP_UNAUTHORIZED;
    }

    ( my $prefix = $class ) =~ s/://g;

    my %params = (
        log => $r->log
    );

    while ( my ( $option, $spec ) = each( %{ $class->options } ) ) {

        next if $option =~ /^(cache|callback|log)$/;

        my $required = $spec->{default} ? 0 : $spec->{optional} ? 0 : 1;
        my $config   = $prefix . '_' . $option;
        my $value    = $r->dir_config($config);

        if ( $required && !defined($value) ) {
            $r->log->error( "PerlAuthenHandler $class - Required parameter '$config' is not set." );
            return SERVER_ERROR;
        }

        $params{ $option } = $value if defined($value);
    }
=1=

= PAGE 1 = NEXT > |2

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.022759 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)