diff --git a/lib/Catalyst/Authentication/Realm/Progressive.pm b/lib/Catalyst/Authentication/Realm/Progressive.pm index 63d00a8..0a9bbd9 100644 --- a/lib/Catalyst/Authentication/Realm/Progressive.pm +++ b/lib/Catalyst/Authentication/Realm/Progressive.pm @@ -6,6 +6,9 @@ use strict; use base 'Catalyst::Authentication::Realm'; +use Try::Tiny; +use Scalar::Util 'blessed'; + =head1 NAME Catalyst::Authentication::Realm::Progressive - Authenticate against multiple realms @@ -123,23 +126,43 @@ sub authenticate { my ( $self, $c, $authinfo ) = @_; my $realms = $self->config->{realms}; carp "No realms to authenticate against, check configuration" - unless $realms; + unless $realms; carp "Realms configuration must be an array reference" - unless ref $realms eq 'ARRAY'; - foreach my $realm_name ( @$realms ) { - my $realm = $c->get_auth_realm( $realm_name ); + unless ref $realms eq 'ARRAY'; + + my $should_detach; + foreach my $realm_name (@$realms) { + my $realm = $c->get_auth_realm($realm_name); carp "Unable to find realm: $realm_name, check configuration" - unless $realm; - my $auth = { %$authinfo }; + unless $realm; + my $auth = {%$authinfo}; $auth->{realm} ||= $realm->name; - if ( my $info = $self->config->{authinfo_munge}->{$realm->name} ) { - $auth = Catalyst::Utils::merge_hashes($auth, $info); + if ( my $info = $self->config->{authinfo_munge}->{ $realm->name } ) { + $auth = Catalyst::Utils::merge_hashes( $auth, $info ); } - if ( my $obj = $realm->authenticate( $c, $auth ) ) { - $c->set_authenticated( $obj, $realm->name ); - return $obj; + + my $auth_obj; + try { + $auth_obj = $realm->authenticate( $c, $auth ); + } + catch { + if ( $_ eq $Catalyst::DETACH ) { + $should_detach = 1; + } + else { + die $_; + } + }; + + if ($auth_obj) { + $c->set_authenticated( $auth_obj, $realm->name ); + return $auth_obj; } } + + # detach if detach is thrown like from Credential::HTTP + $c->detach if $should_detach; + return; } @@ -149,7 +172,7 @@ sub authenticate { ## and return $self in order to avoid nasty warnings. sub new { - my ($class, $realmname, $config, $app) = @_; + my ( $class, $realmname, $config, $app ) = @_; my $self = { config => $config }; bless $self, $class; @@ -164,9 +187,15 @@ J. Shirley C<< >> Jay Kuri C<< >> +=head1 CONTRIBUTORS + +Gavin Henry C<< >> + +Tomas Doran C<< >> + =head1 COPYRIGHT & LICENSE -Copyright (c) 2008 the aforementioned authors. All rights reserved. This program +Copyright (c) 2008-2011 the aforementioned authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/lib/Catalyst/Plugin/Authentication.pm b/lib/Catalyst/Plugin/Authentication.pm index 98415ce..9827e93 100644 --- a/lib/Catalyst/Plugin/Authentication.pm +++ b/lib/Catalyst/Plugin/Authentication.pm @@ -12,7 +12,7 @@ use Tie::RefHash; use Class::Inspector; use Catalyst::Authentication::Realm; -our $VERSION = "0.10018"; +our $VERSION = "0.10019"; sub set_authenticated { my ( $c, $user, $realmname ) = @_; diff --git a/t/lib/AuthRealmTestAppProgressive.pm b/t/lib/AuthRealmTestAppProgressive.pm index 3d205eb..2035a07 100644 --- a/t/lib/AuthRealmTestAppProgressive.pm +++ b/t/lib/AuthRealmTestAppProgressive.pm @@ -27,7 +27,16 @@ __PACKAGE__->config('Plugin::Authentication' => { default_realm => 'progressive', progressive => { class => 'Progressive', - realms => [ 'other', 'members' ], + realms => [ 'alwaysdetach', 'other', 'members' ], + }, + alwaysdetach => { + credential => { + class => 'AlwaysDetach', + }, + store => { + class => 'Minimal', + users => {}, + }, }, other => { credential => { diff --git a/t/lib/AuthRealmTestAppProgressive/Controller/Root.pm b/t/lib/AuthRealmTestAppProgressive/Controller/Root.pm index 8e48623..4e9037f 100644 --- a/t/lib/AuthRealmTestAppProgressive/Controller/Root.pm +++ b/t/lib/AuthRealmTestAppProgressive/Controller/Root.pm @@ -3,7 +3,7 @@ use warnings; use strict; use base qw/Catalyst::Controller/; -__PACKAGE__->config(namespace => ''); +__PACKAGE__->config( namespace => '' ); use Test::More; use Test::Exception; @@ -12,18 +12,22 @@ sub progressive : Local { my ( $self, $c ) = @_; foreach my $realm ( keys %AuthRealmTestAppProgressive::members ) { - while ( my ( $user, $info ) = each %{$AuthRealmTestAppProgressive::members{$realm}} ) { + while ( my ( $user, $info ) = + each %{ $AuthRealmTestAppProgressive::members{$realm} } ) + { + my $res; my $ok = eval { - $c->authenticate( + $res = $c->authenticate( { username => $user, password => $info->{password} }, - ); + ); + 1; }; - ok( !$@, "authentication passed." ); - ok( $ok, "user authenticated" ); + ok( !$@, "authentication passed." ); + ok( $ok, "user authenticated" ); ok( $c->user_in_realm($realm), "user in proper realm" ); } } - $c->res->body( "ok" ); + $c->res->body("ok"); } 1; diff --git a/t/lib/Catalyst/Authentication/Credential/AlwaysDetach.pm b/t/lib/Catalyst/Authentication/Credential/AlwaysDetach.pm new file mode 100644 index 0000000..a5316be --- /dev/null +++ b/t/lib/Catalyst/Authentication/Credential/AlwaysDetach.pm @@ -0,0 +1,16 @@ +package Catalyst::Authentication::Credential::AlwaysDetach; +use strict; +use warnings; + +sub new { + bless {}, __PACKAGE__; +} + +sub authenticate { + my ( $self, $c, $realm, $auth_info ) = @_; + $c->detach; +} + +no Moose; +1; + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy