3 package Catalyst::Plugin::Authentication::Store::Minimal;
8 use Catalyst::Plugin::Authentication::User::Hash;
10 use base qw/Class::Accessor::Fast/;
13 __PACKAGE__->mk_accessors(qw/userhash/);
17 my ( $class, $config, $app) = @_;
19 bless { userhash => $config->{'users'} }, $class;
23 my ( $self, $c, $id ) = @_;
25 return $id if ref $id;
27 $self->find_user( { id => $id } );
30 ## this is not necessarily a good example of what find_user can do, since all we do is
31 ## look up with the id anyway. find_user can be used to locate a user based on other
32 ## combinations of data. See C::P::Authentication::Store::DBIx::Class for a better example
34 my ( $self, $userinfo, $c ) = @_;
36 my $id = $userinfo->{'id'};
38 $id ||= $userinfo->{'username'};
40 return unless exists $self->userhash->{$id};
42 my $user = $self->userhash->{$id};
45 if ( Scalar::Util::blessed($user)
46 and $user->isa('Catalyst::Plugin::Authentication::User::Hash') )
50 if ( ref $user eq "HASH" ) {
52 return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
55 Catalyst::Exception->throw( "The user '$id' is a reference of type "
57 . " but should be a HASH" );
61 Catalyst::Exception->throw(
62 "The user '$id' is has to be a hash reference or an object");
71 # choose a random user
72 scalar keys %{ $self->userhash };
73 ( undef, my $user ) = each %{ $self->userhash };
78 ## Backwards compatibility
80 # This is a backwards compatible routine. get_user is specifically for loading a user by it's unique id
81 # find_user is capable of doing the same by simply passing { id => $id }
82 # no new code should be written using get_user as it is deprecated.
84 my ( $self, $id ) = @_;
85 $self->find_user({id => $id});
88 ## backwards compatibility
92 $c->default_auth_store(
94 $c->config->{authentication}, $c
109 Catalyst::Plugin::Authentication::Store::Minimal - Minimal
110 authentication store.
114 # you probably just want Store::Minimal under most cases,
115 # but if you insist you can instantiate your own store:
117 use Catalyst::Plugin::Authentication::Store::Minimal;
123 __PACKAGE__->config->{authentication} =
125 default_realm => 'members',
130 password_field => 'password',
131 password_type => 'clear'
137 password => "s00p3r",
139 roles => [qw/edit delete/],
142 password => "s3cr3t",
143 roles => [qw/comment/],
154 This authentication store lets you create a very quick and dirty user
155 database in your application's config hash.
157 You will need to include the Authentication plugin, and at least one Credential
158 plugin to use this Store. Credential::Password is reccommended.
160 It's purpose is mainly for testing, and it should probably be replaced by a
161 more "serious" store for production.
163 The hash in the config, as well as the user objects/hashes are freely mutable
172 The classname used for the store. This is part of
173 L<Catalyst::Plugin::Authentication> and is the method by which
174 Catalyst::Plugin::Authentication::Store::Minimal is loaded as the
175 user store. For this module to be used, this must be set to
180 This is a simple hash of users, the keys are the usenames, and the values are
181 hashrefs containing a password key/value pair, and optionally, a roles/list
182 of role-names pair. If using roles, you will also need to add the
183 Authorization::Roles plugin.
185 See the SYNOPSIS for an example.
191 There are no publicly exported routines in the Minimal store (or indeed in
192 most authentication stores) However, below is a description of the routines
193 required by L<Catalyst::Plugin::Authentication> for all authentication stores.
197 =item new ( $config, $app )
199 Constructs a new store object, which uses the user element of the supplied config
200 hash ref as it's backing structure.
202 =item find_user ( $authinfo, $c )
204 Keys the hash by the 'id' or 'username' element in the authinfo hash and returns the user.
206 ... documentation fairy stopped here. ...
208 If the return value is unblessed it will be blessed as
209 L<Catalyst::Plugin::Authentication::User::Hash>.
211 =item from_session $id
213 Delegates to C<get_user>.
217 Chooses a random user from the hash and delegates to it.