[Catalyst] Need some help with Authorization setup

Kieren Diment diment at gmail.com
Tue May 12 07:55:29 GMT 2009


Try prodding around your code with the debugger.

http://search.cpan.org/perldoc?Catalyst::Manual::Tutorial::Debugging

Also Catalyst::Helper::AuthDBIC  on cpan.

The docs are fine, and I think roles support should work out of the  
box, but use the http credential, as it's easier to get up.

Put the following in Controller::Root:

sub auto : Private {
      my ($self, $c) = @_;
      $c->authenticate;
  }

and then have a poke around with TT and with the  debugger to see  
what's missing or wrong in your setup.


Also have a look at Catalyst::Controller::AuthDBIC
On 12/05/2009, at 5:19 PM, kakimoto at tpg.com.au wrote:

>
>
> hi, guys,
>
>   I have looked at my codes again.
>
> I read a lot more and debugged a lot more. I have arrived at the point
> whereby my catalyst user object doesn't have any value for roles  
> (despite
> all the values have been set in the database backend).
>
>  What am I missing?
>
> For example, running the code which dumps a list of roles as per
> http://search.cpan.org/~hkclark/Catalyst-Manual-5.7021/lib/Catalyst/Manual/Tutorial/Authorization.pod#___top
> (title of Add Role-Specific Logic to the "Book List" Template")  
> doesn't
> show anything but by right, my current user has an 'admin' role.
>
>
>
> What am I missing out? Please help.  My apologies for the many files  
> here.
>
> Thank you and help!! :)
>
>
>
>
> File Extract: lib/myApp.pm
> ==========================
>
>
> 	use Catalyst qw(
> 		-Debug
> 		ConfigLoader
> 		Static::Simple
>
> 		StackTrace
>
> 		Authentication
> 		Authentication::Credential::Password
>
> 		Authorization::Roles
>
> 		Cache
> 		Cache::Store::FastMmap
>
> 		FormValidator
>
> 		Session
> 		Session::Store::FastMmap
> 		Session::State::Cookie
> 	);
>
>
> 	__PACKAGE__->config(
> 		'name'    => 'myApp',
> 		'session' => { 'flash_to_stash' => 1 },
> 		'static'  => {
> 			'include_path' => [ $static_dir{'base'},  
> $static_dir{'user_media'}, ],
> 		},
> 		'Plugin::Authentication' => {
> 			default_realm => 'members',
> 			members       => {
> 				credential => {
> 					class                => 'Password',
> 					password_field       => 'password',
> 					password_type        => 'hashed',
> 					'password_hash_type' => 'SHA-384',
> 				},
> 				store => {
> 					class         => 'DBIx::Class',
> 					user_model    => 'myAppDB::Users',
> 					role_relation => 'map_user_role',
> 					role_field    => 'role',
> 				},
> 			},
> 		},
> 		'default_view' => 'myApp::View::TT',
> 	);
>
>
> File Extract:  ~/projects/myApp/lib/myApp/Schema/Roles.pm
> ============================================================
>
> 	package myApp::Schema::Roles;
>
> 	use strict;
> 	use warnings;
>
> 	use base 'DBIx::Class';
>
> 	__PACKAGE__->load_components qw( TimeStamp Core );
> 	__PACKAGE__->table("roles");
> 	__PACKAGE__->add_columns(
> 	  "id",
> 	  {
> 		data_type => "integer",
> 		default_value => "nextval('roles_id_seq'::regclass)",
> 		is_nullable => 0,
> 		size => 4,
> 	  },
> 	  "role",
> 	  {
> 		data_type => "text",
> 		default_value => undef,
> 		is_nullable => 1,
> 		size => undef,
> 	  },
> 	);
> 	__PACKAGE__->set_primary_key("id");
> 	__PACKAGE__->add_unique_constraint("roles_pkey", ["id"]);
>
>
> 	# Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-16  
> 15:08:18
> 	# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7hanYe3kgzC1BJKgsYhH3g
>
> 	__PACKAGE__->has_many( 'map_user_role' => 'myApp::Schema::UserRoles',
> 'role_id');
>
> 	1;
>
> File Extract: ~/projects/myApp/lib/myApp/Schema/Users.pm
> ============================================================
>
> 	use base 'DBIx::Class';
>
> 	__PACKAGE__->load_components qw( TimeStamp Core );
> 	__PACKAGE__->table("users");
> 	__PACKAGE__->add_columns(
> 	  "id",
> 	  { data_type => "integer", default_value =>
> "nextval('users_id_seq'::regclass)", is_nullable => 0, size => 4, },
> 	  "password",
> 	  { data_type => "text", default_value => undef, is_nullable => 0,  
> size
> => undef, },
> 	  "first_name",
> 	  { data_type => "text", default_value => undef, is_nullable => 1,  
> size
> => undef, },
> 	  "last_name",
> 	  { data_type => "text", default_value => undef, is_nullable => 1,  
> size
> => undef, },
> 	  "active",
> 	  { data_type => "integer", default_value => undef, is_nullable => 1,
> size => 4 },
> 	  "main_contact_id",
> 	  { data_type => "integer", default_value => undef, is_nullable => 1,
> size => 4 },
> 	  "company_name",
> 	  { data_type => "text", default_value => undef, is_nullable => 1,  
> size
> => undef, },
> 	  "billing_details_id",
> 	  { data_type => "integer", default_value => undef, is_nullable => 1,
> size => 4 },
> 	  "billing_address_id",
> 	  { data_type => "integer", default_value => undef, is_nullable => 1,
> size => 4 },
> 	  "created_by",
> 	  { data_type => "character varying", default_value => undef,
> is_nullable => 1, size => 12, },
> 	  "updated_by",
> 	  { data_type => "character varying", default_value => undef,
> is_nullable => 1, size => 12, },
> 	  "created_on",
> 	  { data_type => "timestamp without time zone", default_value =>  
> undef,
> is_nullable => 1, size => 8, },
> 	  "updated_on",
> 	  { data_type => "timestamp without time zone", default_value =>  
> undef,
> is_nullable => 1, size => 8, },
> 	  "login_id",
> 	  { data_type => "character varying", default_value => undef,
> is_nullable => 0, size => 20, },
> 	  "abn",
> 	  { data_type => "text", default_value => undef, is_nullable => 1,  
> size
> => undef, },
> 	);
> 	__PACKAGE__->set_primary_key("id");
> 	__PACKAGE__->add_unique_constraint("users_pkey", ["id"]);
> 	__PACKAGE__->add_unique_constraint("unique_login_id", ["login_id"]);
>
>
> # Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-16  
> 15:08:18
> # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:k/gPa2W9kHxvVMrKXFiPng
>
> 	__PACKAGE__->add_columns(
> 		'created_on',
> 		{ data_type => 'datetime', set_on_create => 1 },
> 		'updated_on',
> 		{ data_type => 'datetime', set_on_create => 1, set_on_update => 1 },
> 	);
>
>
> 	__PACKAGE__->has_many( 'map_user_role' => 'myApp::Schema::UserRoles',
> 'user_id');
>
> 	__PACKAGE__->many_to_many( 'roles' => 'map_user_role', 'role' );
>
> 	__PACKAGE__->has_one(main_contact => 'myApp::Schema::MainContacts',
> {'foreign.id' => 'self.main_contact_id' });
>
> 	__PACKAGE__->has_one(billing_address => 'myApp::Schema::Addresses',
> {'foreign.id' => 'self.billing_address_id' });
>
>
> 	1;
>
>
> File Extract: ~/projects/myApp/lib/myApp/Schema/UserRoles.pm
> ============================================================
>
> 	package myApp::Schema::UserRoles;
>
> 	use strict;
> 	use warnings;
>
> 	use base 'DBIx::Class';
>
> 	__PACKAGE__->load_components("Core");
> 	__PACKAGE__->table("user_roles");
> 	__PACKAGE__->add_columns(
> 	  "user_id",
> 	  { data_type => "integer", default_value => undef, is_nullable => 0,
> size => 4 },
> 	  "role_id",
> 	  { data_type => "integer", default_value => undef, is_nullable => 0,
> size => 4 },
> 	);
> 	__PACKAGE__->set_primary_key("user_id", "role_id");
> 	__PACKAGE__->add_unique_constraint("user_roles_pkey", ["user_id",
> "role_id"]);
>
>
> 	# Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-16  
> 15:08:18
> 	# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:laVNuEzY2I7z1XQKMXVx0A
> 	__PACKAGE__->belongs_to( 'user' => 'myApp::Schema::Users',  
> 'user_id');
>
> 	__PACKAGE__->belongs_to('role' => 'myApp::Schema::Roles', 'role_id');
>
> 	1;
>
>
> File Extract: ~/projects/myApp/lib/myApp/Model/myApp.pm
> ============================================================
>
> 	package myApp::Model::myAppDB;
>
> 	use strict;
> 	use base 'Catalyst::Model::DBIC::Schema';
>
> 	__PACKAGE__->config(
> 		schema_class => 'myApp::Schema',
> 		connect_info => [
> 			'dbi:Pg:dbname=myApp',
> 			'my-general-user',
> 			'my-password',
> 		],
> 	);
>
> 	1;
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/





More information about the Catalyst mailing list