dm-ldap-adapter 0.4.4-java → 0.4.5-java

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.
data/History.txt CHANGED
@@ -1,3 +1,24 @@
1
+ version
2
+ =============
3
+
4
+ version 0.4.5
5
+ =============
6
+
7
+ * fixed bug which did count the update result incorrectly
8
+
9
+ * allow to search empty trees and handle DN only queries more useful
10
+
11
+ version 0.4.4
12
+ =============
13
+
14
+ * some less depracted messages
15
+
16
+ * skipped support for jruby-1.5.6 since rubygems bundled with jruby-complete-.1.5.6.jar does not work with latest gems anymore
17
+
18
+ * support for datamapper verions 1.2.0
19
+
20
+ * allow to pass on ldap-adapter(facade) specific parameters with :adapter_options
21
+
1
22
  version 0.4.3
2
23
  =============
3
24
 
@@ -187,8 +187,8 @@ module DataMapper
187
187
  end.size # just return the number of create resources
188
188
  end
189
189
 
190
- def update(attributes, collection)
191
- size = collection.each do |resource|
190
+ def update(attributes, resources)
191
+ resources.select do |resource|
192
192
  #puts "update"
193
193
  #p resource
194
194
  update_resource(resource, attributes)
@@ -298,8 +298,8 @@ module DataMapper
298
298
  end
299
299
 
300
300
  # @see AbstractAdapter#delete
301
- def delete(collection)
302
- collection.each do |resource|
301
+ def delete(resource)
302
+ resource.each do |resource|
303
303
  if resource.model.multivalue_field
304
304
  multivalue_prop = resource.send(:properties).detect do |prop|
305
305
  prop.field.to_sym == resource.model.multivalue_field
@@ -355,7 +355,7 @@ module DataMapper
355
355
  value
356
356
  else
357
357
  prop = props[f.field.to_sym].first
358
- f.primitive == Integer ? prop.to_i : prop.join
358
+ f.primitive == Integer ? prop.to_i : prop.join rescue prop
359
359
  end
360
360
  end
361
361
  props_result << values
@@ -16,6 +16,7 @@ module Ldap
16
16
 
17
17
  # @param config Hash for the ldap connection
18
18
  def initialize(config)
19
+ @ldap_config = config
19
20
  if config.is_a? Hash
20
21
  @ldap = Net::LDAP.new( config )
21
22
  else
@@ -24,10 +25,9 @@ module Ldap
24
25
  end
25
26
 
26
27
  def retrieve_next_id(treebase, key_field)
27
- base = "#{treebase},#{@ldap.base}"
28
28
  id_sym = key_field.downcase.to_sym
29
29
  max = 0
30
- @ldap.search( :base => base,
30
+ @ldap.search( :base => base(treebase),
31
31
  :attributes => [key_field],
32
32
  :return_result => false ) do |entry|
33
33
  n = entry[id_sym].first.to_i
@@ -42,7 +42,6 @@ module Ldap
42
42
  # @param props Hash of the ldap attributes of the new ldap object
43
43
  # @return nil in case of an error or the new id of the created object
44
44
  def create_object(dn_prefix, treebase, key_field, props, silence = false)
45
- base = "#{treebase},#{@ldap.base}"
46
45
  if @ldap.add( :dn => dn(dn_prefix, treebase),
47
46
  :attributes => props) || @ldap.get_operation_result.code.to_s == "0"
48
47
  props[key_field.to_sym]
@@ -66,9 +65,17 @@ module Ldap
66
65
  # @param Array of conditions for the search
67
66
  # @return Array of Hashes with a name/values pair for each attribute
68
67
  def read_objects(treebase, key_fields, conditions, field_names, order_field = nil)
69
- result = []
68
+ searchbase = base(treebase)
70
69
  filter = Conditions2Filter.convert(conditions)
71
- @ldap.search( :base => "#{treebase},#{@ldap.base}",
70
+
71
+ # If there is a :dn in the filter skip everything and look it up
72
+ if dn = conditions.detect { |c| c[1] == "dn" } then
73
+ searchbase = dn[2]
74
+ filter = nil
75
+ end
76
+
77
+ result = []
78
+ @ldap.search( :base => searchbase,
72
79
  :attributes => field_names,
73
80
  :filter => filter ) do |res|
74
81
  mapp = to_map(field_names, res)
@@ -77,7 +84,7 @@ module Ldap
77
84
  # TODO maybe make filter which removes this unless
78
85
  # TODO move this into the ldap_Adapter to make it more general, so that
79
86
  # all field with Integer gets converted, etc
80
- result << mapp if key_fields.detect do |key_field|
87
+ result << mapp if key_fields.all? do |key_field|
81
88
  mapp.keys.detect {|k| k.to_s.downcase == key_field.downcase }
82
89
  end
83
90
  end
@@ -94,6 +101,7 @@ module Ldap
94
101
  :operations => actions ) || @ldap.get_operation_result.code.to_s == "0"
95
102
  true
96
103
  else
104
+ puts caller.join("\n")
97
105
  logger.warn(ldap_error("update",
98
106
  dn(dn_prefix, treebase) + "\n\t#{actions.inspect}"))
99
107
  nil
@@ -118,15 +126,12 @@ module Ldap
118
126
  # @param dn String for identifying the ldap object
119
127
  # @param password String to be used for authenticate to the dn
120
128
  def authenticate(dn, password)
121
- Net::LDAP.new( { :host => @ldap.host,
122
- :port => @ldap.port,
123
- :auth => {
124
- :method => :simple,
125
- :username => dn,
126
- :password => password
127
- },
128
- :base => @ldap.base
129
- } ).bind
129
+ config = @ldap_config.merge(:auth => {
130
+ :method => :simple,
131
+ :username => dn,
132
+ :password => password
133
+ })
134
+ Net::LDAP.new(config).bind
130
135
  end
131
136
 
132
137
  # helper to concat the dn from the various parts
@@ -134,7 +139,15 @@ module Ldap
134
139
  # @param treebase the treebase of the dn or any search
135
140
  # @return the complete dn String
136
141
  def dn(dn_prefix, treebase)
137
- "#{dn_prefix},#{treebase},#{@ldap.base}"
142
+ [ dn_prefix, base(treebase) ].compact.join(",")
143
+ end
144
+
145
+ # helper to concat the base from the various parts
146
+ # @param treebase
147
+ # @param ldap_base the ldap_base defaulting to connection ldap_base
148
+ # @return the complete base String
149
+ def base(treebase = nil, ldap_base = @ldap.base)
150
+ [ treebase, ldap_base ].compact.join(",")
138
151
  end
139
152
 
140
153
  private
@@ -8,6 +8,7 @@ module Ldap
8
8
  attr_reader :base, :host, :port
9
9
 
10
10
  def initialize(config)
11
+ @ldap_config = config
11
12
  super(config[:host], config[:port])
12
13
  @base = config[:base]
13
14
  @port = config[:port]
@@ -41,7 +42,7 @@ module Ldap
41
42
 
42
43
  def retrieve_next_id(treebase, key_field)
43
44
  max = 0
44
- @ldap2.search("#{treebase},#{@ldap2.base}",
45
+ @ldap2.search(base(treebase),
45
46
  LDAP::LDAP_SCOPE_SUBTREE,
46
47
  "(objectclass=*)",
47
48
  [key_field]) do |entry|
@@ -57,7 +58,6 @@ module Ldap
57
58
  # @param props Hash of the ldap attributes of the new ldap object
58
59
  # @return nil in case of an error or the new id of the created object
59
60
  def create_object(dn_prefix, treebase, key_field, props, silence = false)
60
- base = "#{treebase},#{@ldap2.base}"
61
61
  mods = props.collect do |k,v|
62
62
  LDAP.mod(LDAP::LDAP_MOD_ADD, k.to_s, v.is_a?(::Array) ? v : [v.to_s] )
63
63
  end
@@ -90,9 +90,17 @@ module Ldap
90
90
  filter = "(objectclass=*)"
91
91
  end
92
92
 
93
+ searchbase = base(treebase)
94
+
95
+ # If there is a :dn in the filter skip everything and look it up
96
+ if dn = conditions.detect { |c| c[1] == "dn" } then
97
+ searchbase = dn[2]
98
+ filter = nil
99
+ end
100
+
93
101
  result = []
94
102
  begin
95
- @ldap2.search("#{treebase},#{@ldap2.base}",
103
+ @ldap2.search(searchbase,
96
104
  LDAP::LDAP_SCOPE_SUBTREE,
97
105
  filter,
98
106
  field_names, false, 0, 0, order_field) do |res|
@@ -176,7 +184,15 @@ module Ldap
176
184
  # @param treebase the treebase of the dn or any search
177
185
  # @return the complete dn String
178
186
  def dn(dn_prefix, treebase)
179
- "#{dn_prefix},#{treebase},#{@ldap2.base}"
187
+ [ dn_prefix, base(treebase) ].compact.join(",")
188
+ end
189
+
190
+ # helper to concat the base from the various parts
191
+ # @param treebase
192
+ # @param ldap_base the ldap_base defaulting to connection ldap_base
193
+ # @return the complete base String
194
+ def base(treebase = nil, ldap_base = @ldap2.base)
195
+ [ treebase, ldap_base ].compact.join(",")
180
196
  end
181
197
 
182
198
  private
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dm-ldap-adapter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: java
7
7
  authors:
8
8
  - mkristian
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-12-03 00:00:00 Z
14
+ date: 2011-12-14 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: net-ldap