ported Authentication::Store::Htpasswd to Authen::Htpasswd
David Kamholz [Wed, 9 Nov 2005 22:22:22 +0000 (22:22 +0000)]
lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm
lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm
t/backend.t
t/backend_md5.t

index c369ffe..c048347 100644 (file)
@@ -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 {
index dc2bd83..b5efe7c 100644 (file)
@@ -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__;
index bf47856..6834718 100644 (file)
@@ -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");
index 34c6e2c..c6f524a 100644 (file)
@@ -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");