[Catalyst] Questions with Authentication/Authorization [FINAL SOLUTION]

Johannes Kilian Jo.Kilian at gmx.de
Tue Dec 13 13:16:37 GMT 2011


Hello,

just for completeness the "final" solution.

Tomas Doran [bobtfish at bobtfish.net] wrote:
>The best solution is to subclass Catalyst::Authentication::Store::DBIx::Class::User in your application (as MyApp::User or whatever), then re-implement the 'roles' method to do the right thing for your Database..

Here my reimplementation of "roles":
------------------------------------------
package 'MyApp::User;

use strict;
use warnings;
use base qw(Catalyst::Authentication::Store::DBIx::Class::User);

sub roles {
    my ( $self ) = shift;
    ## this used to load @wantedroles - but that doesn't seem to be used by the roles plugin, so I dropped it.

    ## shortcut if we have already retrieved them
    if (ref $self->_roles eq 'ARRAY') {
        return(@{$self->_roles});
    }

    my @roles = ();
    if (defined($self->_user)) {
        my $role_relation = $self->config->{'role_relation'};
        my $role_field = $self->config->{'role_field'};

        push @roles,$self->_user->$role_relation->$role_field;
    }
    $self->_roles(\@roles);
    return @{$self->_roles};
}
-----------------------------------------------


Tomas Doran [bobtfish at bobtfish.net] wrote:
>You can then set the store_user_class config option to 'MyApp::User', and everything should work as expected..

Within my configuration I did the following:
-----------------------------------------------
authentication:
            registered:
                store:
                    class: DBIx::Class
                    user_model: BDB::Userinfo
                    user_field: userinfo_kuerzel
                    role_relation: fk_bdbrolle_pk
                    role_field: bdbrolle_name
                    store_user_class: MyApp::User
-----------------------------------------------

Voila - that was it. Everything works as expected (as Thomas predicted)

Thank you for your support
Johannes

                    




-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!		
Jetzt informieren: http://www.gmx.net/de/go/freephone



More information about the Catalyst mailing list