File Coverage

blib/lib/Catalyst/Model/LDAP.pm
Criterion Covered Total %
statement 15 25 60.0
branch 0 2 0.0
condition 0 2 0.0
subroutine 5 6 83.3
pod 1 1 100.0
total 21 36 58.3


line stmt bran cond sub pod time code
1             package Catalyst::Model::LDAP;
2             # ABSTRACT: LDAP model class for Catalyst
3              
4 3     3   4340188 use strict;
  3         8  
  3         91  
5 3     3   18 use warnings;
  3         5  
  3         92  
6 3     3   17 use base qw/Catalyst::Model/;
  3         11  
  3         852  
7 3     3   529359 use Carp qw/croak/;
  3         9  
  3         230  
8 3     3   21 use Module::Runtime qw/ require_module /;
  3         13  
  3         24  
9              
10             our $VERSION = '0.20';
11              
12              
13             sub ACCEPT_CONTEXT {
14 0     0 1   my ($self) = @_;
15              
16 0           my %args = %$self;
17              
18             # Remove Catalyst-specific parameters (e.g. catalyst_component_name), which
19             # cause issues Net::LDAP
20 0           delete $args{$_} for ( grep { /^_?catalyst/ } keys %args );
  0            
21              
22 0   0       my $class = $args{connection_class} || 'Catalyst::Model::LDAP::Connection';
23 0           require_module($class);
24              
25 0           my $conn = $class->new(%args);
26 0           my $mesg = $conn->bind(%args);
27 0 0         croak 'LDAP error: ' . $mesg->error if $mesg->is_error;
28              
29 0           return $conn;
30             }
31              
32              
33             1;
34              
35             __END__
36              
37             =pod
38              
39             =encoding UTF-8
40              
41             =head1 NAME
42              
43             Catalyst::Model::LDAP - LDAP model class for Catalyst
44              
45             =head1 VERSION
46              
47             version 0.20
48              
49             =head1 SYNOPSIS
50              
51             # Use the Catalyst helper
52             script/myapp_create.pl model Person LDAP ldap.ufl.edu ou=People,dc=ufl,dc=edu
53              
54             # Or, in lib/MyApp/Model/Person.pm
55             package MyApp::Model::Person;
56              
57             use base qw/Catalyst::Model::LDAP/;
58              
59             __PACKAGE__->config(
60             host => 'ldap.ufl.edu',
61             base => 'ou=People,dc=ufl,dc=edu',
62             );
63              
64             1;
65              
66             # Then, in your controller
67             my $mesg = $c->model('Person')->search('(cn=Lou Rhodes)');
68             my @entries = $mesg->entries;
69             print $entries[0]->sn;
70              
71             =head1 DESCRIPTION
72              
73             This is the L<Net::LDAP> model class for Catalyst. It is nothing more
74             than a simple wrapper for L<Net::LDAP>.
75              
76             This class simplifies LDAP access by letting you configure a common
77             set of bind arguments. It also lets you configure a base DN for
78             searching.
79              
80             Please refer to the L<Net::LDAP> documentation for information on what
81             else is available.
82              
83             =head1 CONFIGURATION
84              
85             The following configuration parameters are supported:
86              
87             =over 4
88              
89             =item * C<host>
90              
91             The LDAP server's fully qualified domain name (FQDN),
92             e.g. C<ldap.ufl.edu>. Can also be an IP address, e.g. C<127.0.0.1>.
93              
94             =item * C<base>
95              
96             The base distinguished name (DN) for searching the directory,
97             e.g. C<ou=People,dc=ufl,dc=edu>.
98              
99             =item * C<dn>
100              
101             (Optional) The bind DN for connecting to the directory,
102             e.g. C<dn=admin,dc=ufl,dc=edu>. This can be anyone that has
103             permission to search under the base DN, as per your LDAP server's
104             access control lists.
105              
106             =item * C<password>
107              
108             (Optional) The password for the specified bind DN.
109              
110             =item * C<start_tls>
111              
112             (Optional) Set to C<1> to use TLS when binding to the LDAP server, for
113             secure connections.
114              
115             =item * C<start_tls_options>
116              
117             (Optional) A hashref containing options to use when binding using TLS
118             to the LDAP server.
119              
120             =item * C<options>
121              
122             (Optional) A hashref containing options to pass to
123             L<Catalyst::Model::LDAP::Connection/search>. For example, this can be
124             used to set a sizelimit.
125              
126             NOTE: In previous versions, these options were passed to all
127             L<Net::LDAP> methods. This has changed to allow a cleaner connection
128             interface. If you still require this behavior, create a class
129             inheriting from L<Catalyst::Model::LDAP::Connection> that overrides
130             the specific methods and set C<connection_class>.
131              
132             =item * C<connection_class>
133              
134             (Optional) The class or package name that wraps L<Net::LDAP>.
135             Defaults to L<Catalyst::Model::LDAP::Connection>.
136              
137             See also L<Catalyst::Model::LDAP::Connection/OVERRIDING METHODS>.
138              
139             =item * C<entry_class>
140              
141             (Optional) The class or package name to rebless L<Net::LDAP::Entry>
142             objects as. Defaults to L<Catalyst::Model::LDAP::Entry>.
143              
144             See also L<Catalyst::Model::LDAP::Entry/ADDING ENTRY METHODS>.
145              
146             =back
147              
148             =head1 INTERNAL METHODS
149              
150             =head2 ACCEPT_CONTEXT
151              
152             Bind the client using the current configuration and return it. This
153             method is automatically called when you use e.g. C<< $c->model('LDAP') >>.
154              
155             See L<Catalyst::Model::LDAP::Connection/bind> for information on how
156             the bind operation is done.
157              
158             =head1 SEE ALSO
159              
160             =over 4
161              
162             =item * L<Catalyst::Helper::Model::LDAP>
163              
164             =item * L<Catalyst::Model::LDAP::Connection>
165              
166             =item * L<Catalyst::Model::LDAP::Search>
167              
168             =item * L<Catalyst::Model::LDAP::Entry>
169              
170             =item * L<Catalyst>
171              
172             =item * L<Net::LDAP>
173              
174             =back
175              
176             =head1 AUTHORS
177              
178             =over 4
179              
180             =item * Daniel Westermann-Clark E<lt>danieltwc@cpan.orgE<gt>
181              
182             =item * Adam Jacob E<lt>holoway@cpan.orgE<gt> (TLS support)
183              
184             =item * Marcus Ramberg (paging support and entry AUTOLOAD)
185              
186             =item * Gavin Henry <ghenry@surevoip.co.uk> (authz and raw support, plus bug fixes)
187              
188             =back
189              
190             =head1 ACKNOWLEDGMENTS
191              
192             =over 4
193              
194             =item * Salih Gonullu, for initial work on Catalyst mailing list
195              
196             =back
197              
198             =head1 LICENSE
199              
200             This library is free software; you can redistribute it and/or modify
201             it under the same terms as Perl itself.
202              
203             =head1 AUTHOR
204              
205             Gavin Henry <ghenry@surevoip.co.uk>
206              
207             =head1 COPYRIGHT AND LICENSE
208              
209             This software is copyright (c) 2017 by Gavin Henry.
210              
211             This is free software; you can redistribute it and/or modify it under
212             the same terms as the Perl 5 programming language system itself.
213              
214             =cut