From: David Kamholz Date: Wed, 9 Nov 2005 22:22:22 +0000 (+0000) Subject: ported Authentication::Store::Htpasswd to Authen::Htpasswd X-Git-Tag: v0.02~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Store-Htpasswd.git;a=commitdiff_plain;h=3e0bbcff879384a81c842abcede0dba6b4314790 ported Authentication::Store::Htpasswd to Authen::Htpasswd --- diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm index c369ffe..c048347 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm @@ -6,22 +6,20 @@ use base qw/Class::Accessor::Fast/; use strict; use warnings; -use Apache::Htpasswd; +use Authen::Htpasswd; use Catalyst::Plugin::Authentication::Store::Htpasswd::User; BEGIN { __PACKAGE__->mk_accessors(qw/file/) } sub new { - my ( $class, $file, @extra) = @_; + my ( $class, $file, %extra ) = @_; - bless { file => ( ref($file) ? $file : Apache::Htpasswd->new($file, @extra) ) }, - $class; + bless { file => ( ref $file ? $file : Authen::Htpasswd->new($file, \%extra) ) }, $class; } sub get_user { my ( $self, $id ) = @_; - Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $id, - $self->file ); + Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self->file->lookup_user($id) ); } sub user_supports { diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm index dc2bd83..b5efe7c 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm @@ -6,15 +6,12 @@ use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/; use strict; use warnings; -BEGIN { __PACKAGE__->mk_accessors(qw/file name/) } +BEGIN { __PACKAGE__->mk_accessors(qw/user/) } sub new { - my ( $class, $name, $file ) = @_; + my ( $class, $user ) = @_; - bless { - name => $name, - file => $file, - }, $class; + bless { user => $user }, $class; } sub supported_features { @@ -28,17 +25,12 @@ sub supported_features { sub check_password { my ( $self, $password ) = @_; - return $self->file->htCheckPassword( $self->name, $password ); + return $self->user->check_password( $password ); } sub roles { my $self = shift; - split( ",", $self->info_string ); -} - -sub info_string { - my $self = shift; - $self->file->fetchInfo( $self->name ); + split( ",", $self->user->extra_info ); } __PACKAGE__; diff --git a/t/backend.t b/t/backend.t index bf47856..6834718 100644 --- a/t/backend.t +++ b/t/backend.t @@ -12,16 +12,16 @@ my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Store::Htpasswd::B (undef, my $tmp) = tempfile(); -my $passwd = Apache::Htpasswd->new({ passwdFile => "$tmp" }); +my $passwd = Authen::Htpasswd->new($tmp); -$passwd->htpasswd("user", "s3cr3t"); +$passwd->add_user("user", "s3cr3t"); can_ok($m, "new"); isa_ok(my $o = $m->new( $passwd ), $m); can_ok($m, "file"); -isa_ok( $o->file, "Apache::Htpasswd"); +isa_ok( $o->file, "Authen::Htpasswd"); can_ok( $m, "user_supports"); diff --git a/t/backend_md5.t b/t/backend_md5.t index 34c6e2c..c6f524a 100644 --- a/t/backend_md5.t +++ b/t/backend_md5.t @@ -19,16 +19,16 @@ my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Store::Htpasswd::B (undef, my $tmp) = tempfile(); -my $passwd = Apache::Htpasswd->new({ passwdFile => "$tmp", UseMD5 => 1 }); +my $passwd = Authen::Htpasswd->new($tmp, { encrypt_hash => 'md5' }); -$passwd->htpasswd("user", "s3cr3t"); +$passwd->add_user("user", "s3cr3t"); can_ok($m, "new"); isa_ok(my $o = $m->new( $passwd ), $m); can_ok($m, "file"); -isa_ok( $o->file, "Apache::Htpasswd"); +isa_ok( $o->file, "Authen::Htpasswd"); can_ok( $m, "user_supports");