[Catalyst] Model::LDAP vs Authentication::Credential::LDAP

Daniel Westermann-Clark dwc at pobox.com
Thu Aug 7 17:27:01 BST 2008


On 2008-08-07 17:52:36 +0200, Buchan Milne wrote:
> So, I would prefer to have my Model::LDAP models (re-)bind as the
> authenticated user.
> 
> I wrote a connection_class for my models, but it seems that the
> connection_class doesn't have access to the context, so I can't
> retrieve $c- >user->ldap_entry->dn or $c->sessionid().

You can do this using an ACCEPT_CONTEXT method on your model class,
which tells Catalyst that your model needs information about the
current request to do its job.

For example:

package YourApp::Model::People;

use base qw/Catalyst::Model::LDAP/;
use Class::C3;

__PACKAGE__->config(connection_class => 'YourApp::LDAP::Connection');

sub ACCEPT_CONTEXT {
    my $self = shift;
    my $c = $_[0];

    my $conn = $self->next::method(@_);

    if ($conn->can('catalyst_user') and $c->user_exists) {
        $conn->catalyst_user($c->user);
    }

    return $conn;
}

1;

In your connection class, you simply add an accessor for
e.g. 'catalyst_user' and then use it in the bind step:

YourApp::LDAP::Connection;

use base qw/Catalyst::Model::LDAP::Connection/;
use Authen::SASL qw/Perl/;
use Class::C3;

__PACKAGE__->mk_accessors(qw/catalyst_user/);

sub bind {
    my ($self, %args) = @_;

    # Manipulate %args to include information from $self->catalyst_user

    return $self->next::method(%args);
}

1;

Hope this helps!

-- 
Daniel Westermann-Clark



More information about the Catalyst mailing list