X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAuthentication%2FCredential%2FHTTP.pm;h=b2234b5a4bb31127a44ad029ea87cf72b67da09c;hb=60dd48a6bea236e5ceccb78c37b12f788c30129d;hp=350cfd15403c08f9700b70b27dd8d97f2b4b644d;hpb=b5402c9e1b00eb7dbb28da81db4bfb5e53919744;p=catagits%2FCatalyst-Authentication-Credential-HTTP.git diff --git a/lib/Catalyst/Authentication/Credential/HTTP.pm b/lib/Catalyst/Authentication/Credential/HTTP.pm index 350cfd1..b2234b5 100644 --- a/lib/Catalyst/Authentication/Credential/HTTP.pm +++ b/lib/Catalyst/Authentication/Credential/HTTP.pm @@ -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.010'; 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 ? 1 : 0 }; 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,17 +68,22 @@ 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; } - } - else { - $c->log->debug("Unable to locate user matching user info provided") if $c->debug; + else { + $c->log->debug("Password mismatch!") if $c->debug; + return; + } + } + else { + $c->log->debug("Unable to locate user matching user info provided") + if $c->debug; return; } } @@ -128,7 +142,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 +163,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 +203,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 +213,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 +283,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 +332,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 ); } @@ -621,6 +635,8 @@ Patches contributed by: =item Peter Corlett +=item Devin Austin (dhoss) C + =back =head1 SEE ALSO