X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FAuthentication%2FStore%2FMinimal.pm;h=f79b97e6ebd48562821d2a41a05632a57998a217;hb=675fe850ff8ef284e35f9b78141543187df59d72;hp=cecdfa7f9fdc178b38872aff0d42e7ec22a336da;hpb=54c8dc06a4c1aec61a6595f0d19c42c8d0eed749;p=catagits%2FCatalyst-Plugin-Authentication.git diff --git a/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm b/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm index cecdfa7..f79b97e 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Minimal.pm @@ -1,22 +1,47 @@ -#!/usr/bin/perl - package Catalyst::Plugin::Authentication::Store::Minimal; use strict; use warnings; +use MRO::Compat; -use Catalyst::Plugin::Authentication::Store::Minimal::Backend; +use Catalyst::Authentication::Store::Minimal (); +## backwards compatibility sub setup { my $c = shift; - $c->default_auth_store( - Catalyst::Plugin::Authentication::Store::Minimal::Backend->new( - $c->config->{authentication}{users}, $c - ) - ); + ### If a user does 'use Catalyst qw/Authentication::Store::Minimal/' + ### he will be proxied on to this setup routine (and only then -- + ### non plugins should NOT have their setup routine invoked!) + ### Beware what we pass to the 'new' routine; it wants + ### a config has with a top level key 'users'. New style + ### configs do not have this, and split by realms. If we + ### blindly pass this to new, we will 1) overwrite what we + ### already passed and 2) make ->userhash undefined, which + ### leads to: + ### Can't use an undefined value as a HASH reference at + ### lib/Catalyst/Authentication/Store/Minimal.pm line 38. + ### + ### So only do this compatibility call if: + ### 1) we have a {users} config directive + ### + ### Ideally we could also check for: + ### 2) we don't already have a ->userhash + ### however, that's an attribute of an object we can't + ### access =/ --kane + + my $cfg = $c->config->{'Plugin::Authentication'}->{users} + ? $c->config->{'Plugin::Authentication'} + : undef; + + $c->default_auth_store( Catalyst::Authentication::Store::Minimal->new( $cfg, $c ) ) if $cfg; + + $c->next::method(@_); +} - $c->NEXT::setup(@_); +foreach my $method (qw/ get_user user_supports find_user from_session /) { + no strict 'refs'; + *{$method} = sub { __PACKAGE__->default_auth_store->$method( @_ ) }; } __PACKAGE__; @@ -27,71 +52,31 @@ __END__ =head1 NAME -Catalyst::Plugin::Authentication::Store::Minimal - Authentication -database in C<< $c->config >>. - -=head1 SYNOPSIS - - use Catalyst qw/ - Authentication - Authentication::Store::Minimal - Authentication::Credential::Password - /; - - __PACKAGE__->config->{authentication}{users} = { - name => { - password => "s3cr3t", - roles => [qw/admin editor/], - ... - }, - }; - - sub login : Global { - my ( $self, $c ) = @_; - - $c->login( $c->req->param("login"), $c->req->param("password"), ); - } +Catalyst::Plugin::Authentication::Store::Minimal - Compatibility shim =head1 DESCRIPTION -This authentication store plugin lets you create a very quick and dirty user -database in your application's config hash. +THIS IS A COMPATIBILITY SHIM. It allows old configurations of Catalyst +Authentication to work without code changes. -You will need to include the Authentication plugin, and at least one Credential -plugin to use this Store. Credential::Password is reccommended. +B -It's purpose is mainly for testing, and it should probably be replaced by a -more "serious" store for production. +Please see L for more information. -The hash in the config, as well as the user objects/hashes are freely mutable -at runtime. +=head1 METHODS -=head1 CONFIGURATION +=over -=over 4 +=item find_user -=item users +=item from_session -This is a simple hash of users, the keys are the usenames, and the values are -hashrefs containing a password key/value pair, and optionally, a roles/list -of role-names pair. If using roles, you will also need to add the -Authorization::Roles plugin. - -See the SYNOPSIS for an example. - -=back - -=head1 INTERNAL METHODS - -=over 4 +=item get_user =item setup -This method will popultate C<< $c->config->{authentication}{store} >> so that -L can use it. +=item user_supports =back =cut - -