[Catalyst-commits] r8573 - in trunk/Catalyst-Plugin-Authentication:
. lib/Catalyst/Authentication
lib/Catalyst/Authentication/Store lib/Catalyst/Plugin
lib/Catalyst/Plugin/Authentication t t/lib
jayk at dev.catalyst.perl.org
jayk at dev.catalyst.perl.org
Sun Oct 26 23:29:14 GMT 2008
Author: jayk
Date: 2008-10-26 23:29:14 +0000 (Sun, 26 Oct 2008)
New Revision: 8573
Modified:
trunk/Catalyst-Plugin-Authentication/Changes
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Internals.pod
trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm
trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm
trunk/Catalyst-Plugin-Authentication/t/lib/AuthTestApp.pm
trunk/Catalyst-Plugin-Authentication/t/live_app.t
trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t
trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t
Log:
Changes to allow for dropping of the 'realms' config hash and instead
including each realm within the main Plugin::Authentication hash
Modified: trunk/Catalyst-Plugin-Authentication/Changes
===================================================================
--- trunk/Catalyst-Plugin-Authentication/Changes 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/Changes 2008-10-26 23:29:14 UTC (rev 8573)
@@ -1,17 +1,15 @@
Revision history for Perl extension Catalyst::Plugin::Authentication
-0.1XXX XXXX
- - Update tests prereqs to include Test::Exception (RT #36339)
- - Update live tests to have plans, so that smoke tests against
- 5.80 don't give false positives (t0m)
+0.10007 2008-10-23
+ - Updating config to allow for inclusion of realm ref's in the main
+ config hash rather than in a subref called 'realms'
-0.10007_01 2008-06-05
+0.10007 2008-08-17
+ - Update tests prereqs to include Test::Exception (RT #36339)
- Some documentation fixes (including RT #36062)
- Compatibility fix where the use of new style config and old
style Authentication::Store::Minimal would cause a crash
(Reported & fixed by Jos Boumans C<kane at cpan.org>)
-
-0.10007 2008-03-17
- Documentation update on Password - to indicate proper field naming
- Decouple Authentication system from session. The realm class
now allows complete control over how a user is persisted across
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -269,6 +269,11 @@
Set this to true if you wish this realm to auto-update user accounts after
authentication (most useful for remote authentication schemes).
+=item use_session
+
+Sets session usage for this particular realm - overriding the global use_sesion setting.
+
+
=back
=head1 METHODS
@@ -298,7 +303,7 @@
realm class simply delegates this to the credential and sets
the authenticated user on success. Returns the authenticated user object;
-=head1 USER PERSISTANCE
+=head1 USER PERSISTENCE
The Realm class allows complete control over the persistance of users
between requests. By default the realm attempts to use the Catalyst
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -39,8 +39,6 @@
my $user = $self->userhash->{$id};
- #print STDERR "FOO1! " . ref($user) . " - ". Scalar::Util::blessed($user) . "\n";
-
if ( ref($user) eq "HASH") {
$user->{id} ||= $id;
return bless $user, "Catalyst::Authentication::User::Hash";
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Internals.pod
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Internals.pod 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication/Internals.pod 2008-10-26 23:29:14 UTC (rev 8573)
@@ -88,7 +88,7 @@
If the user object supports session storage, the successfully authenticated
user will be placed in session storage. This is done by calling the realm
-object's save_user_in_session() method. The save_user_in_session() routine by
+object's persist_user() method. The persist_user() routine by
default calls the Store's for_session() method, which should return serialized
data (IE a scalar). This serialized data is passed back to the store via the
from_session() method, so the data should contain enough information for the
@@ -106,7 +106,7 @@
When any user-related activity occurs, and $c->authenticate has not
yet been called, the Catalyst::Plugin::Authentication module will
-attempt to restore the user from the session (if one is available).
+attempt to restore the persisted user (normally from the session if one is available).
There is only one step in this process:
=over 4
@@ -122,7 +122,7 @@
Note that the for_session() is only called during the original
$c->authenticate() call, so if changes are made to the user that need
to be reflected in your session data, you will want to call the
-$c->save_user_in_session() method - which will perform the session
+$c->persist_user() method - which will perform the session
storage process again (complete with call to for_session()).
=back
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -13,9 +13,8 @@
use Class::Inspector;
use Catalyst::Authentication::Realm;
+our $VERSION = "0.10008";
-our $VERSION = "0.10007_01";
-
sub set_authenticated {
my ( $c, $user, $realmname ) = @_;
@@ -56,7 +55,7 @@
# in addition to verifying that they exist.
sub user_exists {
my $c = shift;
- return defined($c->_user) || defined($c->_find_realm_for_persisted_user);
+ return defined($c->_user) || defined($c->find_realm_for_persisted_user);
}
# works like user_exists - except only returns true if user
@@ -67,7 +66,7 @@
if (defined($c->_user)) {
return ($c->_user->auth_realm eq $realmname);
} else {
- my $realm = $c->_find_realm_for_persisted_user;
+ my $realm = $c->find_realm_for_persisted_user;
if ($realm) {
return ($realm->name eq $realmname);
} else {
@@ -128,7 +127,7 @@
$c->user(undef);
- my $realm = $c->_find_realm_for_persisted_user;
+ my $realm = $c->find_realm_for_persisted_user;
if ($realm) {
$realm->remove_persisted_user($c);
}
@@ -149,8 +148,9 @@
return $realm->find_user($userinfo, $c);
}
-
-sub _find_realm_for_persisted_user {
+## Consider making this a public method. - would make certain things easier when
+## dealing with things pre-auth restore.
+sub find_realm_for_persisted_user {
my $c = shift;
my $realm;
@@ -182,10 +182,10 @@
if (defined($realmname)) {
$realm = $c->get_auth_realm($realmname);
} else {
- $realm = $c->_find_realm_for_persisted_user;
+ $realm = $c->find_realm_for_persisted_user;
}
- return unless $realm; # FIXME die unless? This is an internal inconsistency
-
+ return undef unless $realm; # FIXME die unless? This is an internal inconsistency
+
$c->_user( my $user = $realm->restore_user( $c, $frozen_user ) );
# this sets the realm the user originated in.
@@ -226,8 +226,9 @@
## into play if session is disabled.
$app->mk_classdata( '_auth_realm_restore_order' => []);
-
+
my $cfg = $app->config->{'Plugin::Authentication'};
+ my $realmshash;
if (!defined($cfg)) {
if (exists($app->config->{'authentication'})) {
$cfg = $app->config->{'authentication'};
@@ -235,7 +236,17 @@
} else {
$cfg = {};
}
- }
+ } else {
+ # the realmshash contains the various configured realms. By default this is
+ # the main $app->config->{'Plugin::Authentication'} hash - but if that is
+ # not defined, or there is a subkey {'realms'} then we use that.
+ $realmshash = $cfg;
+ }
+
+ ## If we have a sub-key of {'realms'} then we use that for realm configuration
+ if (exists($cfg->{'realms'})) {
+ $realmshash = $cfg->{'realms'};
+ }
# old default was to force use_session on. This must remain for that
# reason - but if use_session is already in the config, we respect its setting.
@@ -243,21 +254,25 @@
$cfg->{'use_session'} = 1;
}
- if (exists($cfg->{'realms'})) {
+ ## if we have a realms hash
+ if (ref($realmshash) eq 'HASH') {
my %auth_restore_order;
my $authcount = 2;
my $defaultrealm = 'default';
-
- foreach my $realm (sort keys %{$cfg->{'realms'}}) {
+
+ foreach my $realm (sort keys %{$realmshash}) {
+ if (ref($realmshash->{$realm}) eq 'HASH' &&
+ (exists($realmshash->{$realm}{credential}) || exists($realmshash->{$realm}{class}))) {
+
+ $app->setup_auth_realm($realm, $realmshash->{$realm});
- $app->setup_auth_realm($realm, $cfg->{'realms'}{$realm});
-
- if (exists($cfg->{'realms'}{$realm}{'user_restore_priority'})) {
- $auth_restore_order{$realm} = $cfg->{'realms'}{$realm}{'user_restore_priority'};
- } else {
- $auth_restore_order{$realm} = $authcount++;
- }
+ if (exists($realmshash->{$realm}{'user_restore_priority'})) {
+ $auth_restore_order{$realm} = $realmshash->{$realm}{'user_restore_priority'};
+ } else {
+ $auth_restore_order{$realm} = $authcount++;
+ }
+ }
}
# if we have a 'default_realm' in the config hash and we don't already
@@ -271,7 +286,7 @@
}
## if the default realm did not have a defined priority in its config - we put it at the front.
- if (!exists($cfg->{'realms'}{$defaultrealm}{'user_restore_priority'})) {
+ if (!exists($realmshash->{$defaultrealm}{'user_restore_priority'})) {
$auth_restore_order{'default'} = 1;
}
@@ -614,30 +629,27 @@
__PACKAGE__->config->{'Plugin::Authentication'} =
{
- default_realm => 'members',
- realms => {
- members => {
- credential => {
- class => 'Password',
- password_field => 'password',
- password_type => 'clear'
- },
- store => {
- class => 'Minimal',
- users => {
- bob => {
- password => "s00p3r",
- editor => 'yes',
- roles => [qw/edit delete/],
- },
- william => {
- password => "s3cr3t",
- roles => [qw/comment/],
- }
- }
- }
- }
- }
+ default => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'Minimal',
+ users => {
+ bob => {
+ password => "s00p3r",
+ editor => 'yes',
+ roles => [qw/edit delete/],
+ },
+ william => {
+ password => "s3cr3t",
+ roles => [qw/comment/],
+ }
+ }
+ }
+ }
};
@@ -738,20 +750,18 @@
__PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'members',
- realms => {
- members => {
- credential => {
- class => 'Password',
- password_field => 'password',
- password_type => 'clear'
- },
- store => {
- class => 'DBIx::Class',
- user_class => 'MyApp::Users',
- role_column => 'roles'
- }
- }
- }
+ members => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'DBIx::Class',
+ user_class => 'MyApp::Users',
+ role_column => 'roles'
+ }
+ }
};
The authentication system works behind the scenes to load your data from the
@@ -764,32 +774,30 @@
__PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'members',
- realms => {
- members => {
- credential => {
- class => 'Password',
- password_field => 'password',
- password_type => 'clear'
- },
- store => {
- class => 'DBIx::Class',
- user_class => 'MyApp::Users',
- role_column => 'roles'
- }
- },
- admins => {
- credential => {
- class => 'Password',
- password_field => 'password',
- password_type => 'clear'
- },
- store => {
- class => '+MyApp::Authentication::Store::NetAuth',
- authserver => '192.168.10.17'
- }
- }
-
- }
+
+ members => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'DBIx::Class',
+ user_class => 'MyApp::Users',
+ role_column => 'roles'
+ }
+ },
+ admins => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => '+MyApp::Authentication::Store::NetAuth',
+ authserver => '192.168.10.17'
+ }
+ }
};
=over 4
@@ -805,11 +813,15 @@
This defines which realm should be used as when no realm is provided to methods
that require a realm such as authenticate or find_user.
-=item realms
+=item realm refs
-This contains the series of realm configurations you want to use for your app.
-The only rule here is that there must be at least one. A realm consists of a
-name, which is used to reference the realm, a credential and a store.
+The Plugin::Authentication config hash contains the series of realm
+configurations you want to use for your app. The only rule here is
+that there must be at least one. A realm consists of a name, which is used
+to reference the realm, a credential and a store. You may also put your
+realm configurations within a subelement called 'realms' if you desire to
+separate them from the remainder of your configuration. Note that if you use
+a 'realms' subelement, you must put ALL of your realms within it.
You can also specify a realm class to instantiate instead of the default
L<Catalyst::Authentication::Realm> class using the 'class' element within the
Modified: trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -43,7 +43,6 @@
__PACKAGE__->config->{'Plugin::Authentication'} = {
default_realm => 'members',
- realms => {
members => {
credential => {
class => 'Password',
@@ -55,7 +54,7 @@
users => $members,
}
},
- }
+
};
__PACKAGE__->setup;
Modified: trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -68,7 +68,7 @@
ok( !$c->user, "no user object either" );
}
-__PACKAGE__->config->{'Plugin::Authentication'}{users} = $users = {
+__PACKAGE__->config->{'authentication'}{users} = $users = {
foo => User::SessionRestoring->new(
id => 'foo',
password => "s3cr3t",
Modified: trunk/Catalyst-Plugin-Authentication/t/lib/AuthTestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthTestApp.pm 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthTestApp.pm 2008-10-26 23:29:14 UTC (rev 8573)
@@ -13,9 +13,13 @@
our $users;
+sub number_of_elements { return scalar @_ }
+
sub moose : Local {
my ( $self, $c ) = @_;
+ is(number_of_elements($c->user), 1, "Array undef");
+ is($c->user, undef, "no user, returns undef");
ok(!$c->user, "no user");
ok($c->login( "foo", "s3cr3t" ), "can login with clear");
is( $c->user, $users->{foo}, "user object is in proper place");
Modified: trunk/Catalyst-Plugin-Authentication/t/live_app.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app.t 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app.t 2008-10-26 23:29:14 UTC (rev 8573)
@@ -1,10 +1,11 @@
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More;
BEGIN {
plan skip_all => "Digest::SHA1 is required for this test" unless eval { require Digest::SHA1 };
+ plan "no_plan";
}
use lib 't/lib';
Modified: trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app_realms.t 2008-10-26 23:29:14 UTC (rev 8573)
@@ -1,8 +1,13 @@
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More;
+BEGIN {
+ plan "no_plan";
+}
+
+
use lib 't/lib';
use Catalyst::Test qw/AuthRealmTestApp/;
Modified: trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t 2008-10-26 23:27:59 UTC (rev 8572)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t 2008-10-26 23:29:14 UTC (rev 8573)
@@ -1,8 +1,12 @@
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More;
+BEGIN {
+ plan "no_plan";
+}
+
use lib 't/lib';
use Catalyst::Test qw/AuthRealmTestAppCompat/;
More information about the Catalyst-commits
mailing list