2 Catalyst::Authentication::Store::LDAP - Authentication from an LDAP
12 default_realm => "ldap",
17 password_field => "password",
18 password_type => "self_check",
21 binddn => "anonymous",
22 bindpw => "dontcarehow",
24 ldap_server => "ldap.yourcompany.com",
25 ldap_server_options => { timeout => 30 },
26 role_basedn => "ou=groups,ou=OxObjects,dc=yourcompany,dc=com",
28 role_filter => "(&(objectClass=posixGroup)(memberUid=%s))",
30 role_search_options => { deref => "always" },
32 role_search_as_user => 0,
34 start_tls_options => { verify => "none" },
35 entry_class => "MyApp::LDAP::Entry",
37 user_basedn => "ou=people,dc=yourcompany,dc=com",
39 user_filter => "(&(objectClass=posixAccount)(uid=%s))",
41 user_search_options => { deref => "always" },
42 user_results_filter => sub { return shift->pop_entry },
50 my ( $self, $c ) = @_;
53 id => $c->req->param("login"),
54 password => $c->req->param("password")
56 $c->res->body("Welcome " . $c->user->username . "!");
60 This plugin implements the Catalyst::Authentication v.10 API. Read that
61 documentation first if you are upgrading from a previous version of this
64 This plugin uses "Net::LDAP" to let your application authenticate
65 against an LDAP directory. It has a pretty high degree of flexibility,
66 given the wide variation of LDAP directories and schemas from one system
69 It authenticates users in two steps:
71 1) A search of the directory is performed, looking for a user object
72 that matches the username you pass. This is done with the bind
73 credentials supplied in the "binddn" and "bindpw" configuration options.
75 2) If that object is found, we then re-bind to the directory as that
76 object. Assuming this is successful, the user is Authenticated.
80 Set Configuration to be loaded via Config.yml in YourApp.pm
82 use YAML qw(LoadFile);
83 use Path::Class 'file';
87 file(__PACKAGE__->config->{home}, 'Config.yml')
91 Settings in Config.yml (adapt these to whatever configuration format you
94 # Config for Store::LDAP
101 password_field: password
102 password_type: self_check
105 ldap_server: ldap.yourcompany.com
113 user_basedn: ou=people,dc=yourcompany,dc=com
114 user_filter: (&(objectClass=posixAccount)(uid=%s))
120 role_basedn: ou=groups,ou=OxObjects,dc=yourcompany,dc=com
121 role_filter: (&(objectClass=posixGroup)(memberUid=%s))
128 NOTE: The settings above reflect the default values for OpenLDAP. If you
129 are using Active Directory instead, Matija Grabnar suggests that the
130 following tweeks to the example configuration will work:
132 user_basedn: ou=Domain Users,ou=Accounts,dc=mycompany,dc=com
133 user_field: samaccountname
134 user_filter: (sAMAccountName=%s)
136 He also notes: "I found the case in the value of user_field to be
137 significant: it didn't seem to work when I had the mixed case value
141 This should be the hostname of your LDAP server.
144 This should be a hashref containing options to pass to Net::LDAP->new().
145 See Net::LDAP for the full list.
148 This should be the DN of the object you wish to bind to the directory as
149 during the first phase of authentication. (The user lookup phase)
151 If you supply the value "anonymous" to this option, we will bind
152 anonymously to the directory. This is the default.
155 This is the password for the initial bind.
158 If this is set to 1, we will convert the LDAP connection to use SSL.
161 This is a hashref, which contains the arguments to the Net::LDAP
162 start_tls method. See Net::LDAP for the complete list of options.
165 This is the basedn for the initial user lookup. Usually points to the
166 top of your "users" branch; ie "ou=people,dc=yourcompany,dc=com".
169 This is the LDAP Search filter used during user lookup. The special
170 string '%s' will be replaced with the username you pass to $c->login. By
171 default it is set to '(uid=%s)'. Other possibly useful filters:
173 (&(objectClass=posixAccount)(uid=%s))
174 (&(objectClass=User)(cn=%s))
177 This specifies the scope of the search for the initial user lookup.
178 Valid values are "base", "one", and "sub". Defaults to "sub".
181 This is the attribute of the returned LDAP object we will use for their
182 "username". This defaults to "uid". If you had user_filter set to:
184 (&(objectClass=User)(cn=%s))
186 You would probably set this to "cn". You can also set it to an array, to
187 allow more than one login field. The first field will be returned as
188 identifier for the user.
191 This takes a hashref. It will append it's values to the call to
192 Net::LDAP's "search" method during the initial user lookup. See
193 Net::LDAP for valid options.
195 Be careful not to specify:
201 As they are already taken care of by other configuration options.
204 This is a Perl CODE ref that can be used to filter out multiple results
205 from your LDAP query. In theory, your LDAP query should only return one
206 result and find_user() will throw an exception if it encounters more
207 than one result. However, if you have, for whatever reason, a legitimate
208 reason for returning multiple search results from your LDAP query, use
209 "user_results_filter" to filter out the LDAP entries you do not want
210 considered. Your CODE ref should expect a single argument, a
211 Net::LDAP::Search object, and it should return exactly one value, a
212 Net::LDAP::Entry object.
216 user_results_filter => sub {
217 my $search_obj = shift;
218 foreach my $entry ($search_obj->entries) {
219 return $entry if my_match_logic( $entry );
221 return undef; # i.e., no match
225 Whether or not to enable role lookups. It defaults to true; set it to 0
226 if you want to always avoid role lookups.
229 This should be the basedn where the LDAP Objects representing your roles
233 This should be the LDAP Search filter to use during the role lookup. It
234 defaults to '(memberUid=%s)'. The %s in this filter is replaced with the
235 value of the "role_value" configuration option.
237 So, if you had a role_value of "cn", then this would be populated with
238 the cn of the User's LDAP object. The special case is a role_value of
239 "dn", which will be replaced with the User's DN.
242 This specifies the scope of the search for the user's role lookup. Valid
243 values are "base", "one", and "sub". Defaults to "sub".
246 Should be set to the Attribute of the Role Object's returned during Role
247 lookup you want to use as the "name" of the role. Defaults to "CN".
250 This is the attribute of the User object we want to use in our
251 role_filter. If this is set to "dn", we will use the User Objects DN.
254 This takes a hashref. It will append it's values to the call to
255 Net::LDAP's "search" method during the user's role lookup. See Net::LDAP
258 Be careful not to specify:
264 As they are already taken care of by other configuration options.
267 By default this setting is false, and the role search will be performed
268 by binding to the directory with the details in the *binddn* and
269 *bindpw* fields. If this is set to false, then the role search will
270 instead be performed when bound as the user you authenticated as.
273 The name of the class of LDAP entries returned. This class should exist
274 and is expected to be a subclass of Net::LDAP::Entry
277 The name of the class of user object returned. By default, this is
278 Catalyst::Authentication::Store::LDAP::User.
282 This method will populate "default_auth_store" in
283 Catalyst::Plugin::Authentication with this object.
286 Adam Jacob <holoway@cpan.org>
288 Some parts stolen shamelessly and entirely from
289 Catalyst::Plugin::Authentication::Store::Htpasswd.
291 Currently maintained by Peter Karman <karman@cpan.org>.
294 To nothingmuch, ghenry, castaway and the rest of #catalyst for the help.
298 Catalyst::Authentication::Store::LDAP,
299 Catalyst::Authentication::Store::LDAP::User,
300 Catalyst::Authentication::Store::LDAP::Backend,
301 Catalyst::Plugin::Authentication, Net::LDAP
304 Copyright (c) 2005 the aforementioned authors. All rights reserved. This
305 program is free software; you can redistribute it and/or modify it under
306 the same terms as Perl itself.