activeldap 1.0.9 → 1.1.0

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.
Files changed (37) hide show
  1. data/CHANGES +648 -567
  2. data/README +53 -48
  3. data/Rakefile +25 -53
  4. data/TODO +2 -0
  5. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  6. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  7. data/examples/al-admin/app/controllers/application_controller.rb +1 -1
  8. data/examples/al-admin/app/views/_entry/_attributes_information.html.erb +7 -1
  9. data/examples/al-admin/app/views/users/_attributes_update_form.html.erb +13 -1
  10. data/examples/al-admin/config/environment.rb +2 -3
  11. data/lib/active_ldap.rb +103 -98
  12. data/lib/active_ldap/association/belongs_to_many.rb +7 -7
  13. data/lib/active_ldap/association/has_many.rb +4 -4
  14. data/lib/active_ldap/associations.rb +29 -5
  15. data/lib/active_ldap/attributes.rb +5 -1
  16. data/lib/active_ldap/base.rb +17 -13
  17. data/lib/active_ldap/configuration.rb +3 -4
  18. data/lib/active_ldap/connection.rb +3 -3
  19. data/lib/active_ldap/get_text/parser.rb +4 -2
  20. data/lib/active_ldap/helper.rb +59 -0
  21. data/lib/active_ldap/operations.rb +15 -10
  22. data/lib/active_ldap/xml.rb +22 -30
  23. data/po/en/active-ldap.po +221 -154
  24. data/po/ja/active-ldap.po +237 -178
  25. data/test-unit/History.txt +26 -0
  26. data/test-unit/Manifest.txt +1 -1
  27. data/test-unit/README.txt +1 -0
  28. data/test-unit/Rakefile +6 -1
  29. data/test-unit/lib/test/unit/autorunner.rb +6 -0
  30. data/test-unit/lib/test/unit/testcase.rb +101 -36
  31. data/test-unit/test/{test_testcase.rb → test-testcase.rb} +30 -1
  32. data/test-unit/test/test_assertions.rb +1 -1
  33. data/test/al-test-utils.rb +3 -1
  34. data/test/test_associations.rb +75 -6
  35. data/test/test_base.rb +45 -3
  36. metadata +75 -45
  37. data/examples/al-admin/config/initializers/gettext.rb +0 -15
data/README CHANGED
@@ -1,12 +1,18 @@
1
- Ruby/ActiveLdap -- ruby library for object-oriented LDAP interction
2
- Copyright (C) 2004-2006 Will Drewry <will@alum.bu.edu>, Kouhei Sutou <kou@cozmixng.org>
3
- Contributors:
4
- * Dick Davies <rasputnik@hellooperator.net>
5
- * Nathan Kinder <quicksilver02@mac.com>
6
- * Patrick Cole <pac@independent.com.au>
7
- * Google Inc.
8
-
9
- DESCRIPTION
1
+ = Ruby/ActiveLdap
2
+
3
+ ruby library for object-oriented LDAP interction
4
+
5
+ * Copyright (C) 2004-2006 Will Drewry <tt><will@alum.bu.edu></tt>
6
+ * Copyright (C) 2006-2009 Kouhei Sutou <tt><kou@clear-code.com></tt>
7
+
8
+ Contributors::
9
+ * Dick Davies <tt><rasputnik AT hellooperator.net></tt>
10
+ * Nathan Kinder <tt><quicksilver02 AT mac.com></tt>
11
+ * Patrick Cole <tt><pac AT independent.com.au></tt>
12
+ * Google Inc.
13
+
14
+ == DESCRIPTION
15
+
10
16
  'Ruby/ActiveLdap' is a ruby extension library which provides a clean objected
11
17
  oriented interface to the Ruby/LDAP[0] library. It was inspired by
12
18
  ActivRecord[3]. This is not nearly as clean or as flexible as ActiveRecord, but
@@ -18,49 +24,56 @@ It is also available on the web at:
18
24
 
19
25
  http://ruby-activeldap.rubyforge.org/
20
26
 
21
- PREREQUISITES
27
+ == PREREQUISITES
22
28
 
23
- * Ruby 1.8.x [2]
24
- * Ruby/LDAP [0] or Net::LDAP [1]
25
- * ActiveRecord [3]
26
- * An LDAP server compatible with Ruby/LDAP: OpenLDAP, etc
29
+ [Ruby intepreter]
30
+ One of them:
31
+ * Ruby[http://www.ruby-lang.org] (1.8.x or 1.9.1)
32
+ * JRuby[http://jruby.codehaus.org/]
27
33
 
34
+ [LDAP client]
35
+ JRuby doesn't need to install new library because JRuby
36
+ has builtin LDAP support. Ruby users need one of them:
37
+ * Ruby/LDAP[http://rubyforge.org/projects/ruby-ldap/]
38
+ * Net::LDAP[http://rubyforge.org/projects/net-ldap/]
28
39
 
29
- NOTES
40
+ * ActiveRecord[http://activerecord.rubyonrails.org]
30
41
 
31
- * Only GSSAPI SASL support exists due to Ruby/LDAP limitations
42
+ == NOTES
32
43
 
44
+ * Only GSSAPI SASL support exists due to Ruby/LDAP limitations
33
45
 
34
- INSTALL
46
+ == INSTALL
35
47
 
36
- - Edit active_ldap/configuration.rb with your LDAP preferences
37
- - Run -
38
- sudo rake install
48
+ % sudo gem install activeldap
39
49
 
40
- RAILS
50
+ == RAILS
41
51
 
42
- There is a small rails plugin included that allows the use of a file named
43
- 'ldap.yml' in the config directory of your rails app. This file has a similar
44
- function to the 'database.yml' file that allows you to set your database
45
- connection settings per environment. Similarly, the ldap.yml file allows
46
- settings to be set for development, test, and production environments. For
47
- instance, the development entry would look something like the following:
52
+ There is a small rails plugin included that allows the use
53
+ of a file named 'config/ldap.yml' in the config directory of
54
+ your rails app. This file has a similar function to the
55
+ 'database.yml' file that allows you to set your database
56
+ connection settings per environment. Similarly, the ldap.yml
57
+ file allows settings to be set for development, test, and
58
+ production environments. For instance, the development entry
59
+ would look something like the following:
48
60
 
49
- development:
50
- host: 127.0.0.1
51
- port: 389
52
- base: dc=localhost
53
- bind_dn: cn=admin,dc=localhost
54
- password: secret
61
+ development:
62
+ host: 127.0.0.1
63
+ port: 389
64
+ base: dc=localhost
65
+ bind_dn: cn=admin,dc=localhost
66
+ password: secret
55
67
 
68
+ To install, simply add the following codes to you config/environment.rb:
56
69
 
57
- To install, simply copy the rails/plugin/active_ldap folder into the
58
- vendor/plugins directory of your rails application and create config/ldap.yml.
59
- When your application starts up, the plugin will call #establish_connection
60
- using the parameters specified for your current environment.
70
+ config.gem "activeldap", :lib => "active_ldap"
61
71
 
72
+ When your application starts up, the plugin will call
73
+ ActiveLdap::Base.setup_connection using the parameters
74
+ specified for your current environment.
62
75
 
63
- LICENCE
76
+ == LICENCE
64
77
 
65
78
  This program is free software; you can redistribute it and/or modify it. It is
66
79
  dual licensed under Ruby's license and under the terms of the GNU General
@@ -69,16 +82,7 @@ or (at your option) any later version.
69
82
 
70
83
  Please see the file LICENSE for the terms of the licence.
71
84
 
72
-
73
- REFERENCES
74
-
75
- [0] - http://ruby-ldap.sourceforge.net
76
- [1] - http://rubyforge.org/projects/net-ldap/
77
- [2] - http://www.ruby-lang.org
78
- [3] - http://activerecord.rubyonrails.org
79
-
80
-
81
- THANKS
85
+ == THANKS
82
86
 
83
87
  This list may not be correct. If you notice mistakes of this
84
88
  list, please point out.
@@ -129,3 +133,4 @@ list, please point out.
129
133
  * Tim Hermans: A bug report.
130
134
  * Joe Francis: A suggestion.
131
135
  * Tiago Fernandes: Bug reports.
136
+ * achemze. A suggestion.
data/Rakefile CHANGED
@@ -53,24 +53,26 @@ at_exit do
53
53
  FileUtils.rm_f("History.txt")
54
54
  end
55
55
 
56
- project = Hoe.new('activeldap', ActiveLdap::VERSION) do |project|
57
- project.rubyforge_name = 'ruby-activeldap'
58
- project.author = ['Will Drewry', 'Kouhei Sutou']
59
- project.email = ['redpig@dataspill.org', 'kou@cozmixng.org']
60
- project.summary = 'Ruby/ActiveLdap is a object-oriented API to LDAP'
61
- project.url = 'http://rubyforge.org/projects/ruby-activeldap/'
62
- project.test_globs = ['test/test_*.rb']
63
- project.changes = project.paragraphs_of('CHANGES', 0..1).join("\n\n")
64
- project.extra_deps = ['activerecord']
65
- project.rdoc_pattern = /(?:^(?:lib|bin)|\AREADME\z)/
66
- project.remote_rdoc_dir = "doc"
67
- project.rsync_args += " --chmod=Dg+ws,Fg+w"
68
- project.spec_extras = {
69
- :requirements => ['ruby-ldap >= 0.8.2', '(Open)LDAP server'],
70
- :autorequire => 'active_ldap',
71
- :executables => [],
72
- }
73
- project.description = String.new(<<-EOF)
56
+ ENV["VERSION"] = ActiveLdap::VERSION
57
+ project = Hoe.spec('activeldap') do
58
+ self.version = ActiveLdap::VERSION
59
+ self.rubyforge_name = 'ruby-activeldap'
60
+ self.author = ['Will Drewry', 'Kouhei Sutou']
61
+ self.email = ['redpig@dataspill.org', 'kou@cozmixng.org']
62
+ self.summary = 'Ruby/ActiveLdap is a object-oriented API to LDAP'
63
+ self.url = 'http://rubyforge.org/projects/ruby-activeldap/'
64
+ self.test_globs = ['test/test_*.rb']
65
+ self.changes = self.paragraphs_of('CHANGES', 1..2).join("\n\n")
66
+ self.extra_deps = [
67
+ # ['ruby-ldap', '= 0.9.9'],
68
+ ['activerecord', '= 2.3.2'],
69
+ ['locale', '= 2.0.4'],
70
+ ['gettext', '= 2.0.4'],
71
+ ['gettext_activerecord', '= 2.0.4'],
72
+ ]
73
+ self.remote_rdoc_dir = "doc"
74
+ self.rsync_args += " --chmod=Dg+ws,Fg+w"
75
+ self.description = String.new(<<-EOF)
74
76
  'Ruby/ActiveLdap' is a ruby extension library which provides a clean
75
77
  objected oriented interface to the Ruby/LDAP library. It was inspired
76
78
  by ActiveRecord. This is not nearly as clean or as flexible as
@@ -79,6 +81,8 @@ project = Hoe.new('activeldap', ActiveLdap::VERSION) do |project|
79
81
  EOF
80
82
  end
81
83
 
84
+ project.spec.extra_rdoc_files = ["README", "CHANGES", "COPYING", "LICENSE"]
85
+
82
86
  publish_docs_actions = task(:publish_docs).instance_variable_get("@actions")
83
87
  original_project_name = nil
84
88
  before_publish_docs = Proc.new do
@@ -91,9 +95,6 @@ end
91
95
  publish_docs_actions.unshift(before_publish_docs)
92
96
  publish_docs_actions.push(after_publish_docs)
93
97
 
94
- # fix Hoe's incorrect guess.
95
- project.spec.executables.clear
96
- project.bin_files = project.spec.files.grep(/^bin/)
97
98
 
98
99
  rdoc_main = "lib/active_ldap.rb"
99
100
  project.spec.rdoc_options.each do |option|
@@ -101,36 +102,7 @@ project.spec.rdoc_options.each do |option|
101
102
  end
102
103
  ObjectSpace.each_object(Rake::RDocTask) do |task|
103
104
  task.main = rdoc_main if task.main == "README.txt"
104
- end
105
-
106
-
107
- # fix Hoe's install and uninstall task.
108
- task(:install).instance_variable_get("@actions").clear
109
- task(:uninstall).instance_variable_get("@actions").clear
110
-
111
- task :install do
112
- [
113
- [project.lib_files, "lib", Hoe::RUBYLIB, 0444],
114
- [project.bin_files, "bin", File.join(Hoe::PREFIX, 'bin'), 0555]
115
- ].each do |files, prefix, dest, mode|
116
- FileUtils.mkdir_p dest unless test ?d, dest
117
- files.each do |file|
118
- base = File.dirname(file.sub(/^#{prefix}#{File::SEPARATOR}/, ''))
119
- _dest = File.join(dest, base)
120
- FileUtils.mkdir_p _dest unless test ?d, _dest
121
- install file, _dest, :mode => mode
122
- end
123
- end
124
- end
125
-
126
- desc 'Uninstall the package.'
127
- task :uninstall do
128
- Dir.chdir Hoe::RUBYLIB do
129
- rm_f project.lib_files.collect {|f| f.sub(/^lib#{File::SEPARATOR}/, '')}
130
- end
131
- Dir.chdir File.join(Hoe::PREFIX, 'bin') do
132
- rm_f project.bin_files.collect {|f| f.sub(/^bin#{File::SEPARATOR}/, '')}
133
- end
105
+ task.rdoc_files = project.spec.require_paths + project.spec.extra_rdoc_files
134
106
  end
135
107
 
136
108
  desc 'Tag the repository for release.'
@@ -145,7 +117,7 @@ task :gettext => ["gettext:po:update", "gettext:mo:create"]
145
117
  namespace :gettext do
146
118
  desc "Setup environment for GetText"
147
119
  task :environment do
148
- require "gettext/utils"
120
+ require "gettext/tools"
149
121
  end
150
122
 
151
123
  namespace :po do
@@ -176,7 +148,7 @@ namespace :gettext do
176
148
  namespace :mo do
177
149
  desc "Create *.mo from *.po (GetText)"
178
150
  task :create => "gettext:environment" do
179
- GetText.create_mofiles(false)
151
+ GetText.create_mofiles
180
152
  end
181
153
  end
182
154
  end
data/TODO CHANGED
@@ -1,3 +1,5 @@
1
+ - [1.1.1] add :readonly option to :has_many.
2
+ - Work as framework on Rails.
1
3
  - [1.1.x] ActiveLdap::Base#dn returns ActiveLdap::DN. [#23932] [Marc Dequènes]
2
4
  - How to support dSCorePropagationData? ignore it?
3
5
  all systemOnly == "TRUE" attribute can be ignored?
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
8
8
  # Uncomment the :secret if you're not using the cookie session store
9
9
  protect_from_forgery # :secret => '5965eefc93d824a9c145fe8edb6d1a36'
10
10
 
11
- # init_gettext "al-admin"
11
+ init_gettext "al-admin"
12
12
 
13
13
  include ExceptionNotifiable
14
14
 
@@ -13,7 +13,13 @@
13
13
  <% (entry.attribute_names(true) - ["objectClass"]).sort.each do |name| -%>
14
14
  <tr class="<%= cycle('even', 'odd') %>">
15
15
  <th scope="row"><%= link_to_attribute(name) %></th>
16
- <td><%= h(entry[name, true].join(", ")) %></td>
16
+ <td>
17
+ <%=
18
+ entry[name, true].collect do |value|
19
+ h(value.inspect)
20
+ end.join("<br />")
21
+ %>
22
+ </td>
17
23
  <td><%= h(lad_(name)) %></td>
18
24
  </tr>
19
25
  <% end -%>
@@ -23,7 +23,19 @@
23
23
  <span class="required-attribute-mark">*</span>
24
24
  <% end -%>
25
25
  </th>
26
- <td><%= text_field("user", name) %></td>
26
+ <td>
27
+ <%=
28
+ ldap_field(:text, :user, name,
29
+ :ldap_options => ["lang-en"]) do |field, info|
30
+ ldap_options = info[:options]
31
+ if ldap_options.empty?
32
+ "#{field}<br />"
33
+ else
34
+ "#{ldap_options.join(';')}: #{field}<br />"
35
+ end
36
+ end
37
+ -%>
38
+ </td>
27
39
  <td><%= h lad_(name) %></td>
28
40
  </tr>
29
41
  <% end -%>
@@ -27,9 +27,8 @@ Rails::Initializer.run do |config|
27
27
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
28
28
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
29
29
  # config.gem "aws-s3", :lib => "aws/s3"
30
- # config.gem "locale_rails"
31
- # config.gem "gettext_activerecord"
32
- # config.gem "gettext_rails"
30
+ config.gem "locale_rails", :version => "2.0.4"
31
+ config.gem "gettext_rails", :version => "2.0.4"
33
32
 
34
33
  # Only load the plugins named here, in the order given. By default, all plugins
35
34
  # in vendor/plugins are loaded in alphabetical order.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/ruby
2
2
  # = ActiveLdap
3
3
  #
4
- # "ActiveLdap" Copyright (C) 2004,2005 Will Drewry mailto:will@alum.bu.edu
5
- # Copyright (C) 2006-2009 Kouhei Sutou <kou@cozmixng.org>
4
+ # Copyright (C) 2004,2005 Will Drewry mailto:will@alum.bu.edu
5
+ # Copyright (C) 2006-2009 Kouhei Sutou <kou@clear-code.com>
6
6
  #
7
7
  # == Introduction
8
8
  #
@@ -58,26 +58,13 @@
58
58
  #
59
59
  # === Installation
60
60
  #
61
- # Assuming all the requirements are installed, you can install by grabbing the latest tgz file from
62
- # the download site[http://rubyforge.org/frs/?group_id=381].
61
+ # Assuming all the requirements are installed, you can install by gem.
63
62
  #
64
- # The following steps will get the ActiveLdap installed in no time!
65
- #
66
- # $ tar -xzvf ruby-activeldap-current.tgz
67
- # $ cd ruby-activeldap-VERSION
68
- #
69
- # Edit lib/active_ldap/configuration.rb replacing values to match what will work
70
- # with your LDAP servers. Please note that those variables are required, but can
71
- # be overridden in any program as detailed later in this document. Also make
72
- # sure that "ROOT" stays all upcase.
73
- #
74
- # Now run:
75
- #
76
- # $ (as root) rake install
63
+ # # gem install activeldap
77
64
  #
78
65
  # Now as a quick test, you can run:
79
66
  #
80
- # $ irb
67
+ # $ irb -rubygems
81
68
  # irb> require 'active_ldap'
82
69
  # => true
83
70
  # irb> exit
@@ -86,33 +73,6 @@
86
73
  # problem with the installation. You may need to customize what setup.rb does on
87
74
  # install.
88
75
  #
89
- #
90
- # === Customizations
91
- #
92
- # Now that ActiveLdap is installed and working, we still have a few more
93
- # steps to make it useful for programming.
94
- #
95
- # Let's say that you are writing a Ruby program for managing user and group
96
- # accounts in LDAP. I will use this as the running example throughout the
97
- # document.
98
- #
99
- # You will want to make a directory called 'ldapadmin' wherever is convenient. Under this directory,
100
- # you'll want to make sure you have a 'lib' directory.
101
- #
102
- # $ cd ~
103
- # $ mkdir ldapadmin
104
- # $ cd ldapadmin
105
- # $ mkdir lib
106
- # $ cd lib
107
- #
108
- # The lib directory is where we'll be making customizations. You can, of course,
109
- # make this changes somewhere in Ruby's default search path to make this
110
- # accessible to every Ruby scripts. Enough of my babbling, I'm sure you'd like to
111
- # know what we're going to put in lib/.
112
- #
113
- # We're going to put extension classes in there. What are extension classes you say . . .
114
- #
115
- #
116
76
  # == Usage
117
77
  #
118
78
  # This section covers using ActiveLdap from writing extension classes to
@@ -122,6 +82,11 @@
122
82
  #
123
83
  # irb> require 'active_ldap'
124
84
  #
85
+ # Call setup_connection method for connect to LDAP server. In this case, LDAP server
86
+ # is localhost, and base of LDAP tree is "dc=dataspill,dc=org".
87
+ #
88
+ # irb> ActiveLdap::Base.setup_connection :host => 'localhost', :base => 'dc=dataspill,dc=org'
89
+ #
125
90
  # Here's an extension class that maps to the LDAP Group objects:
126
91
  #
127
92
  # irb> class Group < ActiveLdap::Base
@@ -171,7 +136,7 @@
171
136
  #
172
137
  # class Group < ActiveLdap::Base
173
138
  # ldap_mapping :dn_attribute => 'cn',
174
- # :prefix => 'ou=Groups', :classes => ['top', 'posixGroup']
139
+ # :prefix => 'ou=Groups', :classes => ['top', 'posixGroup'],
175
140
  # :scope => :one
176
141
  # end
177
142
  #
@@ -181,7 +146,7 @@
181
146
  # * dc=dataspill,dc=org
182
147
  # |- ou=People,dc=dataspill,dc=org
183
148
  # |+ ou=Groups,dc=dataspill,dc=org
184
- # \
149
+ # \
185
150
  # |- cn=develop,ou=Groups,dc=dataspill,dc=org
186
151
  # |- cn=root,ou=Groups,dc=dataspill,dc=org
187
152
  # |- ...
@@ -198,11 +163,12 @@
198
163
  # ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
199
164
  # :dn_attribute | |
200
165
  # :prefix |
201
- # :base from configuration.rb
166
+ # :base from setup_connection
202
167
  #
203
168
  # :scope tells ActiveLdap to only search under ou=Groups, and not to look deeper
204
169
  # for dn_attribute matches.
205
170
  # (e.g. cn=develop,ou=DevGroups,ou=Groups,dc=dataspill,dc=org)
171
+ # You can choose value from between :sub, :one and :base.
206
172
  #
207
173
  # Something's missing: :classes. :classes is used to tell ActiveLdap what
208
174
  # the minimum requirement is when creating a new object. LDAP uses objectClasses
@@ -234,7 +200,7 @@
234
200
  #
235
201
  # * dc=dataspill,dc=org
236
202
  # |+ ou=People,dc=dataspill,dc=org
237
- # \
203
+ # \
238
204
  # |- uid=drewry,ou=People,dc=dataspill,dc=org
239
205
  # |- ou=Groups,dc=dataspill,dc=org
240
206
  #
@@ -251,7 +217,7 @@
251
217
  # group 'develop'. In order to remedy that, we can use belongs_to
252
218
  #
253
219
  # irb> class User < ActiveLdap::Base
254
- # irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'People', :classes => ['top','account']
220
+ # irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['top','account']
255
221
  # irb* belongs_to :groups, :class_name => 'Group', :many => 'memberUid', :foreign_key => 'uid'
256
222
  # irb* end
257
223
  #
@@ -260,7 +226,7 @@
260
226
  #
261
227
  # irb> me = User.find('drewry')
262
228
  # irb> me.groups
263
- # => [#<Group ...>, #<Group ...>, ...]
229
+ # => #<ActiveLdap::Association::BelongsToMany...> # Enumerable object
264
230
  # irb> me.groups.each { |group| p group.cn };nil
265
231
  # "cdrom"
266
232
  # "audio"
@@ -290,7 +256,7 @@
290
256
  # mind, the above definition could become:
291
257
  #
292
258
  # irb> class User < ActiveLdap::Base
293
- # irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'People', :classes => ['top','account']
259
+ # irb* ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['top','account']
294
260
  # irb* belongs_to :groups, :class_name => 'Group', :many => 'memberUid'
295
261
  # irb* end
296
262
  #
@@ -319,8 +285,9 @@
319
285
  # irb> develop = Group.find('develop')
320
286
  # => ...
321
287
  # irb> develop.members
322
- # => [#<User ...>, #<User ...>]
323
- #
288
+ # => #<ActiveLdap::Association::HasManyWrap:..> # Enumerable object
289
+ # irb> develop.members.map{|member| member.id}
290
+ # => ["drewry", "builder"]
324
291
  #
325
292
  # The arguments for has_many follow the exact same idea that belongs_to's
326
293
  # arguments followed. :wrap's contents are used to search for matching
@@ -375,10 +342,10 @@
375
342
  # :scope => :sub, :attributes => ['uid', 'cn'])
376
343
  # => [["uid=root,ou=People,dc=dataspill,dc=org",{"cn"=>["root"], "uidNumber"=>["0"]}]
377
344
  # You can specify the :filter, :base, :scope, and :attributes, but they all have defaults --
378
- # * :filter defaults to objectClass=* - usually this isn't what you want
379
- # * :base defaults to the base of the class this is executed from (as set in ldap_mapping)
380
- # * :scope defaults to :sub. Usually you won't need to change it
381
- # * :attributes defaults to [] and is the list of attributes you want back. Empty means all of them.
345
+ # * :filter defaults to objectClass=* - usually this isn't what you want
346
+ # * :base defaults to the base of the class this is executed from (as set in ldap_mapping)
347
+ # * :scope defaults to :sub. Usually you won't need to change it (You can choose value also from between :one and :base)
348
+ # * :attributes defaults to [] and is the list of attributes you want back. Empty means all of them.
382
349
  #
383
350
  # ==== #valid?
384
351
  #
@@ -438,10 +405,9 @@
438
405
  # )
439
406
  #
440
407
  # There are quite a few arguments, but luckily many of them have safe defaults:
441
- # * :host defaults to @@host from configuration.rb waaay back at the setup.rb stage.@
442
- # * :port defaults to @@port from configuration.rb as well
443
- # * :base defaults to Base.base() from configuration.rb
444
- # * :bind_dn defaults @@bind_format from configuration.rb
408
+ # * :host defaults to "127.0.0.1".
409
+ # * :port defaults to nil. 389 is applied if not specified.
410
+ # * :bind_dn defaults to nil. anonymous binding is applied if not specified.
445
411
  # * :logger defaults to a Logger object that prints fatal messages to stderr
446
412
  # * :password_block defaults to nil
447
413
  # * :allow_anonymous defaults to true
@@ -466,13 +432,12 @@
466
432
  # bind methods fail
467
433
  # * :try_sasl, when true, tells ActiveLdap to attempt a SASL-GSSAPI bind
468
434
  # * :sasl_quiet, when true, tells the SASL libraries to not spew messages to STDOUT
469
- # * :method indicates whether to use :ssl, :tls, or :plain
470
435
  # * :retry_limit - indicates the number of attempts to reconnect that will be undertaken when a stale connection occurs. -1 means infinite.
471
436
  # * :retry_wait - seconds to wait before retrying a connection
472
437
  # * :scope - dictates how to find objects. (Default: :one)
473
438
  # * :timeout - time in seconds - defaults to disabled. This CAN interrupt search() requests. Be warned.
474
439
  # * :retry_on_timeout - whether to reconnect when timeouts occur. Defaults to true
475
- # See lib/configuration.rb for defaults for each option
440
+ # See lib/configuration.rb(ActiveLdap::Configuration::DEFAULT_CONFIG) for defaults for each option
476
441
  #
477
442
  # Base.setup_connection just setups connection
478
443
  # configuration. A connection is connected and bound when it
@@ -518,7 +483,7 @@
518
483
  # ==== ConnectionError
519
484
  #
520
485
  # This exception is raised during Base.setup_connection if no valid
521
- # connection to the LDAP server could be created. Check you configuration.rb,
486
+ # connection to the LDAP server could be created. Check you
522
487
  # Base.setup_connection arguments, and network connectivity! Also check
523
488
  # your LDAP server logs to see if it ever saw the request.
524
489
  #
@@ -543,24 +508,28 @@
543
508
  #
544
509
  # All of the scripts here are in the package's examples/ directory.
545
510
  #
546
- # ==== Setting up lib/
511
+ # ==== Setting up
512
+ #
513
+ # Create directory for scripts.
514
+ #
515
+ # mkdir -p ldapadmin/objects
547
516
  #
548
- # In ldapadmin/lib/ create the file user.rb:
549
- # cat <<EOF
517
+ # In ldapadmin/objects/ create the file user.rb:
518
+ #
519
+ # require 'objects/group'
520
+ #
550
521
  # class User < ActiveLdap::Base
551
- # ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['top', 'account', 'posixAccount']
552
- # belongs_to :groups, :class_name => 'Group', :wrap => 'memberUid'
522
+ # ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People', :classes => ['person', 'posixAccount']
523
+ # belongs_to :groups, :class_name => 'Group', :many => 'memberUid'
553
524
  # end
554
- # EOF
555
525
  #
556
- # In ldapadmin/lib/ create the file group.rb:
557
- # cat <<EOF
526
+ # In ldapadmin/objects/ create the file group.rb:
527
+ #
558
528
  # class Group < ActiveLdap::Base
559
- # ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Group'
560
- # has_many :members, :class_name => "User", :many => "memberUid"
529
+ # ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Groups'
530
+ # has_many :members, :class_name => "User", :wrap => "memberUid"
561
531
  # has_many :primary_members, :class_name => 'User', :foreign_key => 'gidNumber', :primary_key => 'gidNumber'
562
- # end # Group
563
- # EOF
532
+ # end
564
533
  #
565
534
  # Now, we can write some small scripts to do simple management tasks.
566
535
  #
@@ -568,10 +537,13 @@
568
537
  #
569
538
  # Now let's create a really dumb script for adding users - ldapadmin/useradd:
570
539
  #
540
+ # #!/usr/bin/ruby -W0
541
+ #
571
542
  # base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
572
543
  # $LOAD_PATH << File.join(base, "lib")
573
544
  # $LOAD_PATH << File.join(base, "examples")
574
545
  #
546
+ # require 'rubygems'
575
547
  # require 'active_ldap'
576
548
  # require 'objects/user'
577
549
  # require 'objects/group'
@@ -622,6 +594,7 @@
622
594
  # $LOAD_PATH << File.join(base, "lib")
623
595
  # $LOAD_PATH << File.join(base, "examples")
624
596
  #
597
+ # require 'rubygems'
625
598
  # require 'active_ldap'
626
599
  # require 'objects/user'
627
600
  # require 'objects/group'
@@ -659,6 +632,45 @@
659
632
  # exit 1
660
633
  # end
661
634
  #
635
+ # ==== Removing LDAP entries
636
+ # Now let's create more one for deleting users - ldapadmin/userdel:
637
+ #
638
+ # #!/usr/bin/ruby -W0
639
+ #
640
+ # base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
641
+ # $LOAD_PATH << File.join(base, "lib")
642
+ # $LOAD_PATH << File.join(base, "examples")
643
+ #
644
+ # require 'rubygems'
645
+ # require 'active_ldap'
646
+ # require 'objects/user'
647
+ # require 'objects/group'
648
+ #
649
+ # argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
650
+ # opts.banner += " USER_NAME"
651
+ # end
652
+ #
653
+ # if argv.size == 1
654
+ # name = argv.shift
655
+ # else
656
+ # $stderr.puts opts
657
+ # exit 1
658
+ # end
659
+ #
660
+ # pwb = Proc.new do |user|
661
+ # ActiveLdap::Command.read_password("[#{user}] Password: ")
662
+ # end
663
+ #
664
+ # ActiveLdap::Base.setup_connection(:password_block => pwb,
665
+ # :allow_anonymous => false)
666
+ #
667
+ # unless User.exists?(name)
668
+ # $stderr.puts("User #{name} doesn't exist.")
669
+ # exit 1
670
+ # end
671
+ #
672
+ # User.destroy(name)
673
+ #
662
674
  # === Advanced Topics
663
675
  #
664
676
  # Below are some situation tips and tricks to get the most out of ActiveLdap.
@@ -740,7 +752,7 @@
740
752
  # ./myldap/group.rb:
741
753
  # module MyLDAP
742
754
  # class Group < ActiveLdap::Base
743
- # ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Group'
755
+ # ldap_mapping :classes => ['top', 'posixGroup'], :prefix => 'ou=Groups'
744
756
  # has_many :members, :class_name => 'MyLDAP::User', :wrap => 'memberUid'
745
757
  # has_many :primary_members, :class_name => 'MyLDAP::User', :foreign_key => 'gidNumber', :primary_key => 'gidNumber'
746
758
  # end
@@ -791,7 +803,7 @@
791
803
  # => ...
792
804
  # irb> auth_class = Class.new(Base)
793
805
  # => ...
794
- # irb> auth_class.setup_connection(:password_block => {'mypass'})
806
+ # irb> auth_class.setup_connection(:password_block => lambda{'mypass'})
795
807
  # => ...
796
808
  #
797
809
  # This can be useful for doing authentication tests and other such tricks.
@@ -841,7 +853,10 @@
841
853
  # any methods you write might need to figure it out. I'd suggest just
842
854
  # calling self[attribname] to get the value, but if that's not good enough,
843
855
  # you can call look up the stored name by #to_real_attribute_name as follows:
844
- # irb> to_real_attribute_name('commonName')
856
+ #
857
+ # irb> User.find(:first).instance_eval do
858
+ # irb> to_real_attribute_name('commonName')
859
+ # irb> end
845
860
  # => 'cn'
846
861
  #
847
862
  # This tells you the name the attribute is stored in behind the scenes (@data).
@@ -851,8 +866,8 @@
851
866
  # Also, if you like to look up all aliases for an attribute, you can call the
852
867
  # following:
853
868
  #
854
- # irb> schema.attribute_aliases('cn')
855
- # => ['cn','commonName']
869
+ # irb> User.schema.attribute_type 'cn', 'NAME'
870
+ # => ["cn", "commonName"]
856
871
  #
857
872
  # This is discovered automagically from the LDAP server's schema.
858
873
  #
@@ -886,7 +901,7 @@ require_gem_if_need = Proc.new do |library_name, gem_name, *gem_args|
886
901
  end
887
902
  end
888
903
 
889
- require_gem_if_need.call("active_support", "activesupport")
904
+ require_gem_if_need.call("active_support", "activesupport", "= 2.3.2")
890
905
 
891
906
  if ActiveSupport.const_defined?(:Dependencies)
892
907
  dependencies = ActiveSupport::Dependencies
@@ -899,7 +914,7 @@ if dependencies.respond_to?(:load_paths)
899
914
  end
900
915
 
901
916
  module ActiveLdap
902
- VERSION = "1.0.9"
917
+ VERSION = "1.1.0"
903
918
  end
904
919
 
905
920
  if RUBY_PLATFORM.match('linux')
@@ -908,21 +923,11 @@ else
908
923
  require 'active_ldap/timeout_stub'
909
924
  end
910
925
 
911
- require_gem_if_need.call("active_record", "activerecord")
926
+ require_gem_if_need.call("active_record", "activerecord", "= 2.3.2")
912
927
  begin
913
- raise LoadError, "GetText is disabled."
914
- require_gem_if_need.call("locale")
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
928
+ require_gem_if_need.call("locale", nil, "= 2.0.4")
929
+ require_gem_if_need.call("gettext", nil, "= 2.0.4")
930
+ require_gem_if_need.call("gettext_activerecord", nil, "= 2.0.4")
926
931
  rescue LoadError
927
932
  end
928
933
  require 'active_ldap/get_text'