NAME

Catalyst::Model::LDAP::Connection - Convenience methods for Net::LDAP

VERSION

version 0.21

DESCRIPTION

Subclass of Net::LDAP, which adds paging support and an additional method to rebless the entries. See Catalyst::Model::LDAP::Entry for more information.

OVERRIDING METHODS

If you want to override methods provided by Net::LDAP, you can use the connection_class configuration variable. For example:

# In lib/MyApp/Model/LDAP.pm
package MyApp::Model::LDAP;
use base qw/Catalyst::Model::LDAP/;

__PACKAGE__->config(
    # ...
    connection_class => 'MyApp::LDAP::Connection',
);

1;

# In lib/MyApp/LDAP/Connection.pm
package MyApp::LDAP::Connection;
use base qw/Catalyst::Model::LDAP::Connection/;
use Authen::SASL;

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

    my $sasl = Authen::SASL->new(...);
    push @args, sasl => $sasl;

    $self->SUPER::bind(@args);
}

1;

METHODS

new

Create a new connection to the specific LDAP server.

my $conn = Catalyst::Model::LDAP::Connection->new(
    host => 'ldap.ufl.edu',
    base => 'ou=People,dc=ufl,dc=edu',
);

On connection failure, an error is thrown using "croak" in Carp.

bind

Bind to the configured LDAP server using the specified credentials.

$conn->bind(
    dn       => 'uid=dwc,ou=People,dc=ufl,dc=edu',
    password => 'secret',
);

This method behaves similarly to "bind" in Net::LDAP, except that it gives an explicit name to the dn parameter. For example, if you need to use SASL to bind to the server, you can specify that in your call:

$conn->bind(
    dn   => 'uid=dwc,ou=People,dc=ufl,dc=edu',
    sasl => Authen::SASL->new(mechanism => 'GSSAPI'),
);

Additionally, if the start_tls configuration option is present, the client will use "start_tls" in Net::LDAP to make your connection secure.

For more information on customizing the bind process, see "OVERRIDING METHODS".

Search the configured directory using a given filter. For example:

my $mesg = $c->model('Person')->search('(cn=Lou Rhodes)');
my $entry = $mesg->shift_entry;
print $entry->title;

This method overrides the search method in Net::LDAP to add paging support. The following additional options are supported:

raw

Use REGEX to denote the names of attributes that are to be considered binary in search results.

When this option is given, Net::LDAP converts all values of attributes not matching this REGEX into Perl UTF-8 strings so that the regular Perl operators (pattern matching, ...) can operate as one expects even on strings with international characters.

If this option is not given, attribute values are treated as byte strings.

Generally, you'll only ever need to do this if using RFC'd LDAP attributes and not a custom LDAP schema:

raw => qr/(?i:^jpegPhoto|;binary)/,
authz

This allows you to use LDAPv3 Proxy Authorization control object, i.e. (Net::LDAP::Control::ProxyAuth):

authz => 'uid=gavinhenry,ou=users,dc=surevoip,dc=co,dc=uk',
page

Which page to return.

rows

Rows to return per page. Defaults to 25.

order_by

Sort the records (on the server) by the specified attribute. Required if you use page.

When paging is active, this method returns the server response and a Data::Page object. Otherwise, it returns the server response only.

SEE ALSO

AUTHORS

  • Daniel Westermann-Clark

  • Marcus Ramberg (paging support)

  • Gavin Henry <ghenry@surevoip.co.uk> (authz and raw support, plus bug fixes)

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Gavin Henry <ghenry@surevoip.co.uk>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Gavin Henry.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.