activeldap 1.0.2 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +32 -0
- data/README +8 -1
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/app/controllers/{application.rb → application_controller.rb} +3 -1
- data/examples/al-admin/app/views/account/sign_up.html.erb +6 -5
- data/examples/al-admin/config/boot.rb +1 -0
- data/examples/al-admin/config/environment.rb +4 -2
- data/examples/al-admin/config.ru +7 -0
- data/examples/al-admin/lib/ldap_test_helper.rb +38 -0
- data/examples/al-admin/lib/tasks/gettext.rake +3 -2
- data/examples/al-admin/lib/tasks/testing.rake +10 -0
- data/examples/al-admin/po/en/al-admin.po +4 -4
- data/examples/al-admin/po/ja/al-admin.po +4 -4
- data/examples/al-admin/po/nl/al-admin.po +3 -3
- data/examples/al-admin/public/dispatch.cgi +2 -2
- data/examples/al-admin/public/dispatch.fcgi +1 -1
- data/examples/al-admin/public/dispatch.rb +2 -2
- data/examples/al-admin/test/functional/account_controller_test.rb +2 -14
- data/examples/al-admin/test/functional/attributes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/directory_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/object_classes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/syntaxes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/users_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/welcome_controller_test.rb +2 -12
- data/examples/al-admin/test/integration/sign_up_test.rb +44 -0
- data/examples/al-admin/test/run-test.sh +1 -1
- data/examples/al-admin/test/test_helper.rb +25 -1
- data/examples/al-admin/test/unit/user_test.rb +1 -2
- data/examples/groupadd +2 -2
- data/examples/groupdel +2 -2
- data/examples/groupls +2 -2
- data/examples/groupmod +2 -2
- data/examples/lpasswd +2 -2
- data/examples/objects/group.rb +2 -2
- data/examples/objects/user.rb +1 -1
- data/examples/ouadd +2 -2
- data/examples/useradd +2 -2
- data/examples/useradd-binary +6 -3
- data/examples/userdel +2 -2
- data/examples/userls +2 -2
- data/examples/usermod +2 -2
- data/examples/usermod-binary-add +6 -3
- data/examples/usermod-binary-add-time +6 -3
- data/examples/usermod-binary-del +2 -2
- data/examples/usermod-lang-add +2 -2
- data/lib/active_ldap/adapter/base.rb +47 -23
- data/lib/active_ldap/adapter/jndi.rb +30 -28
- data/lib/active_ldap/adapter/jndi_connection.rb +6 -0
- data/lib/active_ldap/adapter/ldap.rb +25 -26
- data/lib/active_ldap/adapter/net_ldap.rb +28 -33
- data/lib/active_ldap/adapter/net_ldap_ext.rb +0 -6
- data/lib/active_ldap/association/proxy.rb +2 -1
- data/lib/active_ldap/attributes.rb +31 -0
- data/lib/active_ldap/base.rb +75 -31
- data/lib/active_ldap/compatible.rb +44 -0
- data/lib/active_ldap/configuration.rb +3 -3
- data/lib/active_ldap/connection.rb +41 -12
- data/lib/active_ldap/distinguished_name.rb +1 -0
- data/lib/active_ldap/get_text.rb +0 -7
- data/lib/active_ldap/ldif.rb +59 -44
- data/lib/active_ldap/operations.rb +41 -10
- data/lib/active_ldap/schema.rb +41 -6
- data/lib/active_ldap/user_password.rb +7 -7
- data/lib/active_ldap/validations.rb +24 -12
- data/lib/active_ldap/xml.rb +2 -2
- data/lib/active_ldap.rb +120 -139
- data/po/en/active-ldap.po +5 -5
- data/po/ja/active-ldap.po +5 -5
- data/rails/README +2 -2
- data/rails/init.rb +2 -2
- data/test/al-test-utils.rb +11 -4
- data/test/run-test.rb +6 -2
- data/test/test_associations.rb +4 -4
- data/test/test_attributes.rb +3 -1
- data/test/test_base.rb +75 -15
- data/test/test_base_per_instance.rb +7 -1
- data/test/test_bind.rb +4 -4
- data/test/test_connection.rb +36 -14
- data/test/test_connection_per_class.rb +5 -5
- data/test/test_connection_per_dn.rb +11 -5
- data/test/test_groupadd.rb +2 -2
- data/test/test_groupdel.rb +2 -2
- data/test/test_groupls.rb +1 -1
- data/test/test_groupmod.rb +2 -2
- data/test/test_ldif.rb +11 -1
- data/test/test_schema.rb +38 -2
- data/test/test_syntax.rb +12 -2
- data/test/test_useradd-binary.rb +1 -0
- data/test/test_usermod-binary-add-time.rb +1 -0
- data/test/test_usermod-binary-add.rb +1 -0
- data/test/test_validation.rb +24 -13
- data/test-unit/lib/test/unit/assertions.rb +97 -14
- data/test-unit/lib/test/unit/autorunner.rb +20 -4
- data/test-unit/lib/test/unit/priority.rb +21 -1
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +7 -4
- data/test-unit/test/test_assertions.rb +52 -5
- metadata +10 -14
- data/rails/plugin/active_ldap/README +0 -54
- data/rails/plugin/active_ldap/generators/README +0 -2
- data/rails/plugin/active_ldap/generators/model_active_ldap/USAGE +0 -17
- data/rails/plugin/active_ldap/generators/model_active_ldap/model_active_ldap_generator.rb +0 -70
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/fixtures.yml +0 -11
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/model_active_ldap.rb +0 -3
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/unit_test.rb +0 -10
- data/rails/plugin/active_ldap/generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +0 -7
- data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +0 -20
- data/rails/plugin/active_ldap/init.rb +0 -36
- data/rails_generators/scaffold_al/scaffold_al_generator.rb +0 -20
data/lib/active_ldap.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/ruby
|
|
2
|
-
# =
|
|
2
|
+
# = ActiveLdap
|
|
3
3
|
#
|
|
4
|
-
# "
|
|
4
|
+
# "ActiveLdap" Copyright (C) 2004,2005 Will Drewry mailto:will@alum.bu.edu
|
|
5
|
+
# Copyright (C) 2006-2009 Kouhei Sutou <kou@cozmixng.org>
|
|
5
6
|
#
|
|
6
7
|
# == Introduction
|
|
7
8
|
#
|
|
8
|
-
#
|
|
9
|
+
# ActiveLdap is a novel way of interacting with LDAP. Most interaction with
|
|
9
10
|
# LDAP is done using clunky LDIFs, web interfaces, or with painful APIs that
|
|
10
|
-
# required a thick reference manual nearby.
|
|
11
|
-
# Inspired by ActiveRecord[http://activerecord.rubyonrails.org],
|
|
11
|
+
# required a thick reference manual nearby. ActiveLdap aims to fix that.
|
|
12
|
+
# Inspired by ActiveRecord[http://activerecord.rubyonrails.org], ActiveLdap provides an
|
|
12
13
|
# object oriented interface to LDAP entries.
|
|
13
14
|
#
|
|
14
15
|
# The target audience is system administrators and LDAP users everywhere that
|
|
@@ -29,40 +30,38 @@
|
|
|
29
30
|
# * RFC1777[http://www.faqs.org/rfcs/rfc1777.html] - Lightweight Directory Access Protocol
|
|
30
31
|
# * OpenLDAP[http://www.openldap.org]
|
|
31
32
|
#
|
|
32
|
-
# === So why use
|
|
33
|
+
# === So why use ActiveLdap?
|
|
33
34
|
#
|
|
34
35
|
# Well if you like to fumble around in the dark, dank innards of LDAP, you can
|
|
35
36
|
# quit reading now. However, if you'd like a cleaner way to integrate LDAP in to
|
|
36
|
-
# your existing code, hopefully that's why you'll want to use
|
|
37
|
+
# your existing code, hopefully that's why you'll want to use ActiveLdap.
|
|
37
38
|
#
|
|
38
39
|
# Using LDAP directly (even with the excellent Ruby/LDAP), leaves you bound to
|
|
39
40
|
# the world of the predefined LDAP API. While this API is important for many
|
|
40
41
|
# reasons, having to extract code out of LDAP search blocks and create huge
|
|
41
42
|
# arrays of LDAP.mod entries make code harder to read, less intuitive, and just
|
|
42
|
-
# less fun to write. Hopefully,
|
|
43
|
+
# less fun to write. Hopefully, ActiveLdap will remedy all of these
|
|
43
44
|
# problems!
|
|
44
45
|
#
|
|
45
46
|
# == Getting Started
|
|
46
47
|
#
|
|
47
|
-
#
|
|
48
|
+
# ActiveLdap does have some overhead when you get started. You must not
|
|
48
49
|
# only install the package and all of it's requirements, but you must also make
|
|
49
50
|
# customizations that will let it work in your environment.
|
|
50
51
|
#
|
|
51
52
|
# === Requirements
|
|
52
53
|
#
|
|
53
|
-
# * Ruby[http://www.ruby-lang.org] 1.8.x
|
|
54
|
-
# * Ruby/LDAP[http://ruby-
|
|
55
|
-
# *
|
|
56
|
-
# * An LDAP server compatible with Ruby/LDAP: OpenLDAP[http://www.openldap.org], etc
|
|
54
|
+
# * A Ruby implementation: Ruby[http://www.ruby-lang.org] 1.8.x, 1.9.1 or JRuby[http://jruby.codehaus.org/]
|
|
55
|
+
# * A LDAP library: Ruby/LDAP[http://code.google.com/p/ruby-activeldap/wiki/RubyLDAP] (for Ruby), Net::LDAP[http://rubyforge.org/projects/net-ldap/] (for Ruby or JRuby) or JNDI (for JRuby)
|
|
56
|
+
# * A LDAP server: OpenLDAP[http://www.openldap.org], etc
|
|
57
57
|
# - Your LDAP server must allow root_dse queries to allow for schema queries
|
|
58
|
-
# * Examples also require: Ruby/Password[http://raa.ruby-lang.org/project/ruby-password/]
|
|
59
58
|
#
|
|
60
59
|
# === Installation
|
|
61
60
|
#
|
|
62
61
|
# Assuming all the requirements are installed, you can install by grabbing the latest tgz file from
|
|
63
62
|
# the download site[http://rubyforge.org/frs/?group_id=381].
|
|
64
63
|
#
|
|
65
|
-
# The following steps will get the
|
|
64
|
+
# The following steps will get the ActiveLdap installed in no time!
|
|
66
65
|
#
|
|
67
66
|
# $ tar -xzvf ruby-activeldap-current.tgz
|
|
68
67
|
# $ cd ruby-activeldap-VERSION
|
|
@@ -90,7 +89,7 @@
|
|
|
90
89
|
#
|
|
91
90
|
# === Customizations
|
|
92
91
|
#
|
|
93
|
-
# Now that
|
|
92
|
+
# Now that ActiveLdap is installed and working, we still have a few more
|
|
94
93
|
# steps to make it useful for programming.
|
|
95
94
|
#
|
|
96
95
|
# Let's say that you are writing a Ruby program for managing user and group
|
|
@@ -116,7 +115,7 @@
|
|
|
116
115
|
#
|
|
117
116
|
# == Usage
|
|
118
117
|
#
|
|
119
|
-
# This section covers using
|
|
118
|
+
# This section covers using ActiveLdap from writing extension classes to
|
|
120
119
|
# writing applications that use them.
|
|
121
120
|
#
|
|
122
121
|
# Just to give a taste of what's to come, here is a quick example using irb:
|
|
@@ -126,7 +125,7 @@
|
|
|
126
125
|
# Here's an extension class that maps to the LDAP Group objects:
|
|
127
126
|
#
|
|
128
127
|
# irb> class Group < ActiveLdap::Base
|
|
129
|
-
# irb*
|
|
128
|
+
# irb* ldap_mapping
|
|
130
129
|
# irb* end
|
|
131
130
|
#
|
|
132
131
|
# Here is the Group class in use:
|
|
@@ -135,10 +134,7 @@
|
|
|
135
134
|
# => ["root", "daemon", "bin", "sys", "adm", "tty", ..., "develop"]
|
|
136
135
|
#
|
|
137
136
|
# irb> group = Group.find("develop")
|
|
138
|
-
# => #<Group
|
|
139
|
-
#
|
|
140
|
-
# irb> group.members.collect {|member| member.uid}
|
|
141
|
-
# => ["drewry"]
|
|
137
|
+
# => #<Group objectClass:<...> ...>
|
|
142
138
|
#
|
|
143
139
|
# irb> group.cn
|
|
144
140
|
# => "develop"
|
|
@@ -155,7 +151,7 @@
|
|
|
155
151
|
#
|
|
156
152
|
# ==== Why do I need them?
|
|
157
153
|
#
|
|
158
|
-
# Extension classes are what make
|
|
154
|
+
# Extension classes are what make ActiveLdap "active"! They do all the
|
|
159
155
|
# background work to make easy-to-use objects by mapping the LDAP object's
|
|
160
156
|
# attributes on to a Ruby class.
|
|
161
157
|
#
|
|
@@ -169,7 +165,7 @@
|
|
|
169
165
|
# ===== ldap_mapping
|
|
170
166
|
#
|
|
171
167
|
# ldap_mapping is the only required method to setup an extension class for use
|
|
172
|
-
# with
|
|
168
|
+
# with ActiveLdap. It must be called inside of a subclass as shown above.
|
|
173
169
|
#
|
|
174
170
|
# Below is a much more realistic Group class:
|
|
175
171
|
#
|
|
@@ -208,9 +204,9 @@
|
|
|
208
204
|
# for dn_attribute matches.
|
|
209
205
|
# (e.g. cn=develop,ou=DevGroups,ou=Groups,dc=dataspill,dc=org)
|
|
210
206
|
#
|
|
211
|
-
# Something's missing: :classes. :classes is used to tell
|
|
207
|
+
# Something's missing: :classes. :classes is used to tell ActiveLdap what
|
|
212
208
|
# the minimum requirement is when creating a new object. LDAP uses objectClasses
|
|
213
|
-
# to define what attributes a LDAP object may have.
|
|
209
|
+
# to define what attributes a LDAP object may have. ActiveLdap needs to know
|
|
214
210
|
# what classes are required when creating a new object. Of course, you can leave
|
|
215
211
|
# that field out to default to ['top'] only. Then you can let each application
|
|
216
212
|
# choose what objectClasses their objects should have by calling the method e.g.
|
|
@@ -222,8 +218,8 @@
|
|
|
222
218
|
# may help avoid programmer error later.
|
|
223
219
|
#
|
|
224
220
|
# :classes isn't the only optional argument. If :dn_attribute is left off,
|
|
225
|
-
# it defaults to
|
|
226
|
-
# it will default to 'ou=
|
|
221
|
+
# it defaults to super class's value or 'cn'. If :prefix is left off,
|
|
222
|
+
# it will default to 'ou=PluralizedClassName'. In this
|
|
227
223
|
# case, it would be 'ou=Groups'.
|
|
228
224
|
#
|
|
229
225
|
# :classes should be an Array. :dn_attribute should be a String and so should
|
|
@@ -256,7 +252,7 @@
|
|
|
256
252
|
#
|
|
257
253
|
# irb> class User < ActiveLdap::Base
|
|
258
254
|
# irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'People', :classes => ['top','account']
|
|
259
|
-
# irb* belongs_to :groups, :
|
|
255
|
+
# irb* belongs_to :groups, :class_name => 'Group', :many => 'memberUid', :foreign_key => 'uid'
|
|
260
256
|
# irb* end
|
|
261
257
|
#
|
|
262
258
|
# Now, class User will have a method called 'groups' which will retrieve all
|
|
@@ -264,7 +260,7 @@
|
|
|
264
260
|
#
|
|
265
261
|
# irb> me = User.find('drewry')
|
|
266
262
|
# irb> me.groups
|
|
267
|
-
# => [#<Group
|
|
263
|
+
# => [#<Group ...>, #<Group ...>, ...]
|
|
268
264
|
# irb> me.groups.each { |group| p group.cn };nil
|
|
269
265
|
# "cdrom"
|
|
270
266
|
# "audio"
|
|
@@ -284,18 +280,18 @@
|
|
|
284
280
|
# Now let's talk about the arguments. The first argument is the name of the
|
|
285
281
|
# method you wish to create. In this case, we created a method called groups
|
|
286
282
|
# using the symbol :groups. The next collection of arguments are actually a Hash
|
|
287
|
-
# (as with ldap_mapping). :
|
|
283
|
+
# (as with ldap_mapping). :class_name should be a string that has the name of a
|
|
288
284
|
# class you've already included. If you class is inside of a module, be sure to
|
|
289
|
-
# put the whole name, e.g. :
|
|
285
|
+
# put the whole name, e.g. :class_name => "MyLdapModule::Group". :foreign_key
|
|
290
286
|
# tells belongs_to what attribute Group objects have that match the
|
|
291
287
|
# :many. :many is the name of the local attribute whose value
|
|
292
|
-
# should be looked up in Group under the
|
|
288
|
+
# should be looked up in Group under the foreign key. If :foreign_key is left
|
|
293
289
|
# off of the argument list, it is assumed to be the dn_attribute. With this in
|
|
294
290
|
# mind, the above definition could become:
|
|
295
291
|
#
|
|
296
292
|
# irb> class User < ActiveLdap::Base
|
|
297
293
|
# irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'People', :classes => ['top','account']
|
|
298
|
-
# irb* belongs_to :groups, :
|
|
294
|
+
# irb* belongs_to :groups, :class_name => 'Group', :many => 'memberUid'
|
|
299
295
|
# irb* end
|
|
300
296
|
#
|
|
301
297
|
# In addition, you can do simple membership tests by doing the following:
|
|
@@ -314,7 +310,7 @@
|
|
|
314
310
|
#
|
|
315
311
|
# class Group < ActiveLdap::Base
|
|
316
312
|
# ldap_mapping :dn_attribute => 'cn', :prefix => 'ou=Groups', :classes => ['top', 'posixGroup']
|
|
317
|
-
# has_many :members, :
|
|
313
|
+
# has_many :members, :class_name => "User", :wrap => "memberUid", :primary_key => 'uid'
|
|
318
314
|
# end
|
|
319
315
|
#
|
|
320
316
|
# Now we can see that group develop has user 'drewry' as a member, and it can
|
|
@@ -323,13 +319,13 @@
|
|
|
323
319
|
# irb> develop = Group.find('develop')
|
|
324
320
|
# => ...
|
|
325
321
|
# irb> develop.members
|
|
326
|
-
# => [#<User
|
|
322
|
+
# => [#<User ...>, #<User ...>]
|
|
327
323
|
#
|
|
328
324
|
#
|
|
329
325
|
# The arguments for has_many follow the exact same idea that belongs_to's
|
|
330
326
|
# arguments followed. :wrap's contents are used to search for matching
|
|
331
327
|
# :primary_key content. If :primary_key is not specified, it defaults to the
|
|
332
|
-
# dn_attribute of the specified :
|
|
328
|
+
# dn_attribute of the specified :class_name.
|
|
333
329
|
#
|
|
334
330
|
# === Using these new classes
|
|
335
331
|
#
|
|
@@ -341,21 +337,21 @@
|
|
|
341
337
|
#
|
|
342
338
|
# ==== .find
|
|
343
339
|
#
|
|
344
|
-
# .find is a class method that is accessible from
|
|
345
|
-
# 'ldap_mapping' called. When
|
|
346
|
-
# class.
|
|
340
|
+
# .find is a class method that is accessible from
|
|
341
|
+
# any subclass of Base that has 'ldap_mapping' called. When
|
|
342
|
+
# called .first(:first) returns the first match of the given class.
|
|
347
343
|
#
|
|
348
|
-
# irb> Group.find('*
|
|
349
|
-
# => "
|
|
344
|
+
# irb> Group.find(:first, 'deve*").cn
|
|
345
|
+
# => "develop"
|
|
350
346
|
#
|
|
351
347
|
# In this simple example, Group.find took the search string of 'deve*' and
|
|
352
348
|
# searched for the first match in Group where the dn_attribute matched the
|
|
353
349
|
# query. This is the simplest example of .find.
|
|
354
350
|
#
|
|
355
|
-
# irb> Group.find(:all
|
|
351
|
+
# irb> Group.find(:all).collect {|group| group.cn}
|
|
356
352
|
# => ["root", "daemon", "bin", "sys", "adm", "tty", ..., "develop"]
|
|
357
353
|
#
|
|
358
|
-
# Here .find(:all) returns all matches to the same query. Both .find and
|
|
354
|
+
# Here .find(:all) returns all matches to the same query. Both .find(:first) and
|
|
359
355
|
# .find(:all) also can take more expressive arguments:
|
|
360
356
|
#
|
|
361
357
|
# irb> Group.find(:all, :attribute => 'gidNumber', :value => '1003').collect {|group| group.cn}
|
|
@@ -412,25 +408,25 @@
|
|
|
412
408
|
#
|
|
413
409
|
# ==== What is it?
|
|
414
410
|
#
|
|
415
|
-
# ActiveLdap::Base is the heart of
|
|
411
|
+
# ActiveLdap::Base is the heart of ActiveLdap. It does all the schema
|
|
416
412
|
# parsing for validation and attribute-to-method mangling as well as manage the
|
|
417
413
|
# connection to LDAP.
|
|
418
414
|
#
|
|
419
|
-
# =====
|
|
415
|
+
# ===== setup_connection
|
|
420
416
|
#
|
|
421
|
-
# Base.
|
|
417
|
+
# Base.setup_connection takes many (optional) arguments and is used to
|
|
422
418
|
# connect to the LDAP server. Sometimes you will want to connect anonymously
|
|
423
|
-
# and other times over TLS with user credentials. Base.
|
|
419
|
+
# and other times over TLS with user credentials. Base.setup_connection is
|
|
424
420
|
# here to do all of that for you.
|
|
425
421
|
#
|
|
426
422
|
#
|
|
427
423
|
# By default, if you call any subclass of Base, such as Group, it will call
|
|
428
|
-
# Base.
|
|
424
|
+
# Base.setup_connection() if these is no active LDAP connection. If your
|
|
429
425
|
# server allows anonymous binding, and you only want to access data in a
|
|
430
|
-
# read-only fashion, you won't need to call Base.
|
|
426
|
+
# read-only fashion, you won't need to call Base.setup_connection. Here
|
|
431
427
|
# is a fully parameterized call:
|
|
432
428
|
#
|
|
433
|
-
# Base.
|
|
429
|
+
# Base.setup_connection(
|
|
434
430
|
# :host => 'ldap.dataspill.org',
|
|
435
431
|
# :port => 389,
|
|
436
432
|
# :base => 'dc=dataspill,dc=org',
|
|
@@ -446,7 +442,7 @@
|
|
|
446
442
|
# * :port defaults to @@port from configuration.rb as well
|
|
447
443
|
# * :base defaults to Base.base() from configuration.rb
|
|
448
444
|
# * :bind_dn defaults @@bind_format from configuration.rb
|
|
449
|
-
# * :logger defaults to a
|
|
445
|
+
# * :logger defaults to a Logger object that prints fatal messages to stderr
|
|
450
446
|
# * :password_block defaults to nil
|
|
451
447
|
# * :allow_anonymous defaults to true
|
|
452
448
|
# * :try_sasl defaults to false - see Advanced Topics for more on this one.
|
|
@@ -471,15 +467,16 @@
|
|
|
471
467
|
# * :try_sasl, when true, tells ActiveLdap to attempt a SASL-GSSAPI bind
|
|
472
468
|
# * :sasl_quiet, when true, tells the SASL libraries to not spew messages to STDOUT
|
|
473
469
|
# * :method indicates whether to use :ssl, :tls, or :plain
|
|
474
|
-
# * :
|
|
470
|
+
# * :retry_limit - indicates the number of attempts to reconnect that will be undertaken when a stale connection occurs. -1 means infinite.
|
|
475
471
|
# * :retry_wait - seconds to wait before retrying a connection
|
|
476
472
|
# * :scope - dictates how to find objects. (Default: :one)
|
|
477
473
|
# * :timeout - time in seconds - defaults to disabled. This CAN interrupt search() requests. Be warned.
|
|
478
474
|
# * :retry_on_timeout - whether to reconnect when timeouts occur. Defaults to true
|
|
479
475
|
# See lib/configuration.rb for defaults for each option
|
|
480
476
|
#
|
|
481
|
-
# Base.
|
|
482
|
-
#
|
|
477
|
+
# Base.setup_connection just setups connection
|
|
478
|
+
# configuration. A connection is connected and bound when it
|
|
479
|
+
# is needed. It follows roughly the following approach:
|
|
483
480
|
#
|
|
484
481
|
# * Connect to host:port using :method
|
|
485
482
|
#
|
|
@@ -488,9 +485,10 @@
|
|
|
488
485
|
# anonymously.
|
|
489
486
|
# * If that fails, error out.
|
|
490
487
|
#
|
|
491
|
-
# On connect, the configuration options passed in are stored
|
|
492
|
-
#
|
|
493
|
-
# from
|
|
488
|
+
# On connect, the configuration options passed in are stored
|
|
489
|
+
# in an internal class variable which is used to cache the
|
|
490
|
+
# information without ditching the defaults passed in from
|
|
491
|
+
# configuration.rb
|
|
494
492
|
#
|
|
495
493
|
# ===== connection
|
|
496
494
|
#
|
|
@@ -498,7 +496,7 @@
|
|
|
498
496
|
#
|
|
499
497
|
# === Exceptions
|
|
500
498
|
#
|
|
501
|
-
# There are a few custom exceptions used in
|
|
499
|
+
# There are a few custom exceptions used in ActiveLdap. They are detailed below.
|
|
502
500
|
#
|
|
503
501
|
# ==== DeleteError
|
|
504
502
|
#
|
|
@@ -514,14 +512,14 @@
|
|
|
514
512
|
#
|
|
515
513
|
# ==== AuthenticationError
|
|
516
514
|
#
|
|
517
|
-
# This exception is raised during Base.
|
|
515
|
+
# This exception is raised during Base.setup_connection if no valid authentication methods
|
|
518
516
|
# succeeded.
|
|
519
517
|
#
|
|
520
518
|
# ==== ConnectionError
|
|
521
519
|
#
|
|
522
|
-
# This exception is raised during Base.
|
|
520
|
+
# This exception is raised during Base.setup_connection if no valid
|
|
523
521
|
# connection to the LDAP server could be created. Check you configuration.rb,
|
|
524
|
-
# Base.
|
|
522
|
+
# Base.setup_connection arguments, and network connectivity! Also check
|
|
525
523
|
# your LDAP server logs to see if it ever saw the request.
|
|
526
524
|
#
|
|
527
525
|
# ==== ObjectClassError
|
|
@@ -538,7 +536,7 @@
|
|
|
538
536
|
#
|
|
539
537
|
# === Putting it all together
|
|
540
538
|
#
|
|
541
|
-
# Now that all of the components of
|
|
539
|
+
# Now that all of the components of ActiveLdap have been covered, it's time
|
|
542
540
|
# to put it all together! The rest of this section will show the steps to setup
|
|
543
541
|
# example user and group management scripts for use with the LDAP tree described
|
|
544
542
|
# above.
|
|
@@ -551,7 +549,7 @@
|
|
|
551
549
|
# cat <<EOF
|
|
552
550
|
# class User < ActiveLdap::Base
|
|
553
551
|
# ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['top', 'account', 'posixAccount']
|
|
554
|
-
# belongs_to :groups, :
|
|
552
|
+
# belongs_to :groups, :class_name => 'Group', :wrap => 'memberUid'
|
|
555
553
|
# end
|
|
556
554
|
# EOF
|
|
557
555
|
#
|
|
@@ -559,8 +557,8 @@
|
|
|
559
557
|
# cat <<EOF
|
|
560
558
|
# class Group < ActiveLdap::Base
|
|
561
559
|
# ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Group'
|
|
562
|
-
# has_many :members, :
|
|
563
|
-
# has_many :primary_members, :
|
|
560
|
+
# has_many :members, :class_name => "User", :many => "memberUid"
|
|
561
|
+
# has_many :primary_members, :class_name => 'User', :foreign_key => 'gidNumber', :primary_key => 'gidNumber'
|
|
564
562
|
# end # Group
|
|
565
563
|
# EOF
|
|
566
564
|
#
|
|
@@ -570,36 +568,37 @@
|
|
|
570
568
|
#
|
|
571
569
|
# Now let's create a really dumb script for adding users - ldapadmin/useradd:
|
|
572
570
|
#
|
|
573
|
-
#
|
|
574
|
-
#
|
|
571
|
+
# base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
|
572
|
+
# $LOAD_PATH << File.join(base, "lib")
|
|
573
|
+
# $LOAD_PATH << File.join(base, "examples")
|
|
574
|
+
#
|
|
575
575
|
# require 'active_ldap'
|
|
576
|
-
# require '
|
|
577
|
-
# require '
|
|
578
|
-
#
|
|
579
|
-
#
|
|
576
|
+
# require 'objects/user'
|
|
577
|
+
# require 'objects/group'
|
|
578
|
+
#
|
|
580
579
|
# argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
|
|
581
580
|
# opts.banner += " USER_NAME CN UID"
|
|
582
581
|
# end
|
|
583
|
-
#
|
|
582
|
+
#
|
|
584
583
|
# if argv.size == 3
|
|
585
584
|
# name, cn, uid = argv
|
|
586
585
|
# else
|
|
587
586
|
# $stderr.puts opts
|
|
588
587
|
# exit 1
|
|
589
588
|
# end
|
|
590
|
-
#
|
|
589
|
+
#
|
|
591
590
|
# pwb = Proc.new do |user|
|
|
592
591
|
# ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
593
592
|
# end
|
|
594
|
-
#
|
|
595
|
-
# ActiveLdap::Base.
|
|
596
|
-
#
|
|
597
|
-
#
|
|
593
|
+
#
|
|
594
|
+
# ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
595
|
+
# :allow_anonymous => false)
|
|
596
|
+
#
|
|
598
597
|
# if User.exists?(name)
|
|
599
598
|
# $stderr.puts("User #{name} already exists.")
|
|
600
599
|
# exit 1
|
|
601
600
|
# end
|
|
602
|
-
#
|
|
601
|
+
#
|
|
603
602
|
# user = User.new(name)
|
|
604
603
|
# user.add_class('shadowAccount')
|
|
605
604
|
# user.cn = cn
|
|
@@ -618,34 +617,38 @@
|
|
|
618
617
|
# Now let's create another dumb script for modifying users - ldapadmin/usermod:
|
|
619
618
|
#
|
|
620
619
|
# #!/usr/bin/ruby -W0
|
|
621
|
-
#
|
|
620
|
+
#
|
|
621
|
+
# base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
|
622
|
+
# $LOAD_PATH << File.join(base, "lib")
|
|
623
|
+
# $LOAD_PATH << File.join(base, "examples")
|
|
624
|
+
#
|
|
622
625
|
# require 'active_ldap'
|
|
623
|
-
# require '
|
|
624
|
-
# require '
|
|
625
|
-
#
|
|
626
|
+
# require 'objects/user'
|
|
627
|
+
# require 'objects/group'
|
|
628
|
+
#
|
|
626
629
|
# argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
|
|
627
630
|
# opts.banner += " USER_NAME CN UID"
|
|
628
631
|
# end
|
|
629
|
-
#
|
|
632
|
+
#
|
|
630
633
|
# if argv.size == 3
|
|
631
634
|
# name, cn, uid = argv
|
|
632
635
|
# else
|
|
633
636
|
# $stderr.puts opts
|
|
634
637
|
# exit 1
|
|
635
638
|
# end
|
|
636
|
-
#
|
|
639
|
+
#
|
|
637
640
|
# pwb = Proc.new do |user|
|
|
638
641
|
# ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
639
642
|
# end
|
|
640
|
-
#
|
|
641
|
-
# ActiveLdap::Base.
|
|
642
|
-
#
|
|
643
|
-
#
|
|
643
|
+
#
|
|
644
|
+
# ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
645
|
+
# :allow_anonymous => false)
|
|
646
|
+
#
|
|
644
647
|
# unless User.exists?(name)
|
|
645
648
|
# $stderr.puts("User #{name} doesn't exist.")
|
|
646
649
|
# exit 1
|
|
647
650
|
# end
|
|
648
|
-
#
|
|
651
|
+
#
|
|
649
652
|
# user = User.find(name)
|
|
650
653
|
# user.cn = cn
|
|
651
654
|
# user.uid_number = uid
|
|
@@ -656,45 +659,9 @@
|
|
|
656
659
|
# exit 1
|
|
657
660
|
# end
|
|
658
661
|
#
|
|
659
|
-
# ==== Removing LDAP entries
|
|
660
|
-
#
|
|
661
|
-
# And finally, a dumb script for removing user - ldapadmin/userdel:
|
|
662
|
-
#
|
|
663
|
-
#
|
|
664
|
-
# #!/usr/bin/ruby -W0
|
|
665
|
-
#
|
|
666
|
-
# require 'active_ldap'
|
|
667
|
-
# require 'lib/user'
|
|
668
|
-
# require 'lib/group'
|
|
669
|
-
#
|
|
670
|
-
# argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
|
|
671
|
-
# opts.banner += " USER_NAME"
|
|
672
|
-
# end
|
|
673
|
-
#
|
|
674
|
-
# if argv.size == 1
|
|
675
|
-
# name = argv.shift
|
|
676
|
-
# else
|
|
677
|
-
# $stderr.puts opts
|
|
678
|
-
# exit 1
|
|
679
|
-
# end
|
|
680
|
-
#
|
|
681
|
-
# pwb = Proc.new do |user|
|
|
682
|
-
# ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
683
|
-
# end
|
|
684
|
-
#
|
|
685
|
-
# ActiveLdap::Base.establish_connection(:password_block => pwb,
|
|
686
|
-
# :allow_anonymous => false)
|
|
687
|
-
#
|
|
688
|
-
# unless User.exists?(name)
|
|
689
|
-
# $stderr.puts("User #{name} doesn't exist.")
|
|
690
|
-
# exit 1
|
|
691
|
-
# end
|
|
692
|
-
#
|
|
693
|
-
# User.destroy(name)
|
|
694
|
-
#
|
|
695
662
|
# === Advanced Topics
|
|
696
663
|
#
|
|
697
|
-
# Below are some situation tips and tricks to get the most out of
|
|
664
|
+
# Below are some situation tips and tricks to get the most out of ActiveLdap.
|
|
698
665
|
#
|
|
699
666
|
#
|
|
700
667
|
# ==== Binary data and other subtypes
|
|
@@ -706,7 +673,7 @@
|
|
|
706
673
|
# irb> user = User.new('drewry')
|
|
707
674
|
# => ...
|
|
708
675
|
# # This adds a cn entry in lang-en and whatever the server default is.
|
|
709
|
-
# irb> user.cn = [ 'wad', {'lang-en' => ['wad', '
|
|
676
|
+
# irb> user.cn = [ 'wad', {'lang-en' => ['wad', 'Will Drewry']} ]
|
|
710
677
|
# => ...
|
|
711
678
|
# irb> user.cn
|
|
712
679
|
# => ["wad", {"lang-en-us" => ["wad", "Will Drewry"]}]
|
|
@@ -729,7 +696,7 @@
|
|
|
729
696
|
#
|
|
730
697
|
# You should note that some binary data does not use the binary subtype all the time.
|
|
731
698
|
# One example is jpegPhoto. You can use it as jpegPhoto;binary or just as jpegPhoto.
|
|
732
|
-
# Since the schema dictates that it is a binary value,
|
|
699
|
+
# Since the schema dictates that it is a binary value, ActiveLdap will write
|
|
733
700
|
# it as binary, but the subtype will not be automatically appended as above. The
|
|
734
701
|
# use of the subtype on attributes like jpegPhoto is ultimately decided by the
|
|
735
702
|
# LDAP site policy and not by any programmatic means.
|
|
@@ -737,7 +704,7 @@
|
|
|
737
704
|
# The only subtypes defined in LDAPv3 are lang-* and binary. These can be nested
|
|
738
705
|
# though:
|
|
739
706
|
#
|
|
740
|
-
# irb> user.cn = [{'lang-
|
|
707
|
+
# irb> user.cn = [{'lang-ja' => {'binary' => 'some Japanese'}}]
|
|
741
708
|
#
|
|
742
709
|
# As I understand it, OpenLDAP does not support nested subtypes, but some
|
|
743
710
|
# documentation I've read suggests that Netscape's LDAP server does. I only
|
|
@@ -766,7 +733,7 @@
|
|
|
766
733
|
# module MyLDAP
|
|
767
734
|
# class User < ActiveLdap::Base
|
|
768
735
|
# ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['top', 'account', 'posixAccount']
|
|
769
|
-
# belongs_to :groups, :
|
|
736
|
+
# belongs_to :groups, :class_name => 'MyLDAP::Group', :many => 'memberUid'
|
|
770
737
|
# end
|
|
771
738
|
# end
|
|
772
739
|
#
|
|
@@ -774,8 +741,8 @@
|
|
|
774
741
|
# module MyLDAP
|
|
775
742
|
# class Group < ActiveLdap::Base
|
|
776
743
|
# ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Group'
|
|
777
|
-
# has_many :members, :
|
|
778
|
-
# has_many :primary_members, :
|
|
744
|
+
# has_many :members, :class_name => 'MyLDAP::User', :wrap => 'memberUid'
|
|
745
|
+
# has_many :primary_members, :class_name => 'MyLDAP::User', :foreign_key => 'gidNumber', :primary_key => 'gidNumber'
|
|
779
746
|
# end
|
|
780
747
|
# end
|
|
781
748
|
#
|
|
@@ -791,7 +758,7 @@
|
|
|
791
758
|
#
|
|
792
759
|
# ==== force array results for single values
|
|
793
760
|
#
|
|
794
|
-
# Even though
|
|
761
|
+
# Even though ActiveLdap attempts to maintain programmatic ease by
|
|
795
762
|
# returning Array values only. By specifying 'true' as an argument to
|
|
796
763
|
# any attribute method you will get back a Array if it is single value.
|
|
797
764
|
# Here's an example:
|
|
@@ -820,11 +787,11 @@
|
|
|
820
787
|
#
|
|
821
788
|
# irb> anon_class = Class.new(Base)
|
|
822
789
|
# => ...
|
|
823
|
-
# irb> anon_class.
|
|
790
|
+
# irb> anon_class.setup_connection
|
|
824
791
|
# => ...
|
|
825
792
|
# irb> auth_class = Class.new(Base)
|
|
826
793
|
# => ...
|
|
827
|
-
# irb> auth_class.
|
|
794
|
+
# irb> auth_class.setup_connection(:password_block => {'mypass'})
|
|
828
795
|
# => ...
|
|
829
796
|
#
|
|
830
797
|
# This can be useful for doing authentication tests and other such tricks.
|
|
@@ -893,7 +860,7 @@
|
|
|
893
860
|
#
|
|
894
861
|
# === Speed
|
|
895
862
|
#
|
|
896
|
-
# Currently,
|
|
863
|
+
# Currently, ActiveLdap could be faster. I have some recursive type
|
|
897
864
|
# checking going on which slows object creation down, and I'm sure there
|
|
898
865
|
# are many, many other places optimizations can be done. Feel free
|
|
899
866
|
# to send patches, or just hang in there until I can optimize away the
|
|
@@ -906,6 +873,7 @@
|
|
|
906
873
|
#
|
|
907
874
|
|
|
908
875
|
require_gem_if_need = Proc.new do |library_name, gem_name, *gem_args|
|
|
876
|
+
gem_name ||= library_name
|
|
909
877
|
begin
|
|
910
878
|
if !gem_args.empty? and Object.const_defined?(:Gem)
|
|
911
879
|
gem gem_name, *gem_args
|
|
@@ -931,7 +899,7 @@ if dependencies.respond_to?(:load_paths)
|
|
|
931
899
|
end
|
|
932
900
|
|
|
933
901
|
module ActiveLdap
|
|
934
|
-
VERSION = "1.0.
|
|
902
|
+
VERSION = "1.0.9"
|
|
935
903
|
end
|
|
936
904
|
|
|
937
905
|
if RUBY_PLATFORM.match('linux')
|
|
@@ -942,12 +910,25 @@ end
|
|
|
942
910
|
|
|
943
911
|
require_gem_if_need.call("active_record", "activerecord")
|
|
944
912
|
begin
|
|
913
|
+
raise LoadError, "GetText is disabled."
|
|
945
914
|
require_gem_if_need.call("locale")
|
|
946
|
-
require_gem_if_need.call("gettext"
|
|
915
|
+
require_gem_if_need.call("gettext")
|
|
916
|
+
|
|
917
|
+
require 'active_record/version'
|
|
918
|
+
active_record_version = [ActiveRecord::VERSION::MAJOR,
|
|
919
|
+
ActiveRecord::VERSION::MINOR,
|
|
920
|
+
ActiveRecord::VERSION::TINY]
|
|
921
|
+
if (active_record_version <=> [2, 2, 0]) < 0
|
|
922
|
+
require "gettext/active_record"
|
|
923
|
+
else
|
|
924
|
+
require_gem_if_need.call("gettext_activerecord")
|
|
925
|
+
end
|
|
947
926
|
rescue LoadError
|
|
948
927
|
end
|
|
949
928
|
require 'active_ldap/get_text'
|
|
950
929
|
|
|
930
|
+
require 'active_ldap/compatible'
|
|
931
|
+
|
|
951
932
|
require 'active_ldap/base'
|
|
952
933
|
|
|
953
934
|
require 'active_ldap/distinguished_name'
|
data/po/en/active-ldap.po
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# English translations for
|
|
2
|
-
# Copyright (C) 2007 Kouhei Sutou
|
|
3
|
-
# This file is distributed under the same license as the
|
|
1
|
+
# English translations for ActiveLdap package.
|
|
2
|
+
# Copyright (C) 2007-2009 Kouhei Sutou
|
|
3
|
+
# This file is distributed under the same license as the ActiveLdap package.
|
|
4
4
|
# Kouhei Sutou <kou@cozmixng.org>, 2007.
|
|
5
5
|
#
|
|
6
6
|
msgid ""
|
|
7
7
|
msgstr ""
|
|
8
|
-
"Project-Id-Version:
|
|
8
|
+
"Project-Id-Version: ActiveLdap 1.1.0\n"
|
|
9
9
|
"POT-Creation-Date: 2008-06-17 21:42+0900\n"
|
|
10
|
-
"PO-Revision-Date:
|
|
10
|
+
"PO-Revision-Date: 2009-02-25 08:40+0900\n"
|
|
11
11
|
"Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
|
|
12
12
|
"Language-Team: English\n"
|
|
13
13
|
"MIME-Version: 1.0\n"
|
data/po/ja/active-ldap.po
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Japanese translations for
|
|
2
|
-
# Copyright (C) 2007 Kouhei Sutou
|
|
3
|
-
# This file is distributed under the same license as the
|
|
1
|
+
# Japanese translations for ActiveLdap.
|
|
2
|
+
# Copyright (C) 2007-2009 Kouhei Sutou
|
|
3
|
+
# This file is distributed under the same license as the ActiveLdap package.
|
|
4
4
|
# Kouhei Sutou <kou@cozmixng.org>, 2007.
|
|
5
5
|
#
|
|
6
6
|
msgid ""
|
|
7
7
|
msgstr ""
|
|
8
|
-
"Project-Id-Version:
|
|
8
|
+
"Project-Id-Version: ActiveLdap 1.1.0\n"
|
|
9
9
|
"POT-Creation-Date: 2008-06-17 21:42+0900\n"
|
|
10
|
-
"PO-Revision-Date:
|
|
10
|
+
"PO-Revision-Date: 2009-02-25 08:40+0900\n"
|
|
11
11
|
"Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
|
|
12
12
|
"Language-Team: Japanese\n"
|
|
13
13
|
"MIME-Version: 1.0\n"
|