Catalyst::Authentication::Realm::SimpleDB(3pm) | User Contributed Perl Documentation | Catalyst::Authentication::Realm::SimpleDB(3pm) |
Catalyst::Authentication::Realm::SimpleDB - A simplified Catalyst authentication configurator.
use Catalyst qw/ Authentication /; __PACKAGE__->config->{'Plugin::Authentication'} = { default => { class => 'SimpleDB', user_model => 'MyApp::Schema::Users', } } # later on ... $c->authenticate({ username => 'myusername', password => 'mypassword' }); my $age = $c->user->get('age'); $c->logout;
The Catalyst::Authentication::Realm::SimpleDB provides a simple way to configure Catalyst Authentication when using the most common configuration of a password protected user retrieved from an SQL database.
The SimpleDB Realm class configures the Catalyst authentication system based on the following:
For the above usage, only one configuration option is necessary, 'user_model'. user_model should contain the class name of your user class. See the "PREPARATION" section for info on how to set up your database for use with this module.
If your system differs from the above, some minor configuration may be necessary. The options available are detailed below. These options match the configuration options used by the underlying credential and store modules. More information on these options can be found in Catalyst::Authentication::Credential::Password and Catalyst::Authentication::Store::DBIx::Class.
$c->authenticate({ username => 'bob', users_password => 'foo' });
This module makes several assumptions about the structure of your database. Below is an example of a table structure which will function with this module in it's default configuration. You can use this table structure as-is or add additional fields as necessary. NOTE that this is the default SimpleDB configuration only. Your table structure can differ significantly from this when using the DBIx::Class Store directly.
-- -- note that you can add any additional columns you require to the users table. -- CREATE TABLE users ( id INTEGER PRIMARY KEY, username TEXT, password TEXT, ); CREATE TABLE roles ( id INTEGER PRIMARY KEY, role TEXT ); CREATE TABLE user_roles ( user_id INTEGER, role_id INTEGER, PRIMARY KEY (user_id, role_id) );
Also, after you have loaded this table structure into your DBIx::Class schema, please be sure that you have a many_to_many DBIx::Class relationship defined for the users to roles relation. Your schema files should contain something along these lines:
"lib/MyApp/Schema/Users.pm":
__PACKAGE__->has_many(map_user_role => 'MyApp::Schema::UserRoles', 'user_id'); __PACKAGE__->many_to_many(roles => 'map_user_role', 'role');
"lib/MyApp/Schema/UserRoles.pm":
__PACKAGE__->belongs_to(role => 'MyApp::Schema::Roles', 'role_id');
If and when your application becomes complex enough that you need more features than SimpleDB gives you access to, you can migrate to a standard Catalyst Authentication configuration fairly easily. SimpleDB simply creates a standard Auth config based on the inputs you give it. The config SimpleDB creates by default looks like this:
MyApp->config('Plugin::Authentication') = { default => { credential => { class => 'Password', password_type => 'clear' }, store => { class => 'DBIx::Class', role_relation => 'roles', role_field => 'role', use_userdata_from_session => '1', user_model => $user_model_from_simpledb_config } } };
This module relies on a number of other modules to do it's job. For more information you can refer to the following:
2022-06-09 | perl v5.34.0 |