rom-ldap 0.2.2

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 (104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +251 -0
  3. data/CONTRIBUTING.md +18 -0
  4. data/README.md +172 -0
  5. data/TODO.md +33 -0
  6. data/config/responses.yml +328 -0
  7. data/lib/dry/monitor/ldap/colorizers/default.rb +17 -0
  8. data/lib/dry/monitor/ldap/colorizers/rouge.rb +31 -0
  9. data/lib/dry/monitor/ldap/logger.rb +58 -0
  10. data/lib/rom-ldap.rb +1 -0
  11. data/lib/rom/ldap.rb +22 -0
  12. data/lib/rom/ldap/alias.rb +30 -0
  13. data/lib/rom/ldap/associations.rb +6 -0
  14. data/lib/rom/ldap/associations/core.rb +23 -0
  15. data/lib/rom/ldap/associations/many_to_many.rb +18 -0
  16. data/lib/rom/ldap/associations/many_to_one.rb +22 -0
  17. data/lib/rom/ldap/associations/one_to_many.rb +32 -0
  18. data/lib/rom/ldap/associations/one_to_one.rb +19 -0
  19. data/lib/rom/ldap/associations/self_ref.rb +35 -0
  20. data/lib/rom/ldap/attribute.rb +327 -0
  21. data/lib/rom/ldap/client.rb +185 -0
  22. data/lib/rom/ldap/client/authentication.rb +118 -0
  23. data/lib/rom/ldap/client/operations.rb +233 -0
  24. data/lib/rom/ldap/commands.rb +6 -0
  25. data/lib/rom/ldap/commands/create.rb +41 -0
  26. data/lib/rom/ldap/commands/delete.rb +17 -0
  27. data/lib/rom/ldap/commands/update.rb +35 -0
  28. data/lib/rom/ldap/constants.rb +193 -0
  29. data/lib/rom/ldap/dataset.rb +286 -0
  30. data/lib/rom/ldap/dataset/conversion.rb +62 -0
  31. data/lib/rom/ldap/dataset/dsl.rb +299 -0
  32. data/lib/rom/ldap/dataset/persistence.rb +44 -0
  33. data/lib/rom/ldap/directory.rb +126 -0
  34. data/lib/rom/ldap/directory/capabilities.rb +71 -0
  35. data/lib/rom/ldap/directory/entry.rb +200 -0
  36. data/lib/rom/ldap/directory/env.rb +155 -0
  37. data/lib/rom/ldap/directory/operations.rb +282 -0
  38. data/lib/rom/ldap/directory/password.rb +122 -0
  39. data/lib/rom/ldap/directory/root.rb +187 -0
  40. data/lib/rom/ldap/directory/tokenization.rb +66 -0
  41. data/lib/rom/ldap/directory/transactions.rb +31 -0
  42. data/lib/rom/ldap/directory/vendors/active_directory.rb +129 -0
  43. data/lib/rom/ldap/directory/vendors/apache_ds.rb +27 -0
  44. data/lib/rom/ldap/directory/vendors/e_directory.rb +16 -0
  45. data/lib/rom/ldap/directory/vendors/open_directory.rb +12 -0
  46. data/lib/rom/ldap/directory/vendors/open_dj.rb +25 -0
  47. data/lib/rom/ldap/directory/vendors/open_ldap.rb +35 -0
  48. data/lib/rom/ldap/directory/vendors/three_eight_nine.rb +16 -0
  49. data/lib/rom/ldap/directory/vendors/unknown.rb +22 -0
  50. data/lib/rom/ldap/dsl.rb +76 -0
  51. data/lib/rom/ldap/errors.rb +47 -0
  52. data/lib/rom/ldap/expression.rb +77 -0
  53. data/lib/rom/ldap/expression_encoder.rb +174 -0
  54. data/lib/rom/ldap/extensions.rb +50 -0
  55. data/lib/rom/ldap/extensions/active_support_notifications.rb +26 -0
  56. data/lib/rom/ldap/extensions/compatibility.rb +11 -0
  57. data/lib/rom/ldap/extensions/dsml.rb +165 -0
  58. data/lib/rom/ldap/extensions/msgpack.rb +23 -0
  59. data/lib/rom/ldap/extensions/optimised_json.rb +25 -0
  60. data/lib/rom/ldap/extensions/rails_log_subscriber.rb +38 -0
  61. data/lib/rom/ldap/formatter.rb +26 -0
  62. data/lib/rom/ldap/functions.rb +207 -0
  63. data/lib/rom/ldap/gateway.rb +145 -0
  64. data/lib/rom/ldap/ldif.rb +74 -0
  65. data/lib/rom/ldap/ldif/exporter.rb +77 -0
  66. data/lib/rom/ldap/ldif/importer.rb +95 -0
  67. data/lib/rom/ldap/mapper_compiler.rb +19 -0
  68. data/lib/rom/ldap/matchers.rb +69 -0
  69. data/lib/rom/ldap/message_queue.rb +7 -0
  70. data/lib/rom/ldap/oid.rb +101 -0
  71. data/lib/rom/ldap/parsers/abstract_syntax.rb +91 -0
  72. data/lib/rom/ldap/parsers/attribute.rb +290 -0
  73. data/lib/rom/ldap/parsers/filter_syntax.rb +133 -0
  74. data/lib/rom/ldap/pdu.rb +285 -0
  75. data/lib/rom/ldap/plugin/pagination.rb +145 -0
  76. data/lib/rom/ldap/plugins.rb +7 -0
  77. data/lib/rom/ldap/projection_dsl.rb +38 -0
  78. data/lib/rom/ldap/relation.rb +135 -0
  79. data/lib/rom/ldap/relation/exporting.rb +72 -0
  80. data/lib/rom/ldap/relation/reading.rb +461 -0
  81. data/lib/rom/ldap/relation/writing.rb +64 -0
  82. data/lib/rom/ldap/responses.rb +17 -0
  83. data/lib/rom/ldap/restriction_dsl.rb +45 -0
  84. data/lib/rom/ldap/schema.rb +123 -0
  85. data/lib/rom/ldap/schema/attributes_inferrer.rb +59 -0
  86. data/lib/rom/ldap/schema/dsl.rb +13 -0
  87. data/lib/rom/ldap/schema/inferrer.rb +50 -0
  88. data/lib/rom/ldap/schema/type_builder.rb +133 -0
  89. data/lib/rom/ldap/scope.rb +19 -0
  90. data/lib/rom/ldap/search_request.rb +249 -0
  91. data/lib/rom/ldap/socket.rb +210 -0
  92. data/lib/rom/ldap/tasks/ldap.rake +103 -0
  93. data/lib/rom/ldap/tasks/ldif.rake +80 -0
  94. data/lib/rom/ldap/transaction.rb +29 -0
  95. data/lib/rom/ldap/type_map.rb +88 -0
  96. data/lib/rom/ldap/types.rb +158 -0
  97. data/lib/rom/ldap/version.rb +17 -0
  98. data/lib/rom/plugins/relation/ldap/active_directory.rb +182 -0
  99. data/lib/rom/plugins/relation/ldap/auto_restrictions.rb +69 -0
  100. data/lib/rom/plugins/relation/ldap/e_directory.rb +27 -0
  101. data/lib/rom/plugins/relation/ldap/instrumentation.rb +35 -0
  102. data/lib/rouge/lexers/ldap.rb +72 -0
  103. data/lib/rouge/themes/ldap.rb +49 -0
  104. metadata +231 -0
data/lib/rom-ldap.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rom/ldap'
data/lib/rom/ldap.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/core'
4
+ require 'rom/configuration_dsl'
5
+
6
+ require 'rom/ldap/version'
7
+ require 'rom/ldap/constants'
8
+ require 'rom/ldap/formatter'
9
+ require 'rom/ldap/errors'
10
+ require 'rom/ldap/plugins'
11
+ require 'rom/ldap/relation'
12
+ require 'rom/ldap/mapper_compiler'
13
+ require 'rom/ldap/associations'
14
+ require 'rom/ldap/gateway'
15
+ require 'rom/ldap/commands'
16
+ require 'rom/ldap/extensions'
17
+
18
+ if defined?(Rails)
19
+ ROM::LDAP.load_extensions(:active_support_notifications, :rails_log_subscriber)
20
+ end
21
+
22
+ ROM.register_adapter :ldap, ROM::LDAP
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ROM
4
+ module LDAP
5
+ #
6
+ # Alias Dereferencing [RFC4512]
7
+ #
8
+ # An indicator as to whether or not alias entries are to be dereferenced.
9
+ #
10
+ # Dereferencing aliases can cause poor search performance for some LDAP directories.
11
+ # Control the extent to which alias dereferencing occurs when searching the directory.
12
+
13
+ # Do not dereference aliases in searching or in locating the base object of the search.
14
+ DEREF_NEVER = 0 # "never"
15
+
16
+ # While searching subordinates of the base object, dereference any alias within the search scope.
17
+ DEREF_SEARCH = 1 # "searching"
18
+
19
+ # Dereference aliases in locating the base object of the search, but not
20
+ # when searching subordinates of the base object.
21
+ DEREF_FIND = 2 # "finding"
22
+
23
+ # Always dereference aliases both in searching and in locating the base object of the search.
24
+ # is the default behavior.
25
+ DEREF_ALWAYS = 3 # "always"
26
+
27
+ # Array of all dereferencing modes
28
+ DEREF_ALL = [DEREF_NEVER, DEREF_SEARCH, DEREF_FIND, DEREF_ALWAYS].freeze
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/ldap/associations/many_to_many'
4
+ require 'rom/ldap/associations/many_to_one'
5
+ require 'rom/ldap/associations/one_to_many'
6
+ require 'rom/ldap/associations/one_to_one'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ROM
4
+ module LDAP
5
+ module Associations
6
+ # Core LDAP association API
7
+ #
8
+ # @api private
9
+ module Core
10
+ # Used when relation association override is not true
11
+ #
12
+ # @see https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation.rb#L319
13
+ #
14
+ # @api private
15
+ def preload(target, loaded)
16
+ source_key, target_key = join_keys.flatten(1)
17
+ target_pks = loaded.pluck(source_key.key).flatten.uniq
18
+ target.where(target_key.key => target_pks)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/associations/many_to_many'
4
+
5
+ module ROM
6
+ module LDAP
7
+ module Associations
8
+ class ManyToMany < ROM::Associations::ManyToMany
9
+
10
+ # @api public
11
+ def call(*)
12
+ # binding.pry
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/associations/many_to_one'
4
+
5
+ module ROM
6
+ module LDAP
7
+ module Associations
8
+ class ManyToOne < ROM::Associations::ManyToOne
9
+
10
+ # @api public
11
+ def call(*)
12
+ # binding.pry
13
+ end
14
+
15
+ def join(source = self.source, target = self.target)
16
+ # binding.pry
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/associations/one_to_many'
4
+
5
+ require 'rom/ldap/associations/core'
6
+ require 'rom/ldap/associations/self_ref'
7
+
8
+ module ROM
9
+ module LDAP
10
+ module Associations
11
+ class OneToMany < ROM::Associations::OneToMany
12
+
13
+ include Associations::Core
14
+ include Associations::SelfRef
15
+
16
+ # @api public
17
+ def call(target: self.target)
18
+ schema = target.schema
19
+ target_fks = target.list(foreign_key).uniq
20
+ relation = source.where(source.primary_key => target_fks)
21
+
22
+ if view
23
+ apply_view(schema, relation)
24
+ else
25
+ schema.call(relation)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/ldap/associations/one_to_many'
4
+
5
+ module ROM
6
+ module LDAP
7
+ module Associations
8
+ class OneToOne < OneToMany
9
+
10
+ # @api public
11
+ def call(*)
12
+ # binding.pry
13
+ super
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ROM
4
+ module LDAP
5
+ module Associations
6
+ module SelfRef
7
+ def self.included(klass)
8
+ super
9
+ klass.memoize :join_keys, :source_attr, :target_attr
10
+ end
11
+
12
+ # @return [Hash]
13
+ #
14
+ # @api public
15
+ def join_keys
16
+ { source_attr => target_attr }
17
+ end
18
+
19
+ # @return [ROM::LDAP::Attribute]
20
+ #
21
+ # @api public
22
+ def source_attr
23
+ source[source_key]
24
+ end
25
+
26
+ # @return [ROM::LDAP::Attribute]
27
+ #
28
+ # @api public
29
+ def target_attr
30
+ target[target_key]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,327 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/core/cache'
4
+ require 'rom/attribute'
5
+
6
+ module ROM
7
+ module LDAP
8
+ # Extended schema attributes tailored for LDAP directories
9
+ #
10
+ # @api public
11
+ class Attribute < ROM::Attribute
12
+
13
+ extend Dry::Core::Cache
14
+
15
+ # @param args [Mixed]
16
+ #
17
+ # @return [ROM::LDAP::Attribute]
18
+ #
19
+ # @api public
20
+ def self.[](*args)
21
+ fetch_or_store(args) { new(*args) }
22
+ end
23
+
24
+ # Attribute definition identifies this is not a directory internal attribute
25
+ # and values can be altered.
26
+ #
27
+ # @return [Boolean]
28
+ #
29
+ # @api public
30
+ def editable?
31
+ meta[:editable].equal?(true)
32
+ end
33
+
34
+ # Attribute definition identifies this attribute can not have multiple values.
35
+ #
36
+ # @return [Boolean]
37
+ #
38
+ # @api public
39
+ def single?
40
+ meta[:single].equal?(true)
41
+ end
42
+
43
+ # OID permits multiple values?
44
+ #
45
+ # @return [Boolean]
46
+ #
47
+ # @api public
48
+ def multiple?
49
+ meta[:single].equal?(false)
50
+ end
51
+
52
+ # Return a new attribute marked as joined
53
+ #
54
+ # Whenever you join two schemas, the right schema's attribute
55
+ # will be marked as joined using this method
56
+ #
57
+ # @return [LDAP::Attribute] Original attribute marked as joined
58
+ #
59
+ # @api public
60
+ def joined
61
+ meta(joined: true)
62
+ end
63
+
64
+ # Return if an attribute was used in a join
65
+ #
66
+ # @example
67
+ # schema = users.schema.join(tasks.schema)
68
+ #
69
+ # schema[:id, :tasks].joined?
70
+ # # => true
71
+ #
72
+ # @return [Boolean]
73
+ #
74
+ # @api public
75
+ def joined?
76
+ meta[:joined].equal?(true)
77
+ end
78
+
79
+ # Return a new attribute marked as a FK
80
+ #
81
+ # @return [LDAP::Attribute]
82
+ #
83
+ # @api public
84
+ def foreign_key
85
+ meta(foreign_key: true)
86
+ end
87
+
88
+ # Attribute Numeric Object Identifier
89
+ #
90
+ # @return [String]
91
+ #
92
+ # @api public
93
+ def oid
94
+ meta[:oid]
95
+ end
96
+
97
+ # Raw LDAP Attribute Definition.
98
+ #
99
+ # @return [String]
100
+ #
101
+ # @api public
102
+ def definition
103
+ meta[:definition]
104
+ end
105
+
106
+ # Attribute's syntax Numeric Object Identifier
107
+ #
108
+ # @return [String]
109
+ #
110
+ # @api public
111
+ def syntax
112
+ meta[:syntax]
113
+ end
114
+
115
+ # OID description
116
+ #
117
+ # @return [String]
118
+ #
119
+ # @api public
120
+ def description
121
+ meta[:description]
122
+ end
123
+
124
+ # Convert to string for ldap query using original name
125
+ # The canonical attribute name defined in RFC4512.
126
+ #
127
+ # @return [String]
128
+ #
129
+ # @api public
130
+ def to_s
131
+ meta[:canonical] || name.to_s
132
+ end
133
+ alias_method :original_name, :to_s
134
+
135
+ # @return [Boolean]
136
+ #
137
+ # @api public
138
+ def indexed?
139
+ meta[:index].equal?(true)
140
+ end
141
+
142
+ # Returns a new attribute marked as indexed
143
+ #
144
+ # @return [LDAP::Attribute]
145
+ #
146
+ # @api public
147
+ def indexed
148
+ meta(index: true)
149
+ end
150
+
151
+ # Return a new attribute in its canonical form
152
+ #
153
+ # @see Dataset#export
154
+ #
155
+ # @return [LDAP::Attribute]
156
+ #
157
+ # @api public
158
+ def canonical
159
+ if aliased?
160
+ meta(alias: nil)
161
+ else
162
+ self
163
+ end
164
+ end
165
+
166
+ # @example
167
+ # users.where { given_name.exists }
168
+ # users.where { ~given_name }
169
+ #
170
+ # @return [Array]
171
+ #
172
+ # @api public
173
+ def exists
174
+ [:op_eql, name, :wildcard]
175
+ end
176
+ alias_method :~@, :exists
177
+
178
+ # @example
179
+ # users.where { !given_name }
180
+ #
181
+ # @return [Array]
182
+ #
183
+ # @api public
184
+ def !@
185
+ [:con_not, exists]
186
+ end
187
+
188
+ # @param value [Mixed]
189
+ #
190
+ # @example
191
+ # users.where { id.is(1) }
192
+ # users.where { id == 1 }
193
+ #
194
+ # users.where(users[:id].is(1))
195
+ #
196
+ # @return [Array]
197
+ #
198
+ # @api public
199
+ def is(value)
200
+ [:op_eql, name, value]
201
+ end
202
+ alias_method :==, :is
203
+
204
+ # @param value [Mixed]
205
+ #
206
+ # @example
207
+ # users.where { id.not(1) }
208
+ # users.where { id != 1 }
209
+ #
210
+ # @return [Array]
211
+ #
212
+ # @api public
213
+ def not(value)
214
+ [:con_not, is(value)]
215
+ end
216
+ alias_method :!=, :not
217
+
218
+ # @param value [Mixed]
219
+ #
220
+ # @example
221
+ # users.where { uid_number.gt(101) }
222
+ # users.where { uid_number > 101 }
223
+ #
224
+ # @return [Array]
225
+ #
226
+ # @api public
227
+ def gt(value)
228
+ [:con_not, lte(value)]
229
+ end
230
+ alias_method :>, :gt
231
+
232
+ # @param value [Mixed]
233
+ #
234
+ # @example
235
+ # users.where { uid_number.lt(101) }
236
+ # users.where { uid_number < 101 }
237
+ #
238
+ # @return [Array]
239
+ #
240
+ # @api public
241
+ def lt(value)
242
+ [:con_not, gte(value)]
243
+ end
244
+ alias_method :<, :lt
245
+
246
+ # @param value [Mixed]
247
+ #
248
+ # @example
249
+ # users.where { uid_number.gte(101) }
250
+ # users.where { uid_number >= 101 }
251
+ #
252
+ # @return [Array]
253
+ #
254
+ # @api public
255
+ def gte(value)
256
+ [:op_gte, name, value]
257
+ end
258
+ alias_method :>=, :gte
259
+
260
+ # @param value [Mixed]
261
+ #
262
+ # @example
263
+ # users.where { uid_number.lte(101) }
264
+ # users.where { uid_number <= 101 }
265
+ #
266
+ # @return [Array]
267
+ #
268
+ # @api public
269
+ def lte(value)
270
+ [:op_lte, name, value]
271
+ end
272
+ alias_method :<=, :lte
273
+
274
+ # @param value [Mixed]
275
+ #
276
+ # @example
277
+ # users.where { given_name.like('peter') }
278
+ # users.where { given_name =~ 'peter' }
279
+ #
280
+ # @return [Array]
281
+ #
282
+ # @api public
283
+ def like(value)
284
+ [:op_prx, name, value]
285
+ end
286
+ alias_method :=~, :like
287
+
288
+ # @param value [Mixed]
289
+ #
290
+ # @example
291
+ # users.where { given_name.not_like('peter') }
292
+ # users.where { given_name !~ 'peter' }
293
+ #
294
+ # @return [Array]
295
+ #
296
+ # @api public
297
+ def not_like(value)
298
+ [:con_not, like(value)]
299
+ end
300
+ alias_method :!~, :not_like
301
+
302
+ # @param value [Mixed]
303
+ #
304
+ # @see https://ldapwiki.com/wiki/ExtensibleMatch
305
+ #
306
+ # @return [Array]
307
+ #
308
+ # @api public
309
+ def extensible(value)
310
+ [:op_ext, name, value]
311
+ end
312
+
313
+ # @param value [Mixed]
314
+ #
315
+ # @return [Array]
316
+ #
317
+ # @api public
318
+ def bitwise(value)
319
+ [:op_eql, name, value]
320
+ end
321
+ alias_method :===, :bitwise
322
+
323
+ memoize :oid, :syntax, :joined, :canonical, :to_s
324
+
325
+ end
326
+ end
327
+ end