ruby-activeldap 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGES +375 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +58 -0
  4. data/Manifest.txt +33 -0
  5. data/README +63 -0
  6. data/Rakefile +37 -0
  7. data/TODO +31 -0
  8. data/benchmark/bench-al.rb +152 -0
  9. data/lib/{activeldap.rb → active_ldap.rb} +280 -263
  10. data/lib/active_ldap/adaptor/base.rb +29 -0
  11. data/lib/active_ldap/adaptor/ldap.rb +466 -0
  12. data/lib/active_ldap/association/belongs_to.rb +38 -0
  13. data/lib/active_ldap/association/belongs_to_many.rb +40 -0
  14. data/lib/active_ldap/association/collection.rb +80 -0
  15. data/lib/active_ldap/association/has_many.rb +48 -0
  16. data/lib/active_ldap/association/has_many_wrap.rb +56 -0
  17. data/lib/active_ldap/association/proxy.rb +89 -0
  18. data/lib/active_ldap/associations.rb +162 -0
  19. data/lib/active_ldap/attributes.rb +199 -0
  20. data/lib/active_ldap/base.rb +1343 -0
  21. data/lib/active_ldap/callbacks.rb +19 -0
  22. data/lib/active_ldap/command.rb +46 -0
  23. data/lib/active_ldap/configuration.rb +96 -0
  24. data/lib/active_ldap/connection.rb +137 -0
  25. data/lib/{activeldap → active_ldap}/ldap.rb +1 -1
  26. data/lib/active_ldap/object_class.rb +70 -0
  27. data/lib/active_ldap/schema.rb +258 -0
  28. data/lib/{activeldap → active_ldap}/timeout.rb +0 -0
  29. data/lib/{activeldap → active_ldap}/timeout_stub.rb +0 -0
  30. data/lib/active_ldap/user_password.rb +92 -0
  31. data/lib/active_ldap/validations.rb +78 -0
  32. data/rails/plugin/active_ldap/README +54 -0
  33. data/rails/plugin/active_ldap/init.rb +6 -0
  34. data/test/TODO +2 -0
  35. data/test/al-test-utils.rb +337 -0
  36. data/test/command.rb +62 -0
  37. data/test/config.yaml +8 -0
  38. data/test/config.yaml.sample +6 -0
  39. data/test/run-test.rb +17 -0
  40. data/test/test-unit-ext.rb +2 -0
  41. data/test/test_associations.rb +334 -0
  42. data/test/test_attributes.rb +71 -0
  43. data/test/test_base.rb +345 -0
  44. data/test/test_base_per_instance.rb +32 -0
  45. data/test/test_bind.rb +53 -0
  46. data/test/test_callback.rb +35 -0
  47. data/test/test_connection.rb +38 -0
  48. data/test/test_connection_per_class.rb +50 -0
  49. data/test/test_find.rb +36 -0
  50. data/test/test_groupadd.rb +50 -0
  51. data/test/test_groupdel.rb +46 -0
  52. data/test/test_groupls.rb +107 -0
  53. data/test/test_groupmod.rb +51 -0
  54. data/test/test_lpasswd.rb +75 -0
  55. data/test/test_object_class.rb +32 -0
  56. data/test/test_reflection.rb +173 -0
  57. data/test/test_schema.rb +166 -0
  58. data/test/test_user.rb +209 -0
  59. data/test/test_user_password.rb +93 -0
  60. data/test/test_useradd-binary.rb +59 -0
  61. data/test/test_useradd.rb +55 -0
  62. data/test/test_userdel.rb +48 -0
  63. data/test/test_userls.rb +86 -0
  64. data/test/test_usermod-binary-add-time.rb +62 -0
  65. data/test/test_usermod-binary-add.rb +61 -0
  66. data/test/test_usermod-binary-del.rb +64 -0
  67. data/test/test_usermod-lang-add.rb +57 -0
  68. data/test/test_usermod.rb +56 -0
  69. data/test/test_validation.rb +38 -0
  70. metadata +94 -21
  71. data/lib/activeldap/associations.rb +0 -170
  72. data/lib/activeldap/base.rb +0 -1456
  73. data/lib/activeldap/configuration.rb +0 -59
  74. data/lib/activeldap/schema2.rb +0 -217
@@ -1,59 +0,0 @@
1
-
2
- module ActiveLDAP
3
- # Configuration
4
- #
5
- # Configuration provides the default settings required for
6
- # ActiveLDAP to work with your LDAP server. All of these
7
- # settings can be passed in at initialization time.
8
- module Configuration
9
- DEFAULT_CONFIG = {}
10
- DEFAULT_CONFIG[:host] = '127.0.0.1'
11
- DEFAULT_CONFIG[:port] = 389
12
- DEFAULT_CONFIG[:method] = :plain # :ssl, :tls, :plain allowed
13
-
14
- DEFAULT_CONFIG[:bind_format] = "cn=%s,dc=localdomain"
15
- DEFAULT_CONFIG[:user] = ENV['USER']
16
- DEFAULT_CONFIG[:password_block] = nil
17
- DEFAULT_CONFIG[:password] = nil
18
- DEFAULT_CONFIG[:store_password] = true
19
- DEFAULT_CONFIG[:allow_anonymous] = true
20
- DEFAULT_CONFIG[:sasl_quiet] = false
21
- DEFAULT_CONFIG[:try_sasl] = false
22
-
23
- DEFAULT_CONFIG[:retries] = 3
24
- DEFAULT_CONFIG[:retry_wait] = 3
25
- DEFAULT_CONFIG[:timeout] = 0 # in seconds; 0 <= Never timeout
26
- # Whether or not to retry on timeouts
27
- DEFAULT_CONFIG[:retry_on_timeout] = true
28
-
29
- # Whether to return objects by default from find/find_all
30
- DEFAULT_CONFIG[:return_objects] = false
31
-
32
- DEFAULT_CONFIG[:logger] = nil
33
-
34
- # On connect, this is overriden by the :base argument
35
- #
36
- # Set this to LDAP_SCOPE_SUBTREE if you have a LDAP tree where all
37
- # objects of the same class living in different parts of the same subtree, but
38
- # not. LDAP_SCOPE_ONELEVEL is for use when all the objects in your classes live
39
- # under one shared level (e.g. ou=People,dc=localdomain)
40
- #
41
- # This can be overriden on a per class basis in ldap_mapping :scope
42
- def Base.ldap_scope
43
- LDAP::LDAP_SCOPE_ONELEVEL
44
- end
45
-
46
- # On connect, this is overriden by the :base argument
47
- # Make the return value the string that is your LDAP base
48
- def Base.base
49
- 'dc=localdomain'
50
- end
51
-
52
- # This is optionally set to the array of objectClass names
53
- # that are minimally required for EVERY object on your LDAP server.
54
- # If you don't want one, set this to [].
55
- def Base.required_classes
56
- ['top']
57
- end
58
- end
59
- end
@@ -1,217 +0,0 @@
1
- require 'ldap'
2
- require 'ldap/schema'
3
-
4
- module LDAP
5
- class Schema2 < Schema
6
- @@attr_cache = {}
7
- @@class_cache = {}
8
-
9
- # attr
10
- #
11
- # This is just like LDAP::Schema#attr except that it allows
12
- # look up in any of the given keys.
13
- # e.g.
14
- # attr('attributeTypes', 'cn', 'DESC')
15
- # attr('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')
16
- def attr(sub, type, at)
17
- return [] if sub.empty?
18
- return [] if type.empty?
19
- return [] if at.empty?
20
-
21
- type = type.downcase # We're going case insensitive.
22
-
23
- # Check already parsed options first
24
- if @@attr_cache.has_key? sub \
25
- and @@attr_cache[sub].has_key? type \
26
- and @@attr_cache[sub][type].has_key? at
27
- return @@attr_cache[sub][type][at].dup
28
- end
29
-
30
- # Initialize anything that is required
31
- unless @@attr_cache.has_key? sub
32
- @@attr_cache[sub] = {}
33
- end
34
-
35
- unless @@attr_cache[sub].has_key? type
36
- @@attr_cache[sub][type] = {}
37
- end
38
-
39
- at = at.upcase
40
- self[sub].each do |s|
41
- line = ''
42
- if type[0..0] =~ /[0-9]/
43
- if s =~ /\(\s+(?i:#{type})\s+(?:[A-Z]|\))/
44
- line = s
45
- end
46
- else
47
- if s =~ /NAME\s+\(?.*'(?i:#{type})'.*\)?\s+(?:[A-Z]|\))/
48
- line = s
49
- end
50
- end
51
-
52
- # I need to check, but I think some of these matchs
53
- # overlap. I'll need to check these when I'm less sleepy.
54
- multi = ''
55
- case line
56
- when /#{at}\s+[\)A-Z]/
57
- @@attr_cache[sub][type][at] = ['TRUE']
58
- return ['TRUE']
59
- when /#{at}\s+'(.+?)'/
60
- @@attr_cache[sub][type][at] = [$1]
61
- return [$1]
62
- when /#{at}\s+\((.+?)\)/
63
- multi = $1
64
- when /#{at}\s+\(([\w\d\s\.]+)\)/
65
- multi = $1
66
- when /#{at}\s+([\w\d\.]+)/
67
- @@attr_cache[sub][type][at] = [$1]
68
- return [$1]
69
- end
70
- # Split up multiple matches
71
- # if oc then it is sep'd by $
72
- # if attr then bu spaces
73
- if multi.match(/\$/)
74
- @@attr_cache[sub][type][at] = multi.split("$").collect{|attr| attr.strip}
75
- return @@attr_cache[sub][type][at].dup
76
- elsif not multi.empty?
77
- @@attr_cache[sub][type][at] = multi.gsub(/'/, '').split(' ').collect{|attr| attr.strip}
78
- return @@attr_cache[sub][type][at].dup
79
- end
80
- end
81
- @@attr_cache[sub][type][at] = []
82
- return []
83
- end
84
-
85
- # attribute_aliases
86
- #
87
- # Returns all names from the LDAP schema for the
88
- # attribute given.
89
- def attribute_aliases(attr)
90
- attr('attributeTypes', attr, 'NAME')
91
- end # attribute aliases
92
-
93
- # read_only?
94
- #
95
- # Returns true if an attribute is read-only
96
- # NO-USER-MODIFICATION
97
- def read_only?(attr)
98
- result = attr('attributeTypes', attr, 'NO-USER-MODIFICATION')
99
- return true if result[0] == 'TRUE'
100
- return false
101
- end
102
-
103
- # single_value?
104
- #
105
- # Returns true if an attribute can only have one
106
- # value defined
107
- # SINGLE-VALUE
108
- def single_value?(attr)
109
- result = attr('attributeTypes', attr, 'SINGLE-VALUE')
110
- return true if result[0] == 'TRUE'
111
- return false
112
- end
113
-
114
- # binary?
115
- #
116
- # Returns true if the given attribute's syntax
117
- # is X-NOT-HUMAN-READABLE or X-BINARY-TRANSFER-REQUIRED
118
- def binary?(attr)
119
- # Get syntax OID
120
- syntax = attr('attributeTypes', attr, 'SYNTAX')
121
- return false if syntax.empty?
122
-
123
- # This seems to indicate binary
124
- result = attr('ldapSyntaxes', syntax[0], 'X-NOT-HUMAN-READABLE')
125
- return true if result[0] == "TRUE"
126
-
127
- # Get if binary transfer is required (non-binary types)
128
- # Usually these have the above tag
129
- result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED')
130
- return true if result[0] == "TRUE"
131
-
132
- return false
133
- end # binary?
134
-
135
- # binary_required?
136
- #
137
- # Returns true if the value MUST be transferred in binary
138
- def binary_required?(attr)
139
- # Get syntax OID
140
- syntax = attr('attributeTypes', attr, 'SYNTAX')
141
- return false if syntax.empty?
142
-
143
- # Get if binary transfer is required (non-binary types)
144
- # Usually these have the above tag
145
- result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED')
146
- return true if result[0] == "TRUE"
147
-
148
- return false
149
- end # binary_required?
150
-
151
- # class_attributes
152
- #
153
- # Returns an Array of all the valid attributes (but not with full aliases)
154
- # for the given objectClass
155
- def class_attributes(objc)
156
- if @@class_cache.has_key? objc
157
- return @@class_cache[objc]
158
- end
159
-
160
- # Setup the cache
161
- @@class_cache[objc] = {}
162
-
163
- # First get all the current level attributes
164
- @@class_cache[objc] = {:must => attr('objectClasses', objc, 'MUST'),
165
- :may => attr('objectClasses', objc, 'MAY')}
166
-
167
- # Now add all attributes from the parent object (SUPerclasses)
168
- # Hopefully an iterative approach will be pretty speedy
169
- # 1. build complete list of SUPs
170
- # 2. Add attributes from each
171
- sups = attr('objectClasses', objc, 'SUP')
172
- loop do
173
- start_size = sups.size
174
- new_sups = []
175
- sups.each do |sup|
176
- new_sups += attr('objectClasses', sup, 'SUP')
177
- end
178
-
179
- sups += new_sups
180
- sups.uniq!
181
- break if sups.size == start_size
182
- end
183
- sups.each do |sup|
184
- @@class_cache[objc][:must] += attr('objectClasses', sup, 'MUST')
185
- @@class_cache[objc][:may] += attr('objectClasses', sup, 'MAY')
186
- end
187
-
188
- # Clean out the dupes.
189
- @@class_cache[objc][:must].uniq!
190
- @@class_cache[objc][:may].uniq!
191
-
192
- # Return the cached value
193
- return @@class_cache[objc].dup
194
- end
195
-
196
- end # Schema2
197
-
198
- class Conn
199
- def schema2(base = nil, attrs = nil, sec = 0, usec = 0)
200
- attrs ||= [
201
- 'objectClasses',
202
- 'attributeTypes',
203
- 'matchingRules',
204
- 'matchingRuleUse',
205
- 'dITStructureRules',
206
- 'dITContentRules',
207
- 'nameForms',
208
- 'ldapSyntaxes',
209
- ]
210
- base ||= root_dse(['subschemaSubentry'], sec, usec)[0]['subschemaSubentry'][0]
211
- base ||= 'cn=schema'
212
- ent = search2(base, LDAP_SCOPE_BASE, '(objectClass=subschema)',
213
- attrs, false, sec, usec)
214
- return Schema2.new(ent[0])
215
- end
216
- end
217
- end # end LDAP