| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
CatalystX::Usul::Authentication - Use a Catalyst model as an authentication store
0.3.$Revision: 576 $
package MyApp;
use Catalyst qw( ... Authentication ... );
# The Catalyst::Authentication config below uses this module as an
# authentication store for both realms
<component name="Plugin::Authentication">
<default_realm>R01-Localhost</default_realm>
<realms>
<R01-Localhost>
<credential>
<class>Password</class>
<password_field>password</password_field>
<password_type>self_check</password_type>
</credential>
<store>
<class>+CatalystX::Usul::Authentication</class>
<model_class>IdentityUnix</model_class>
<user_field>username</user_field>
</store>
</R01-Localhost>
<R02-Database>
<credential>
<class>Password</class>
<password_field>password</password_field>
<password_type>self_check</password_type>
</credential>
<store>
<class>+CatalystX::Usul::Authentication</class>
<model_class>IdentityDBIC</model_class>
<user_field>username</user_field>
</store>
</R02-Database>
</realms>
</component>
Implements the Catalyst::Authentication::Store interface. Uses any
Catalyst::Model that implements the methods; find_user,
check_password, for_session, get, get_object, id, and
supports
Constructor options are passed as a list of scalars. Options are:
The constructor stores a copy of the $config on itself
Uses the model method to obtain a copy of the
identity object. This identity object is instantiated by Catalyst when
the application restarts. In the example config the R01-Localhost
authentication realm uses MyApp::Model::IdentityUnix as an identity
class (the MyApp::Model:: prefix is automatically applied to the
store class value). The identity object's find_user method returns
a user object. The config for the authentication store defines the
user field in the input parameters.
Exposes the for_session method in the user class. This allows the
user class to remove attribute from the user object prior to
serialisation on the session store
Return the user object if it already exists otherwise create one by
calling our own find_user method
Expose the supports class method in the user class. Allows the user
class to define which optional features it supports
None
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <Support at RoxSoft.co.uk>
Copyright (c) 2008 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
# @(#)$Id: Authentication.pm 576 2009-06-09 23:23:46Z pjf $ package CatalystX::Usul::Authentication; use strict; use warnings; use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 576 $ =~ /\d+/gmx ); use parent qw(Class::Accessor::Fast); __PACKAGE__->mk_accessors( qw(config) ); sub new { my ($self, $config, $app, $realm) = @_; return bless { config => $config }, ref $self || $self; } sub find_user { my ($self, $params, $c) = @_; my $id_obj = $c->model( $self->config->{model_class} ); return $id_obj->find_user( $params->{ $self->config->{user_field} } ); } sub for_session { my ($self, $c, $user) = @_; return $user->for_session; } sub from_session { my ($self, $c, $user) = @_; return $user if (ref $user); return $self->find_user( { $self->config->{user_field} => $user }, $c ); } sub user_supports { my ($self, @rest) = @_; return $self->{config}->{model_class}->supports( @rest ); } 1; __END__
# Local Variables: # mode: perl # tab-width: 3 # End: