Checking in changes prior to tagging of version 1.009. Changelog diff is: v1.009
Tomas Doran [Sun, 4 Jan 2009 21:32:13 +0000 (21:32 +0000)]
=== Changes
==================================================================
--- Changes (revision 9903)
+++ Changes (local)
@@ -1,3 +1,10 @@
+1.009  2009-01-04
+   - Remove use of _config accessor, which I'd stupidly cargo-culted.
+     As we don't ever run in auth back-compat mode, we can store
+     everything in instance data without worrying about conflicts.
+     Note however - have to keep the accessor itself so that our
+     parent class (which is still stupid and uses it) continues to work.
+
1.008  2008-12-10
- Fix issue with the user not being authenticated into the correct
realm, by not calling $c->set_authenticated ourselves, but instead

Changes
lib/Catalyst/Authentication/Credential/HTTP.pm
t/basic.t

diff --git a/Changes b/Changes
index ab512be..0a1cf97 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,10 @@
+1.009  2009-01-04
+   - Remove use of _config accessor, which I'd stupidly cargo-culted. 
+     As we don't ever run in auth back-compat mode, we can store 
+     everything in instance data without worrying about conflicts.
+     Note however - have to keep the accessor itself so that our
+     parent class (which is still stupid and uses it) continues to work.
+
 1.008  2008-12-10
   - Fix issue with the user not being authenticated into the correct 
     realm, by not calling $c->set_authenticated ourselves, but instead
index 350cfd1..ebc3c09 100644 (file)
@@ -9,17 +9,25 @@ use URI::Escape    ();
 use Catalyst       ();
 use Digest::MD5    ();
 
-BEGIN {
-    __PACKAGE__->mk_accessors(qw/_config realm/);
-}
-
-our $VERSION = '1.008';
+__PACKAGE__->mk_accessors(qw/
+    _config 
+    authorization_required_message 
+    password_field 
+    username_field 
+    type 
+    realm 
+    algorithm 
+    use_uri_for
+/);
+
+our $VERSION = '1.009';
 
 sub new {
     my ($class, $config, $app, $realm) = @_;
     
     $config->{username_field} ||= 'username';
-    my $self = { _config => $config, _debug => $app->debug };
+    # _config is shity back-compat with our base class.
+    my $self = { %$config, _config => $config, _debug => $app->debug };
     bless $self, $class;
     
     $self->realm($realm);
@@ -30,11 +38,12 @@ sub new {
 
 sub init {
     my ($self) = @_;
-    my $type = $self->_config->{'type'} ||= 'any';
+    my $type = $self->type || 'any';
     
     if (!grep /$type/, ('basic', 'digest', 'any')) {
         Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported authentication type: " . $type);
     }
+    $self->type($type);
 }
 
 sub authenticate {
@@ -59,11 +68,11 @@ sub authenticate_basic {
     my $headers = $c->req->headers;
 
     if ( my ( $username, $password ) = $headers->authorization_basic ) {
-           my $user_obj = $realm->find_user( { $self->_config->{username_field} => $username }, $c);
+           my $user_obj = $realm->find_user( { $self->username_field => $username }, $c);
            if (ref($user_obj)) {
             my $opts = {};
-            $opts->{$self->_config->{password_field}} = $password 
-                if $self->_config->{password_field};            
+            $opts->{$self->password_field} = $password 
+                if $self->password_field;            
             if ($self->check_password($user_obj, $opts)) {
                 return $user_obj;
             }
@@ -128,7 +137,7 @@ sub authenticate_digest {
         my $user_obj;
 
         unless ( $user_obj = $auth_info->{user} ) {
-            $user_obj = $realm->find_user( { $self->_config->{username_field} => $username }, $c);
+            $user_obj = $realm->find_user( { $self->username_field => $username }, $c);
         }
         unless ($user_obj) {    # no user, no authentication
             $c->log->debug("Unable to locate user matching user info provided") if $c->debug;
@@ -149,7 +158,7 @@ sub authenticate_digest {
         # the idea of the for loop:
         # if we do not want to store the plain password in our user store,
         # we can store md5_hex("$username:$realm:$password") instead
-        my $password_field = $self->_config->{password_field};
+        my $password_field = $self->password_field;
         for my $r ( 0 .. 1 ) {
             # calculate H(A1) as per spec
             my $A1_digest = $r ? $user_obj->$password_field() : do {
@@ -189,7 +198,7 @@ sub _check_cache {
 
 sub _is_http_auth_type {
     my ( $self, $type ) = @_;
-    my $cfgtype = lc( $self->_config->{'type'} || 'any' );
+    my $cfgtype = lc( $self->type );
     return 1 if $cfgtype eq 'any' || $cfgtype eq lc $type;
     return 0;
 }
@@ -199,10 +208,10 @@ sub authorization_required_response {
 
     $c->res->status(401);
     $c->res->content_type('text/plain');
-    if (exists $self->_config->{authorization_required_message}) {
+    if (exists $self->{authorization_required_message}) {
         # If you set the key to undef, don't stamp on the body.
-        $c->res->body($self->_config->{authorization_required_message}) 
-            if defined $c->res->body($self->_config->{authorization_required_message}); 
+        $c->res->body($self->authorization_required_message) 
+            if defined $self->authorization_required_message; 
     }
     else {
         $c->res->body('Authorization required.');
@@ -269,7 +278,7 @@ sub _build_auth_header_domain {
           unless ref($domain) && ref($domain) eq "ARRAY";
 
         my @uris =
-          $self->_config->{use_uri_for}
+          $self->use_uri_for
           ? ( map { $c->uri_for($_) } @$domain )
           : ( map { URI::Escape::uri_escape($_) } @$domain );
 
@@ -318,7 +327,7 @@ sub _digest_auth_nonce {
 
     my $nonce   = $package->new;
 
-    if ( my $algorithm = $opts->{algorithm} || $self->_config->{algorithm}) { 
+    if ( my $algorithm = $opts->{algorithm} || $self->algorithm) { 
         $nonce->algorithm( $algorithm );
     }
 
index 3df2527..105c795 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -139,6 +139,7 @@ $c->clear;
 $req_headers->clear;
 $res_headers->clear;
 $c->clear;
+$body = 'quuux';
 {
     my $self = new_self( type => 'any', password_type => 'clear',
         authorization_required_message => undef
@@ -146,7 +147,7 @@ $c->clear;
     throws_ok {
         $self->authenticate( $c, $realm );
     } qr/^ $Catalyst::DETACH $/x, "detached";
-    is( $body, undef, 'Body is not set - user overrode auth message');
+    is( $body, 'quuux', 'Body is not set - user overrode auth message');
 }
 
 # Check domain config works