HTTP-Server-Simple-Authen-0.04/0000755000175000017500000000000010362362066017555 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/t/0000755000175000017500000000000010362362066020020 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/t/00_compile.t0000644000175000017500000000013010362252317022123 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'HTTP::Server::Simple::Authen' } HTTP-Server-Simple-Authen-0.04/server.pl0000755000175000017500000000063210362337543021426 0ustar miyagawamiyagawa00000000000000#!/usr/bin/perl -w use strict; use lib 'lib'; package MyServer; use base qw( HTTP::Server::Simple::Authen HTTP::Server::Simple::CGI ); use Authen::Simple::Passwd; sub authen_handler { Authen::Simple::Passwd->new(passwd => '/etc/passwd'); } sub handle_request { my $self = shift; my $user = $self->authenticate(); return unless defined $user; print "Hello World"; } MyServer->new->run; HTTP-Server-Simple-Authen-0.04/MANIFEST0000644000175000017500000000027310362252331020701 0ustar miyagawamiyagawa00000000000000Changes lib/HTTP/Server/Simple/Authen.pm Makefile.PL MANIFEST This list of files server.pl t/00_compile.t META.yml Module meta-data (added by MakeMaker) HTTP-Server-Simple-Authen-0.04/META.yml0000644000175000017500000000070610362362066021031 0ustar miyagawamiyagawa00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: HTTP-Server-Simple-Authen version: 0.04 version_from: lib/HTTP/Server/Simple/Authen.pm installdirs: site requires: Authen::Simple: 0.04 HTTP::Server::Simple: 0.16 Test::More: 0.32 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 HTTP-Server-Simple-Authen-0.04/Changes0000644000175000017500000000113310362361726021050 0ustar miyagawamiyagawa00000000000000Revision history for Perl extension HTTP::Server::Simple::Authen 0.04 2006-01-15T05:55:25Z - NEXT is not needed anymore. 0.03 2006-01-15T03:17:31Z - Oops, handle_request() is typically subclassed, so prior versions are not subject to work. - Now authenticate() should be called explicitly from subclass. Hence some methods like needs_authen() are removed to be more DIY. 0.02 2006-01-14T21:34:25Z - Fixed a bug that you can't use 0 as username or password - Updated document 0.01 Sat Jan 14 17:15:45 2006 - original version HTTP-Server-Simple-Authen-0.04/lib/0000755000175000017500000000000010362362066020323 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/lib/HTTP/0000755000175000017500000000000010362362066021102 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/lib/HTTP/Server/0000755000175000017500000000000010362362066022350 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/lib/HTTP/Server/Simple/0000755000175000017500000000000010362362066023601 5ustar miyagawamiyagawa00000000000000HTTP-Server-Simple-Authen-0.04/lib/HTTP/Server/Simple/Authen.pm0000644000175000017500000000562610362362052025367 0ustar miyagawamiyagawa00000000000000package HTTP::Server::Simple::Authen; use strict; our $VERSION = '0.04'; use Carp; use MIME::Base64; sub do_authenticate { my $self = shift; if (($ENV{HTTP_AUTHORIZATION} || '') =~ /^Basic (.*?)$/) { my($user, $pass) = split /:/, (MIME::Base64::decode($1) || ':'); if ($self->authen_handler->authenticate($user, $pass)) { return $user; } } return; } sub authen_realm { "Authorized area" } sub authen_handler { my $class = ref(shift); Carp::croak("You have to override $class\::authen_handler to return Authen::Simple object"); } sub authenticate { my $self = shift; my $user = $self->do_authenticate(); unless (defined $user) { my $realm = $self->authen_realm(); print "HTTP/1.0 401\r\n"; print qq(WWW-Authenticate: Basic realm="$realm"\r\n\r\n); print "Authentication required."; return; } return $user; } 1; __END__ =head1 NAME HTTP::Server::Simple::Authen - Authentication plugin for HTTP::Server::Simple =head1 SYNOPSIS package MyServer; use base qw( HTTP::Server::Simple::Authen HTTP::Server::Simple::CGI); use Authen::Simple::Passwd; sub authen_handler { Authen::Simple::Passwd->new(passwd => '/etc/passwd'); } sub handle_request { my($self, $cgi) = @_; my $user = $self->authenticate or return; ... } MyServer->new->run(); =head1 DESCRIPTION HTTP::Server::Simple::Authen is an HTTP::Server::Simple plugin to allow HTTP authentication. Authentication scheme is pluggable and you can use whatever Authentication protocol that Authen::Simple supports. You can use C method whatever you want to authenticate the request. The method returns C<$username> taken from the request if the authentication is successful, and C otherwise. The code in L requires authentication for all the requests and behaves just the same as Apache's C. The following code will explain more about conditioning. sub handle_request { my($self, $cgi) = @_; if ($cgi->path_info =~ m!/foo/!) { my $user = $self->authenticate; return unless defined($user) && length($user) == 8; } ... } This means all the requests to URL C require to be authenticated, and usernames with 8 chars long are authorized. =head1 METHODS Your subclass has to override following methods to implement HTTP authentication. =over 4 =item authen_handler Should return a valid Authen::Simple instance to authenticate HTTP request (Required). =item authen_realm Returns a string for Authentication realm to be shown in the browser's dialog box. Defaults to 'Authorized area'. =back =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L =cut HTTP-Server-Simple-Authen-0.04/Makefile.PL0000644000175000017500000000044010362361652021525 0ustar miyagawamiyagawa00000000000000use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'HTTP::Server::Simple::Authen', 'VERSION_FROM' => 'lib/HTTP/Server/Simple/Authen.pm', # finds $VERSION 'PREREQ_PM' => { Test::More => 0.32, Authen::Simple => 0.04, HTTP::Server::Simple => 0.16, }, );