[Catalyst] LDAP

Jonathan Rockway jon at jrock.us
Thu Jan 24 15:40:41 GMT 2008


"Carl Johnstone" <catalyst at fadetoblack.me.uk> writes:

> Hi,
>
> I've been playing around with the LDAP stuff in Catalyst, we have a
> need to share user data externally for authentication reasons and
> currently believe LDAP is a good solution for this.
>
> To this end I've got C:P:Auth:Store:LDAP correctly authenticating
> users against a LDAP database. I've also got C:Model:LDAP pulling
> users out of the DB so that we can display names next to
> user-submitted content.
>
> Now to get to this stage I've got two lots of configuration, and
> effectively two chunks of code doing very similar jobs. I now need to
> add a custom method, and can't see anyway outside of doing it twice.
>
> Next up I want to link my DBIC schema to the LDAP stuff so I can
> automatically inflate users, however on this project we have some
> chunks of code that work outside Catalyst using the same schema, so I
> can't link them to the Catalyst Model. Ideally what I need here is
> some kind of generic ORM layer, an a thinner Catalyst Model which uses
> it.

I haven't done exactly this, but I have used linked two outside
databases for the purpose of "joining" them inside Catalyst.  This
ended up being very simple.   I wrote a class like this:

  package MyApp::Backend::CleverName;
  use Moose;
  use MyApp::DB::Foo;
  use MyApp::DB::Bar;

  has foo_db => (is => ro, isa => 'MyApp::DB::Foo', ...);
  has bar_db => (is => ro, isa => 'MyApp::DB::Bar', ...);

  sub operation_that_needs_both_dbs {
      my ($self) = @_;
      $self->foo_db->whatever + $self->bar_db->whatever; # you get the idea
  }
  
  1;

Then I used it in Catalyst like this:

  package MyApp::Model::CleverName;
  use strict;
  use warnings;
  
  use base 'Catalyst::Model::Factory';
  
  __PACKAGE__->config( class => MyApp::Backend::CleverName' );
  
  sub prepare_arguments {
      my ($self, $c) = @_;
      return 
        { 
            foo_db => $c->model('FooDB')->schema,
            bar_db => $c->model('BarDB')->schema,
        };
  }

Then I got a Backend::CleverName whenever I said 

  $c->model('CleverName')

inside Catalyst.

Hope this helps.

Regards,
Jonathan Rockway



More information about the Catalyst mailing list