| Catalyst-Authentication-Store-KiokuDB documentation | Contained in the Catalyst-Authentication-Store-KiokuDB distribution. |
Catalyst::Authentication::Store::KiokuDB - KiokuDB store for auth
use Catalyst qw/
Authentication
/;
__PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'admin',
realms => {
admin => {
credential => {
class => 'Password',
password_field => 'password',
password_type => 'clear'
},
store => {
class => 'KiokuDB',
kiokuDir => '/path/to/some/dir',
}
}
}
};
This is a simple authentication store that uses KiokuDB as its backend storage. It is recommended if you are already using KiokuDB and wish to centralise all of your storage there.
Only one of the following should be specified.
This is the path to the directory in which you tell KiokuDB to store its data.
This is an already instantiated KiokuDB object which you wish to reuse to store you data with. This object needs to support searching based on attributes.
This store implements no methods outside of those required by its base class.
Robin Berjon, <robin@berjon.com>, http://robineko.com/
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| Catalyst-Authentication-Store-KiokuDB documentation | Contained in the Catalyst-Authentication-Store-KiokuDB distribution. |
package Catalyst::Authentication::Store::KiokuDB; use strict; use warnings; our $VERSION = '0.01'; use Catalyst::Authentication::User::KiokuDB; use Search::GIN::Extract::Class; use Search::GIN::Extract::Attributes; use Search::GIN::Extract::Multiplex; use Search::GIN::Query::Attributes; use KiokuDB; use KiokuDB::Backend::BDB::GIN; sub new { my ($class, $conf, $app, $realm) = @_; my %self; if ($conf->{kiokuObject}) { $self{kioku} = $conf->{kiokuObject}; } elsif ($conf->{kiokuDir}) { $self{kioku} = KiokuDB->new( backend => KiokuDB::Backend::BDB::GIN->new( manager => { home => $conf->{kiokuDir}, create => 1 }, extract => Search::GIN::Extract::Multiplex->new({ extractors => [ Search::GIN::Extract::Class->new, Search::GIN::Extract::Attributes->new, ] }) ), ); } else { Catalyst::Exception->throw( message => "KiokuDB requires at least 'kiokuObject' or 'kiokuDir' to be set." ); } $self{kiokuScope} = $self{kioku}->new_scope(); return bless \%self, $class; } sub from_session { my ($self, $c, $id) = @_; return $id if ref $id; return $self->find_user({ id => $id }); } sub find_user { my ($self, $userinfo, $c) = @_; return $self->{kioku}->lookup($userinfo->{id}) if $userinfo->{id}; my $q = Search::GIN::Query::Attributes->new({ attributes => $userinfo }); my @res = $self->{kioku}->search($q)->all; # XXX can't we just get the first? return $res[0]; } sub user_supports { my $self = shift; return Catalyst::Authentication::User::KiokuDB->supports(@_); } sub get_user { my ($self, $id) = @_; $self->find_user({id => $id}); } 1;