package Catalyst::Model::LDAP; use strict; use warnings; use base qw/Catalyst::Model/; use Carp qw/croak/; our $VERSION = '0.17'; =head1 NAME Catalyst::Model::LDAP - LDAP model class for Catalyst =head1 SYNOPSIS # Use the Catalyst helper script/myapp_create.pl model Person LDAP ldap.ufl.edu ou=People,dc=ufl,dc=edu # Or, in lib/MyApp/Model/Person.pm package MyApp::Model::Person; use base qw/Catalyst::Model::LDAP/; __PACKAGE__->config( host => 'ldap.ufl.edu', base => 'ou=People,dc=ufl,dc=edu', ); 1; # Then, in your controller my $mesg = $c->model('Person')->search('(cn=Lou Rhodes)'); my @entries = $mesg->entries; print $entries[0]->sn; =head1 DESCRIPTION This is the L model class for Catalyst. It is nothing more than a simple wrapper for L. This class simplifies LDAP access by letting you configure a common set of bind arguments. It also lets you configure a base DN for searching. Please refer to the L documentation for information on what else is available. =head1 CONFIGURATION The following configuration parameters are supported: =over 4 =item * C The LDAP server's fully qualified domain name (FQDN), e.g. C. Can also be an IP address, e.g. C<127.0.0.1>. =item * C The base distinguished name (DN) for searching the directory, e.g. C. =item * C (Optional) The bind DN for connecting to the directory, e.g. C. This can be anyone that has permission to search under the base DN, as per your LDAP server's access control lists. =item * C (Optional) The password for the specified bind DN. =item * C (Optional) Set to C<1> to use TLS when binding to the LDAP server, for secure connections. =item * C (Optional) A hashref containing options to use when binding using TLS to the LDAP server. =item * C (Optional) A hashref containing options to pass to L. For example, this can be used to set a sizelimit. NOTE: In previous versions, these options were passed to all L methods. This has changed to allow a cleaner connection interface. If you still require this behavior, create a class inheriting from L that overrides the specific methods and set C. =item * C (Optional) The class or package name that wraps L. Defaults to L. See also L. =item * C (Optional) The class or package name to rebless L objects as. Defaults to L. See also L. =back =head1 INTERNAL METHODS =head2 ACCEPT_CONTEXT Bind the client using the current configuration and return it. This method is automatically called when you use e.g. C<< $c->model('LDAP') >>. See L for information on how the bind operation is done. =cut sub ACCEPT_CONTEXT { my ($self) = @_; my %args = %$self; # Remove Catalyst-specific parameters (e.g. catalyst_component_name), which # cause issues Net::LDAP delete $args{$_} for (grep { /^_?catalyst/ } keys %args); my $class = $args{connection_class} || 'Catalyst::Model::LDAP::Connection'; eval "require $class"; die $@ if $@; my $conn = $class->new(%args); my $mesg = $conn->bind(%args); croak 'LDAP error: ' . $mesg->error if $mesg->is_error; return $conn; } =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =item * L =back =head1 AUTHORS =over 4 =item * Daniel Westermann-Clark Edanieltwc@cpan.orgE =item * Adam Jacob Eholoway@cpan.orgE (TLS support) =item * Marcus Ramberg (paging support and entry AUTOLOAD) =back =head1 ACKNOWLEDGMENTS =over 4 =item * Salih Gonullu, for initial work on Catalyst mailing list =back =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;