[Catalyst] Questions with Authentication/Authorization
Johannes Kilian
Jo.Kilian at gmx.de
Thu Nov 24 12:40:22 GMT 2011
Hi,
As a beginner with Catalyst authentication I've got a few questions on which I'm struggling at the moment:
Starting situation:
* I've got to authenticate the user against a database to get the role (each user only can have ONE role)
In my database there are two tables:
USERINFO - containig attributes for PK, USERNAME (attributename: userinfo_kuerzel) and foreign key to table ROLE (attribute name: fk_bdbrolle_pk)
ROLE - containig attributes for PK and ROLE (attribute name: bdbrolle_name)
Within my catalyst configuration I've the following realm configured:
authentication:
default_realm: db
realms:
db:
credential:
class: Password
password_field: userinfo_password
password_type: clear
store:
class: DBIx::Class
user_model: BDB::Userinfo
user_field: userinfo_kuerzel
role_relation: fk_bdbrolle_pk
role_field: bdbrolle_name
I succeeded to authenticate against this realm:
------------------
if ($c->authenticate({userinfo_kuerzel => $username, userinfo_password => ''}, "db") ) { # Authenticate against realm
...
# The username is available here via $c->user->userinfo_kuerzel; # so my realm seems to get data ...
# The role is available here via $c->user->fk_bdbrolle_pk->bdbrolle_name; # so my realm seems to get data ...
# $c->assert_user_roles( qw/Wizard/ ); # This fails!! but $c->user->fk_bdbrolle_pk->bdbrolle_name IS "Wizard"
$c->stash->{template} = 'index.tt';
$c->forward( $c->view('TT') );
}
* Within index.tt I try to access the username and role - which also works. I use something like this:
[% IF c.user %]Willkommen, [% c.user.userinfo_kuerzel %]([% c.user.fk_bdbrolle_pk.bdbrolle_name %])[% ELSE %]Not logged in[% END %]
------------------
Questions:
* Isn't $c->user a persistent value within $c? When I try to access to c.user later (after "successfull" login) $c->user is undefined.
What is neccessary to make it persistent?
* When I try to check the user role for example via $c->assert_user_roles( qw/Wizard/ ); (c.user.fk_bdbrolle_pk.bdbrolle_name has been Wizard in my example) this fails completely: Caught exception in BDBInfo2::Controller::Root->login "Can't locate object method "search" via package "BDBInfo2::Model::BDB::Bdbrolle" at .../Catalyst/Authentication/Store/DBIx/Class/User.pm line 144." What's wrong here?
I tried several things - but cannot find any solution yet ...
Any help welcome - Thanks in advance!
Johannes
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
More information about the Catalyst
mailing list