[Catalyst] how to authenticate using database users

Karl Forner karl.forner at gmail.com
Fri Mar 20 09:03:09 GMT 2009


Hi,

I have implemented such an authentication sheme. I'm rather new to catalyst
so I do not pretend it si the best way.
Anyway what I've done is :

1) add the session and authentication plugins to catalyst app:

use Catalyst qw/...
Authentication
Session
Session::Store::FastMmap
Session:State::Cookie
...

2) write a custom Authentication plugin, the your specific code is in
_authenticate_against_SGDB

package Serono::Gecko::Business::CredentialVerifier;

use Catalyst::Plugin::Authentication::User::Hash;

sub authenticate {
    my ( $self, $c, $realm, $authinfo ) =3D @_;

    my $schema =3D $c->model('DB') or confess "unable to get schema";
    my $username =3D $authinfo->{username} || "";
    my $password =3D $authinfo->{password} || "";

    my $user =3D $self->_authenticate_against_SGDB($schema, $username,
$password );
    if ($user) {
        $c->log->debug( "authentication successful in  " . __PACKAGE__ );
        my $user_store =3D Catalyst::Plugin::Authentication::User::Hash->ne=
w(
id =3D> $user->user_id, username =3D> $username,
             password =3D> $password);
        return $user_store;
    }

    $c->log->debug(
        "Unable to locate user matching user info provided in " .
__PACKAGE__ );
    return;
}


3) configure it through the catalyst config file

<authentication>
        default_realm dbic
    <realms>
        <dbic>
            <credential>
                    class +Serono::Gecko::Business::CredentialVerifier
            </credential>
            <store>
                    class DBIx::Class
                    user_class DB::GeckoUserInfo
            </store>
        </dbic>
    </realms>
</authentication>

4) I use Root::auto to implement pass-through login and DB reconnection on
authenticated user if needed.

The only problem is that I encountered a bug with DBD::Oracle (I think),
that do not allow me to disconnect then reconnect, even DBI->connect (see my
previous post on this list).


On Wed, Mar 18, 2009 at 4:51 PM, Adam Witney <awitney at sgul.ac.uk> wrote:

>
> Hi,
>
> Our database uses actual database users rather than a table containing
> usernames and password. How would I authenticate against the database
> itself? The examples I have come across in the Tutorial and various
> Catalyst::Authentication::* modules all seem to require the presence of a
> table containing username and password fields.
>
> I guess I could write my own authenticate method that performed a manual
> dbh connection somehow... but I was wondering if there was a more
> standard/recommended way to do this?
>
> thanks for any help
>
> adam
>
> _______________________________________________
> 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090320/84dca=
5bf/attachment.htm


More information about the Catalyst mailing list