powerhome-activeldap 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/COPYING +340 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +59 -0
  6. data/README.textile +140 -0
  7. data/TODO +32 -0
  8. data/benchmark/README.md +64 -0
  9. data/benchmark/bench-backend.rb +247 -0
  10. data/benchmark/bench-instantiate.rb +98 -0
  11. data/benchmark/config.yaml.sample +5 -0
  12. data/doc/text/development.textile +54 -0
  13. data/doc/text/news.textile +811 -0
  14. data/doc/text/rails.textile +144 -0
  15. data/doc/text/tutorial.textile +1010 -0
  16. data/examples/config.yaml.example +5 -0
  17. data/examples/example.der +0 -0
  18. data/examples/example.jpg +0 -0
  19. data/examples/groupadd +41 -0
  20. data/examples/groupdel +35 -0
  21. data/examples/groupls +49 -0
  22. data/examples/groupmod +42 -0
  23. data/examples/lpasswd +55 -0
  24. data/examples/objects/group.rb +13 -0
  25. data/examples/objects/ou.rb +4 -0
  26. data/examples/objects/user.rb +20 -0
  27. data/examples/ouadd +38 -0
  28. data/examples/useradd +45 -0
  29. data/examples/useradd-binary +53 -0
  30. data/examples/userdel +34 -0
  31. data/examples/userls +50 -0
  32. data/examples/usermod +42 -0
  33. data/examples/usermod-binary-add +50 -0
  34. data/examples/usermod-binary-add-time +54 -0
  35. data/examples/usermod-binary-del +48 -0
  36. data/examples/usermod-lang-add +43 -0
  37. data/lib/active_ldap.rb +85 -0
  38. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +55 -0
  39. data/lib/active_ldap/acts/tree.rb +78 -0
  40. data/lib/active_ldap/adapter/base.rb +707 -0
  41. data/lib/active_ldap/adapter/jndi.rb +184 -0
  42. data/lib/active_ldap/adapter/jndi_connection.rb +185 -0
  43. data/lib/active_ldap/adapter/ldap.rb +290 -0
  44. data/lib/active_ldap/adapter/ldap_ext.rb +105 -0
  45. data/lib/active_ldap/adapter/net_ldap.rb +309 -0
  46. data/lib/active_ldap/adapter/net_ldap_ext.rb +23 -0
  47. data/lib/active_ldap/association/belongs_to.rb +47 -0
  48. data/lib/active_ldap/association/belongs_to_many.rb +58 -0
  49. data/lib/active_ldap/association/children.rb +21 -0
  50. data/lib/active_ldap/association/collection.rb +105 -0
  51. data/lib/active_ldap/association/has_many.rb +31 -0
  52. data/lib/active_ldap/association/has_many_utils.rb +44 -0
  53. data/lib/active_ldap/association/has_many_wrap.rb +75 -0
  54. data/lib/active_ldap/association/proxy.rb +107 -0
  55. data/lib/active_ldap/associations.rb +205 -0
  56. data/lib/active_ldap/attribute_methods.rb +23 -0
  57. data/lib/active_ldap/attribute_methods/before_type_cast.rb +24 -0
  58. data/lib/active_ldap/attribute_methods/dirty.rb +43 -0
  59. data/lib/active_ldap/attribute_methods/query.rb +31 -0
  60. data/lib/active_ldap/attribute_methods/read.rb +44 -0
  61. data/lib/active_ldap/attribute_methods/write.rb +38 -0
  62. data/lib/active_ldap/attributes.rb +176 -0
  63. data/lib/active_ldap/base.rb +1410 -0
  64. data/lib/active_ldap/callbacks.rb +71 -0
  65. data/lib/active_ldap/command.rb +49 -0
  66. data/lib/active_ldap/compatible.rb +44 -0
  67. data/lib/active_ldap/configuration.rb +147 -0
  68. data/lib/active_ldap/connection.rb +299 -0
  69. data/lib/active_ldap/distinguished_name.rb +291 -0
  70. data/lib/active_ldap/entry_attribute.rb +78 -0
  71. data/lib/active_ldap/escape.rb +12 -0
  72. data/lib/active_ldap/get_text.rb +20 -0
  73. data/lib/active_ldap/get_text/parser.rb +161 -0
  74. data/lib/active_ldap/helper.rb +92 -0
  75. data/lib/active_ldap/human_readable.rb +133 -0
  76. data/lib/active_ldap/ldap_error.rb +74 -0
  77. data/lib/active_ldap/ldif.rb +930 -0
  78. data/lib/active_ldap/log_subscriber.rb +50 -0
  79. data/lib/active_ldap/object_class.rb +95 -0
  80. data/lib/active_ldap/operations.rb +624 -0
  81. data/lib/active_ldap/persistence.rb +100 -0
  82. data/lib/active_ldap/populate.rb +53 -0
  83. data/lib/active_ldap/railtie.rb +43 -0
  84. data/lib/active_ldap/railties/controller_runtime.rb +48 -0
  85. data/lib/active_ldap/schema.rb +701 -0
  86. data/lib/active_ldap/schema/syntaxes.rb +422 -0
  87. data/lib/active_ldap/timeout.rb +75 -0
  88. data/lib/active_ldap/timeout_stub.rb +17 -0
  89. data/lib/active_ldap/user_password.rb +99 -0
  90. data/lib/active_ldap/validations.rb +200 -0
  91. data/lib/active_ldap/version.rb +3 -0
  92. data/lib/active_ldap/xml.rb +139 -0
  93. data/lib/rails/generators/active_ldap/model/USAGE +18 -0
  94. data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
  95. data/lib/rails/generators/active_ldap/model/templates/model_active_ldap.rb +3 -0
  96. data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
  97. data/lib/rails/generators/active_ldap/scaffold/templates/ldap.yml +19 -0
  98. data/po/en/active-ldap.po +4029 -0
  99. data/po/ja/active-ldap.po +4060 -0
  100. data/test/add-phonetic-attribute-options-to-slapd.ldif +10 -0
  101. data/test/al-test-utils.rb +428 -0
  102. data/test/command.rb +111 -0
  103. data/test/config.yaml.sample +6 -0
  104. data/test/fixtures/lower_case_object_class_schema.rb +802 -0
  105. data/test/run-test.rb +34 -0
  106. data/test/test_acts_as_tree.rb +60 -0
  107. data/test/test_adapter.rb +121 -0
  108. data/test/test_associations.rb +701 -0
  109. data/test/test_attributes.rb +117 -0
  110. data/test/test_base.rb +1214 -0
  111. data/test/test_base_per_instance.rb +61 -0
  112. data/test/test_bind.rb +62 -0
  113. data/test/test_callback.rb +31 -0
  114. data/test/test_configuration.rb +40 -0
  115. data/test/test_connection.rb +82 -0
  116. data/test/test_connection_per_class.rb +112 -0
  117. data/test/test_connection_per_dn.rb +112 -0
  118. data/test/test_dirty.rb +98 -0
  119. data/test/test_dn.rb +172 -0
  120. data/test/test_find.rb +176 -0
  121. data/test/test_groupadd.rb +50 -0
  122. data/test/test_groupdel.rb +46 -0
  123. data/test/test_groupls.rb +107 -0
  124. data/test/test_groupmod.rb +51 -0
  125. data/test/test_ldif.rb +1890 -0
  126. data/test/test_load.rb +133 -0
  127. data/test/test_lpasswd.rb +75 -0
  128. data/test/test_object_class.rb +74 -0
  129. data/test/test_persistence.rb +131 -0
  130. data/test/test_reflection.rb +175 -0
  131. data/test/test_schema.rb +559 -0
  132. data/test/test_syntax.rb +444 -0
  133. data/test/test_user.rb +217 -0
  134. data/test/test_user_password.rb +108 -0
  135. data/test/test_useradd-binary.rb +62 -0
  136. data/test/test_useradd.rb +57 -0
  137. data/test/test_userdel.rb +48 -0
  138. data/test/test_userls.rb +91 -0
  139. data/test/test_usermod-binary-add-time.rb +65 -0
  140. data/test/test_usermod-binary-add.rb +64 -0
  141. data/test/test_usermod-binary-del.rb +66 -0
  142. data/test/test_usermod-lang-add.rb +59 -0
  143. data/test/test_usermod.rb +58 -0
  144. data/test/test_validation.rb +274 -0
  145. metadata +379 -0
@@ -0,0 +1,58 @@
1
+ require 'active_ldap/association/collection'
2
+
3
+ module ActiveLdap
4
+ module Association
5
+ class BelongsToMany < Collection
6
+ private
7
+ def insert_entry(entry)
8
+ _foreign_class = foreign_class
9
+ entry = _foreign_class.find(entry) unless entry.is_a?(_foreign_class)
10
+ old_value = entry[@options[:many], true]
11
+ primary_key_name = @options[:primary_key_name]
12
+ if primary_key_name == "dn"
13
+ old_value = dn_values_to_string_values(old_value)
14
+ end
15
+ current_value = @owner[primary_key_name, true]
16
+ current_value = dn_values_to_string_values(current_value)
17
+ new_value = old_value + current_value
18
+ new_value = new_value.uniq.sort
19
+ if old_value != new_value
20
+ entry[@options[:many]] = new_value
21
+ entry.save
22
+ end
23
+ end
24
+
25
+ def delete_entries(entries)
26
+ _foreign_class = foreign_class
27
+ entries.each do |entry|
28
+ entry = _foreign_class.find(entry) unless entry.is_a?(_foreign_class)
29
+ old_value = entry[@options[:many], true]
30
+ primary_key_name = @options[:primary_key_name]
31
+ if primary_key_name == "dn"
32
+ old_value = dn_values_to_string_values(old_value)
33
+ end
34
+ current_value = @owner[primary_key_name, true]
35
+ current_value = dn_values_to_string_values(current_value)
36
+ new_value = old_value - current_value
37
+ new_value = new_value.uniq.sort
38
+ if old_value != new_value
39
+ entry[@options[:many]] = new_value
40
+ entry.save
41
+ end
42
+ end
43
+ end
44
+
45
+ def find_target
46
+ values = @owner[@options[:primary_key_name], true].compact
47
+ return [] if values.empty?
48
+
49
+ key = @options[:many]
50
+ components = values.collect do |value|
51
+ [key, value]
52
+ end
53
+ options = find_options(:filter => [:or, *components])
54
+ foreign_class.find(:all, options)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_ldap/association/collection'
2
+
3
+ module ActiveLdap
4
+ module Association
5
+ class Children < Collection
6
+ private
7
+ def insert_entry(entry)
8
+ entry.dn = [entry.id, @owner.dn.to_s].join(",")
9
+ entry.save
10
+ end
11
+
12
+ def find_target
13
+ @owner.find(:all, :base => @owner.dn, :scope => :one)
14
+ end
15
+
16
+ def delete_entries(entries)
17
+ entries.each(&:destroy)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,105 @@
1
+ require 'active_ldap/association/proxy'
2
+
3
+ module ActiveLdap
4
+ module Association
5
+ class Collection < Proxy
6
+ include Enumerable
7
+
8
+ def to_ary
9
+ load_target
10
+ @target.to_ary
11
+ end
12
+
13
+ def reset
14
+ @target = []
15
+ @loaded = false
16
+ end
17
+
18
+ def <<(*entries)
19
+ add_entries(*entries)
20
+ end
21
+ alias_method(:push, :<<)
22
+ alias_method(:concat, :<<)
23
+
24
+ def each(&block)
25
+ to_ary.each(&block)
26
+ end
27
+
28
+ def delete(*entries)
29
+ entries = flatten_deeper(entries).reject do |entry|
30
+ @target.delete(entry) if entry.new_entry?
31
+ entry.new_entry?
32
+ end
33
+ return if entries.empty?
34
+
35
+ delete_entries(entries)
36
+ entries.each do |entry|
37
+ @target.delete(entry)
38
+ end
39
+ end
40
+
41
+ def replace(others)
42
+ load_target
43
+
44
+ entry = @target.first
45
+ if entry.nil?
46
+ deleted_entries = []
47
+ added_entries = others
48
+ else
49
+ base_class = entry.class
50
+ others = others.collect do |other|
51
+ other = base_class.find(other) unless other.is_a?(base_class)
52
+ other
53
+ end
54
+ deleted_entries = @target - others
55
+ added_entries = others - @target
56
+ end
57
+
58
+ delete(deleted_entries)
59
+ concat(added_entries)
60
+ end
61
+
62
+ def exists?
63
+ load_target
64
+ not @target.empty?
65
+ end
66
+
67
+ private
68
+ def flatten_deeper(array)
69
+ array.collect do |element|
70
+ element.respond_to?(:flatten) ? element.flatten : element
71
+ end.flatten
72
+ end
73
+
74
+ def insert_entry(entry)
75
+ entry[@options[:foreign_key_name]] = @owner[@options[:local_key_name]]
76
+ entry.save
77
+ end
78
+
79
+ def add_entries(*entries)
80
+ result = true
81
+ load_target
82
+
83
+ flatten_deeper(entries).each do |entry|
84
+ unless @owner.new_entry?
85
+ infect_connection(entry)
86
+ result &&= insert_entry(entry)
87
+ end
88
+ @target << entry
89
+ end
90
+
91
+ result && self
92
+ end
93
+
94
+ def dn_values_to_string_values(values)
95
+ values.collect do |value|
96
+ if value.is_a?(DN)
97
+ value.to_s
98
+ else
99
+ value
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_ldap/association/collection'
2
+ require 'active_ldap/association/has_many_utils'
3
+
4
+ module ActiveLdap
5
+ module Association
6
+ class HasMany < Collection
7
+ include HasManyUtils
8
+
9
+ private
10
+ def insert_entry(entry)
11
+ entry[foreign_key] = @owner[primary_key]
12
+ entry.save
13
+ end
14
+
15
+ def find_target
16
+ collect_targets(primary_key)
17
+ end
18
+
19
+ def delete_entries(entries)
20
+ _foreign_key = foreign_key
21
+ components = @owner[primary_key, true].reject do |value|
22
+ value.nil?
23
+ end
24
+ filter = [:and,
25
+ [:and, {_foreign_key => components}],
26
+ [:or, {foreign_class.dn_attribute => entries.collect(&:id)}]]
27
+ foreign_class.update_all({_foreign_key => []}, filter)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ module ActiveLdap
2
+ module Association
3
+ module HasManyUtils
4
+ private
5
+ def collect_targets(requested_target_key, need_requested_targets=false)
6
+ _foreign_key = foreign_key
7
+ return [] if _foreign_key.nil?
8
+
9
+ requested_targets = @owner[requested_target_key, true]
10
+ requested_targets = requested_targets.reject(&:nil?)
11
+ if requested_targets.empty?
12
+ targets = []
13
+ elsif _foreign_key == "dn"
14
+ requested_targets = requested_targets.collect do |target|
15
+ if target.is_a?(DN)
16
+ target
17
+ else
18
+ DN.parse(target)
19
+ end
20
+ end
21
+ targets = []
22
+ requested_targets.each do |target|
23
+ begin
24
+ targets << foreign_class.find(target, find_options)
25
+ rescue EntryNotFound
26
+ end
27
+ end
28
+ else
29
+ components = requested_targets.collect do |value|
30
+ [_foreign_key, value]
31
+ end
32
+ options = find_options(:filter => [:or, *components])
33
+ targets = foreign_class.find(:all, options)
34
+ end
35
+
36
+ if need_requested_targets
37
+ [targets, requested_targets]
38
+ else
39
+ targets
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,75 @@
1
+ require 'active_ldap/association/collection'
2
+ require 'active_ldap/association/has_many_utils'
3
+
4
+ module ActiveLdap
5
+ module Association
6
+ class HasManyWrap < Collection
7
+ include HasManyUtils
8
+
9
+ private
10
+ def insert_entry(entry)
11
+ old_value = @owner[@options[:wrap], true]
12
+ _foreign_key = foreign_key
13
+ if _foreign_key == "dn"
14
+ old_value = dn_values_to_string_values(old_value)
15
+ end
16
+ current_value = entry[_foreign_key, true]
17
+ current_value = dn_values_to_string_values(current_value)
18
+ new_value = (old_value + current_value).uniq.sort
19
+ if old_value != new_value
20
+ @owner[@options[:wrap]] = new_value
21
+ @owner.save unless @owner.new_entry?
22
+ end
23
+ end
24
+
25
+ def delete_entries(entries)
26
+ old_value = @owner[@options[:wrap], true]
27
+ _foreign_key = foreign_key
28
+ if _foreign_key == "dn"
29
+ old_value = dn_values_to_string_values(old_value)
30
+ end
31
+ current_value = entries.collect {|entry| entry[_foreign_key]}
32
+ current_value = dn_values_to_string_values(current_value)
33
+ new_value = old_value - current_value
34
+ new_value = new_value.uniq.sort
35
+ if old_value != new_value
36
+ @owner[@options[:wrap]] = new_value
37
+ @owner.save unless @owner.new_entry?
38
+ end
39
+ end
40
+
41
+ def find_target
42
+ targets, requested_targets = collect_targets(@options[:wrap], true)
43
+ return [] if targets.nil?
44
+
45
+ found_targets = {}
46
+ _foreign_key = foreign_key
47
+ targets.each do |target|
48
+ found_targets[target[_foreign_key]] ||= target
49
+ end
50
+
51
+ klass = foreign_class
52
+ requested_targets.collect do |name|
53
+ found_targets[name] || klass.new(name)
54
+ end
55
+ end
56
+
57
+ def foreign_key
58
+ @options[:primary_key_name] || foreign_class.dn_attribute
59
+ end
60
+
61
+ def add_entries(*entries)
62
+ result = true
63
+ load_target
64
+
65
+ flatten_deeper(entries).each do |entry|
66
+ infect_connection(entry)
67
+ insert_entry(entry) or result = false
68
+ @target << entry
69
+ end
70
+
71
+ result && self
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,107 @@
1
+ module ActiveLdap
2
+ module Association
3
+ class Proxy
4
+ alias_method :proxy_respond_to?, :respond_to?
5
+ alias_method :proxy_extend, :extend
6
+ delegate :to_param, :to => :target
7
+
8
+ def initialize(owner, options)
9
+ @owner = owner
10
+ @options = options
11
+ reset
12
+ extend(options[:extend]) if options[:extend]
13
+ end
14
+
15
+ def respond_to?(symbol, include_priv=false)
16
+ proxy_respond_to?(symbol, include_priv) or
17
+ (load_target && @target.respond_to?(symbol, include_priv))
18
+ end
19
+
20
+ def ===(other)
21
+ load_target and other === @target
22
+ end
23
+
24
+ def reset
25
+ @target = nil
26
+ @loaded = false
27
+ end
28
+
29
+ def reload
30
+ reset
31
+ load_target
32
+ end
33
+
34
+ def loaded?
35
+ @loaded
36
+ end
37
+
38
+ def loaded
39
+ @loaded = true
40
+ end
41
+
42
+ def target
43
+ @target
44
+ end
45
+
46
+ def target=(target)
47
+ @target = target
48
+ loaded
49
+ end
50
+
51
+ def exists?
52
+ load_target
53
+ not @target.nil?
54
+ end
55
+
56
+ private
57
+ def method_missing(method, *args, &block)
58
+ load_target
59
+ @target.send(method, *args, &block)
60
+ end
61
+
62
+ def foreign_class
63
+ klass = @owner.class.associated_class(@options[:association_id])
64
+ klass = @owner.class.module_eval(klass) if klass.is_a?(String)
65
+ klass
66
+ end
67
+
68
+ def have_foreign_key?
69
+ false
70
+ end
71
+
72
+ def primary_key
73
+ @options[:primary_key_name] || @owner.dn_attribute
74
+ end
75
+
76
+ def foreign_key
77
+ @options[:foreign_key_name] || foreign_class.dn_attribute
78
+ end
79
+
80
+ def load_target
81
+ if !@owner.new_entry? or have_foreign_key?
82
+ begin
83
+ @target = find_target unless loaded?
84
+ rescue EntryNotFound
85
+ reset
86
+ end
87
+ end
88
+
89
+ loaded if target
90
+ target
91
+ end
92
+
93
+ def find_options(options={})
94
+ if @owner.connection != @owner.class.connection
95
+ {:connection => @owner.connection}.merge(options)
96
+ else
97
+ options
98
+ end
99
+ end
100
+
101
+ def infect_connection(target)
102
+ conn = @owner.instance_variable_get("@connection")
103
+ target.connection = conn if conn
104
+ end
105
+ end
106
+ end
107
+ end