ruby-activeldap 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGES +5 -0
  2. data/Manifest.txt +91 -25
  3. data/README +22 -0
  4. data/Rakefile +41 -8
  5. data/TODO +1 -6
  6. data/examples/config.yaml.example +5 -0
  7. data/examples/example.der +0 -0
  8. data/examples/example.jpg +0 -0
  9. data/examples/groupadd +41 -0
  10. data/examples/groupdel +35 -0
  11. data/examples/groupls +49 -0
  12. data/examples/groupmod +42 -0
  13. data/examples/lpasswd +55 -0
  14. data/examples/objects/group.rb +13 -0
  15. data/examples/objects/ou.rb +4 -0
  16. data/examples/objects/user.rb +20 -0
  17. data/examples/ouadd +38 -0
  18. data/examples/useradd +45 -0
  19. data/examples/useradd-binary +50 -0
  20. data/examples/userdel +34 -0
  21. data/examples/userls +50 -0
  22. data/examples/usermod +42 -0
  23. data/examples/usermod-binary-add +47 -0
  24. data/examples/usermod-binary-add-time +51 -0
  25. data/examples/usermod-binary-del +48 -0
  26. data/examples/usermod-lang-add +43 -0
  27. data/lib/active_ldap.rb +213 -214
  28. data/lib/active_ldap/adapter/base.rb +461 -0
  29. data/lib/active_ldap/adapter/ldap.rb +232 -0
  30. data/lib/active_ldap/adapter/ldap_ext.rb +69 -0
  31. data/lib/active_ldap/adapter/net_ldap.rb +288 -0
  32. data/lib/active_ldap/adapter/net_ldap_ext.rb +29 -0
  33. data/lib/active_ldap/association/belongs_to.rb +3 -1
  34. data/lib/active_ldap/association/belongs_to_many.rb +5 -6
  35. data/lib/active_ldap/association/has_many.rb +9 -17
  36. data/lib/active_ldap/association/has_many_wrap.rb +4 -5
  37. data/lib/active_ldap/attributes.rb +4 -0
  38. data/lib/active_ldap/base.rb +201 -56
  39. data/lib/active_ldap/configuration.rb +11 -1
  40. data/lib/active_ldap/connection.rb +15 -9
  41. data/lib/active_ldap/distinguished_name.rb +246 -0
  42. data/lib/active_ldap/ldap_error.rb +74 -0
  43. data/lib/active_ldap/object_class.rb +9 -5
  44. data/lib/active_ldap/schema.rb +50 -9
  45. data/lib/active_ldap/validations.rb +11 -13
  46. data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +7 -0
  47. data/rails/plugin/active_ldap/generators/scaffold_al/templates/ldap.yml +21 -0
  48. data/rails/plugin/active_ldap/init.rb +10 -4
  49. data/test/al-test-utils.rb +46 -3
  50. data/test/run-test.rb +16 -4
  51. data/test/test-unit-ext/always-show-result.rb +28 -0
  52. data/test/test-unit-ext/priority.rb +163 -0
  53. data/test/test_adapter.rb +81 -0
  54. data/test/test_attributes.rb +8 -1
  55. data/test/test_base.rb +132 -3
  56. data/test/test_base_per_instance.rb +14 -3
  57. data/test/test_connection.rb +19 -0
  58. data/test/test_dn.rb +161 -0
  59. data/test/test_find.rb +24 -0
  60. data/test/test_object_class.rb +15 -2
  61. data/test/test_schema.rb +108 -1
  62. metadata +111 -41
  63. data/lib/active_ldap/adaptor/base.rb +0 -29
  64. data/lib/active_ldap/adaptor/ldap.rb +0 -466
  65. data/lib/active_ldap/ldap.rb +0 -113
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.8.2:
2
+ * Added Net::LDAP support!
3
+ * Loads of bug fixes and enhancements -- see SVN for a complete history!
1
4
  0.8.1:
2
5
  * used Dependencies.load_paths.
3
6
  * check whether attribute name is available or not.
@@ -28,6 +31,8 @@
28
31
  * API TRANSITION: Base#write is now deprecated. Please use Base#save
29
32
  * API TRANSITION: Added SaveError exception (which is a subclass of WriteError for now)
30
33
  * API TRANSITION: Base.connect() is now deprecated. Please use Base.establish_connection()
34
+ * API TRANSITION: Base.close() is now deprecated. Please use Base.remove_connection()
35
+ * API TRANSITION: :bind_format and :user of Base.establish_connection() are now deprecated. Please use :bind_dn
31
36
  * Added update_attribute(name, value) to update one attribute and save immediately
32
37
  * #delete -> #destroy
33
38
  * Base.destroy_all
data/Manifest.txt CHANGED
@@ -1,33 +1,99 @@
1
- Rakefile
2
- LICENSE
3
- TODO
4
- COPYING
5
1
  CHANGES
6
- README
2
+ COPYING
3
+ LICENSE
7
4
  Manifest.txt
8
- lib/active_ldap/adaptor/ldap.rb
9
- lib/active_ldap/adaptor/base.rb
10
- lib/active_ldap/association/has_many_wrap.rb
11
- lib/active_ldap/association/has_many.rb
12
- lib/active_ldap/association/proxy.rb
5
+ README
6
+ Rakefile
7
+ TODO
8
+ benchmark/bench-al.rb
9
+ examples/config.yaml.example
10
+ examples/example.der
11
+ examples/example.jpg
12
+ examples/groupadd
13
+ examples/groupdel
14
+ examples/groupls
15
+ examples/groupmod
16
+ examples/lpasswd
17
+ examples/objects/group.rb
18
+ examples/objects/ou.rb
19
+ examples/objects/user.rb
20
+ examples/ouadd
21
+ examples/useradd
22
+ examples/useradd-binary
23
+ examples/userdel
24
+ examples/userls
25
+ examples/usermod
26
+ examples/usermod-binary-add
27
+ examples/usermod-binary-add-time
28
+ examples/usermod-binary-del
29
+ examples/usermod-lang-add
30
+ lib/active_ldap.rb
31
+ lib/active_ldap/adapter/base.rb
32
+ lib/active_ldap/adapter/ldap.rb
33
+ lib/active_ldap/adapter/ldap_ext.rb
34
+ lib/active_ldap/adapter/net_ldap.rb
35
+ lib/active_ldap/adapter/net_ldap_ext.rb
36
+ lib/active_ldap/association/belongs_to.rb
13
37
  lib/active_ldap/association/belongs_to_many.rb
14
38
  lib/active_ldap/association/collection.rb
15
- lib/active_ldap/association/belongs_to.rb
16
- lib/active_ldap/validations.rb
17
- lib/active_ldap/command.rb
18
- lib/active_ldap/callbacks.rb
19
- lib/active_ldap/ldap.rb
20
- lib/active_ldap/timeout_stub.rb
21
- lib/active_ldap/timeout.rb
39
+ lib/active_ldap/association/has_many.rb
40
+ lib/active_ldap/association/has_many_wrap.rb
41
+ lib/active_ldap/association/proxy.rb
42
+ lib/active_ldap/associations.rb
22
43
  lib/active_ldap/attributes.rb
23
- lib/active_ldap/object_class.rb
44
+ lib/active_ldap/base.rb
45
+ lib/active_ldap/callbacks.rb
46
+ lib/active_ldap/command.rb
47
+ lib/active_ldap/configuration.rb
24
48
  lib/active_ldap/connection.rb
25
- lib/active_ldap/associations.rb
26
- lib/active_ldap/user_password.rb
49
+ lib/active_ldap/distinguished_name.rb
50
+ lib/active_ldap/ldap_error.rb
51
+ lib/active_ldap/object_class.rb
27
52
  lib/active_ldap/schema.rb
28
- lib/active_ldap/configuration.rb
29
- lib/active_ldap/base.rb
30
- lib/active_ldap.rb
31
- benchmark/bench-al.rb
32
- rails/plugin/active_ldap/init.rb
53
+ lib/active_ldap/timeout.rb
54
+ lib/active_ldap/timeout_stub.rb
55
+ lib/active_ldap/user_password.rb
56
+ lib/active_ldap/validations.rb
33
57
  rails/plugin/active_ldap/README
58
+ rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb
59
+ rails/plugin/active_ldap/generators/scaffold_al/templates/ldap.yml
60
+ rails/plugin/active_ldap/init.rb
61
+ test/TODO
62
+ test/al-test-utils.rb
63
+ test/command.rb
64
+ test/config.yaml.sample
65
+ test/run-test.rb
66
+ test/test-unit-ext.rb
67
+ test/test-unit-ext/always-show-result.rb
68
+ test/test-unit-ext/priority.rb
69
+ test/test_adapter.rb
70
+ test/test_associations.rb
71
+ test/test_attributes.rb
72
+ test/test_base.rb
73
+ test/test_base_per_instance.rb
74
+ test/test_bind.rb
75
+ test/test_callback.rb
76
+ test/test_connection.rb
77
+ test/test_connection_per_class.rb
78
+ test/test_dn.rb
79
+ test/test_find.rb
80
+ test/test_groupadd.rb
81
+ test/test_groupdel.rb
82
+ test/test_groupls.rb
83
+ test/test_groupmod.rb
84
+ test/test_lpasswd.rb
85
+ test/test_object_class.rb
86
+ test/test_reflection.rb
87
+ test/test_schema.rb
88
+ test/test_user.rb
89
+ test/test_user_password.rb
90
+ test/test_useradd-binary.rb
91
+ test/test_useradd.rb
92
+ test/test_userdel.rb
93
+ test/test_userls.rb
94
+ test/test_usermod-binary-add-time.rb
95
+ test/test_usermod-binary-add.rb
96
+ test/test_usermod-binary-del.rb
97
+ test/test_usermod-lang-add.rb
98
+ test/test_usermod.rb
99
+ test/test_validation.rb
data/README CHANGED
@@ -40,6 +40,28 @@ INSTALL
40
40
  - Run -
41
41
  sudo rake install
42
42
 
43
+ RAILS
44
+
45
+ There is a small rails plugin included that allows the use of a file named
46
+ 'ldap.yml' in the config directory of your rails app. This file has a similar
47
+ function to the 'database.yml' file that allows you to set your database
48
+ connection settings per environment. Similarly, the ldap.yml file allows
49
+ settings to be set for development, test, and production environments. For
50
+ instance, the development entry would look something like the following:
51
+
52
+ development:
53
+ host: 127.0.0.1
54
+ port: 389
55
+ base: dc=localhost
56
+ bind_dn: cn=admin,dc=localhost
57
+ password: secret
58
+
59
+
60
+ To install, simply copy the rails/plugin/active_ldap folder into the
61
+ vendor/plugins directory of your rails application and create config/ldap.yml.
62
+ When your application starts up, the plugin will call #establish_connection
63
+ using the parameters specified for your current environment.
64
+
43
65
 
44
66
  LICENCE
45
67
 
data/Rakefile CHANGED
@@ -2,21 +2,22 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
- $:<<'./lib'
5
+ $LOAD_PATH.unshift('./lib')
6
6
  require 'active_ldap'
7
7
 
8
- Hoe.new('ruby-activeldap', ActiveLdap::VERSION) do |project|
8
+ project = Hoe.new('ruby-activeldap', ActiveLdap::VERSION) do |project|
9
9
  project.rubyforge_name = 'ruby-activeldap'
10
10
  project.author = ['Will Drewry', 'Kouhei Sutou']
11
11
  project.email = ['will@alum.bu.edu', 'kou@cozmixng.org']
12
12
  project.summary = 'Ruby/ActiveLdap is a object-oriented API to LDAP'
13
13
  project.url = 'http://rubyforge.org/projects/ruby-activeldap/'
14
- project.test_globs = ['test/**']
14
+ project.test_globs = ['test/test_*.rb']
15
15
  project.changes = project.paragraphs_of('CHANGES', 0..1).join("\n\n")
16
- project.extra_deps = [['log4r','>= 1.0.4'], 'activerecord']
16
+ project.extra_deps = [['log4r', '>= 1.0.4'], 'activerecord']
17
17
  project.spec_extras = {
18
18
  :requirements => ['ruby-ldap >= 0.8.2', '(Open)LDAP server'],
19
- :autorequire => 'active_ldap'
19
+ :autorequire => 'active_ldap',
20
+ :executables => [],
20
21
  }
21
22
  project.description = String.new(<<-EOF)
22
23
  'Ruby/ActiveLdap' is a ruby extension library which provides a clean
@@ -27,11 +28,43 @@ Hoe.new('ruby-activeldap', ActiveLdap::VERSION) do |project|
27
28
  EOF
28
29
  end
29
30
 
31
+ # fix Hoe's incorrect guess.
32
+ project.spec.executables.clear
33
+ project.bin_files = project.spec.files.grep(/^bin/)
34
+
35
+ # fix Hoe's install and uninstall task.
36
+ task(:install).instance_variable_get("@actions").clear
37
+ task(:uninstall).instance_variable_get("@actions").clear
38
+
39
+ task :install do
40
+ [
41
+ [project.lib_files, "lib", Hoe::RUBYLIB, 0444],
42
+ [project.bin_files, "bin", File.join(Hoe::PREFIX, 'bin'), 0555]
43
+ ].each do |files, prefix, dest, mode|
44
+ FileUtils.mkdir_p dest unless test ?d, dest
45
+ files.each do |file|
46
+ base = File.dirname(file.sub(/^#{prefix}#{File::SEPARATOR}/, ''))
47
+ _dest = File.join(dest, base)
48
+ FileUtils.mkdir_p _dest unless test ?d, _dest
49
+ install file, _dest, :mode => mode
50
+ end
51
+ end
52
+ end
53
+
54
+ desc 'Uninstall the package.'
55
+ task :uninstall do
56
+ Dir.chdir Hoe::RUBYLIB do
57
+ rm_f project.lib_files.collect {|f| f.sub(/^lib#{File::SEPARATOR}/, '')}
58
+ end
59
+ Dir.chdir File.join(Hoe::PREFIX, 'bin') do
60
+ rm_f project.bin_files.collect {|f| f.sub(/^bin#{File::SEPARATOR}/, '')}
61
+ end
62
+ end
63
+
64
+
30
65
  desc 'Tag the repository for release.'
31
66
  task :tag do
32
67
  system "svn copy -m 'New release tag' https://ruby-activeldap.googlecode.com/svn/trunk https://ruby-activeldap.googlecode.com/svn/tags/r#{ActiveLdap::VERSION}"
33
68
  end
34
69
 
35
-
36
-
37
- # vim: syntax=Ruby
70
+ # vim: syntax=ruby
data/TODO CHANGED
@@ -1,4 +1,4 @@
1
- - Fix case sensitivity in object classes
1
+ - Test SASL bind.
2
2
  - Add result pagination via LDAP::Controls
3
3
  - serialize & serialized_attributes
4
4
  - schema mgmt - how does AR handle it?
@@ -9,9 +9,6 @@ http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000865
9
9
  ActiveLdap exception. I think we need to develop an
10
10
  application using ActiveLdap.
11
11
  - support Ruby/GetText.
12
- - support Net::LDAP as LDAP backend after Net::LDAP
13
- supports START_TLS. (I made a patch and submitted to the
14
- bug tracker of Net::LDAP)
15
12
  - Add locking around Timeout.alarm() to ensure a multithreaded ruby
16
13
  app doesn't hit any race conditions
17
14
  - Add AR matching exceptions:
@@ -24,5 +21,3 @@ http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000865
24
21
  * MultiparameterAssignmentErrors
25
22
  * AttributeAssignmentError
26
23
  * RecordNotSaved
27
-
28
-
@@ -0,0 +1,5 @@
1
+ host: 127.0.0.1
2
+ method: :tls
3
+ base: dc=localdomain
4
+ bind_dn: cn=admin,dc=localdomain
5
+ #adapter: net-ldap
Binary file
Binary file
data/examples/groupadd ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby -W0
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.establish_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ if Group.exists?(name)
30
+ $stderr.puts("Group #{name} already exists.")
31
+ exit 1
32
+ end
33
+
34
+ group = Group.new(name)
35
+ group.gid_number = 9000
36
+
37
+ unless group.save
38
+ puts "failed"
39
+ puts group.errors.full_messages
40
+ exit 1
41
+ end
data/examples/groupdel ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -W0
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.establish_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+
30
+ unless Group.exists?(name)
31
+ $stderr.puts("Group #{name} doesn't exist.")
32
+ exit 1
33
+ end
34
+
35
+ Group.destroy(name)
data/examples/groupls ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/ruby -W0
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.establish_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ unless Group.exists?(name)
30
+ $stderr.puts("Group #{name} doesn't exist.")
31
+ exit 1
32
+ end
33
+
34
+ group = Group.find(name)
35
+
36
+ members = []
37
+ group.primary_members.each do |mem|
38
+ members << "#{mem.uid}[#{mem.uidNumber}]"
39
+ end
40
+
41
+ group.members.each do |mem|
42
+ if mem.new_entry?
43
+ members << "#{mem.uid}[????]"
44
+ else
45
+ members << "#{mem.uid}[#{mem.uidNumber}]"
46
+ end
47
+ end
48
+
49
+ puts("#{group.id}(#{group.gid_number}): #{members.join(', ')}")
data/examples/groupmod ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby -W0
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME GID_NUMBER"
13
+ end
14
+
15
+ if argv.size == 2
16
+ name, gid = argv
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.establish_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+
30
+ unless Group.exists?(name)
31
+ $stderr.puts("Group #{name} doesn't exist.")
32
+ exit 1
33
+ end
34
+
35
+ group = Group.find(name)
36
+ group.gid_number = gid
37
+
38
+ unless group.save
39
+ puts "failed"
40
+ puts group.errors.full_messages
41
+ exit 1
42
+ end