madison.sacd has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am trying to use Catalyst::PluginAuthorization modules. However, according to Catalyst tutorial on CPAN, it seems that I must have 2 tables in database, one for user and one for roles.

My question is that I just have one table which contains user accounts, passwords and roles all together. Therefore, I cannot follow the yml file settings in tutorial as below code. Especially the line role_rel: map_user_role which indicates the relationship between user table and role table. Please give me some hints about how should I do to fix the setting. Thanks.
authentication: dbic: user_class: MyappDB::User user_field: username password_field: password password_type: clear authorization: dbic: role_class: MyAppDB::User role_field: role role_rel: map_user_role user_role_user_field: user_id
  • Comment on Catalyst::Plugin::Authorization -- dont have "role_rel" for one table
  • Download Code

Replies are listed 'Best First'.
Re: Catalyst::Plugin::Authorization -- dont have "role_rel" for one table
by Herkum (Parson) on May 09, 2007 at 11:37 UTC
    While Catalyst is written using Perl it is a very specific set of software. You would probably be better off asking your question on the Catalyst Mailing Lists rather than here.

Re: Catalyst::Plugin::Authorization -- dont have "role_rel" for one table
by jasonk (Parson) on May 09, 2007 at 16:06 UTC

    As I see it you have several options

    In the end though, you can't simply change the configuration and expect it to work, the module you are trying to use expects a specific table structure which you don't have. You could just not use it and do the role checking manually though...

    package MyApp; sub check_role { my ( $c, $role ) = @_; return 1 if ( $user && $c->user->obj->role eq $role ); return 0; } sub assert_role { my ( $c, $role ) = @_; if ( ! $c->check_role( $role ) ) { $c->detach( '/access_denied' ); } } package MyApp::Controller::Root; sub auto : Private { my ( $self, $c ) = @_; $c->stash->{ 'is_admin' } = $c->check_role( 'Admin' ); return 1; } package MyApp::Controller::Admin; sub auto : Private { my ( $self, $c ) = @_; $c->assert_role( 'Admin' ); return 1; }

    We're not surrounded, we're in a target-rich environment!