lib/ldap/net_ldap_facade.rb in dm-ldap-adapter-0.4.1 vs lib/ldap/net_ldap_facade.rb in dm-ldap-adapter-0.4.2
- old
+ new
@@ -42,11 +42,11 @@
# @return nil in case of an error or the new id of the created object
def create_object(dn_prefix, treebase, key_field, props, silence = false)
base = "#{treebase},#{@ldap.base}"
if @ldap.add( :dn => dn(dn_prefix, treebase),
:attributes => props) || @ldap.get_operation_result.code.to_s == "0"
- props[key_field.downcase.to_sym]
+ props[key_field.to_sym]
else
unless silence
msg = ldap_error("create",
dn(dn_prefix, treebase)) + "\n\t#{props.inspect}"
# TODO maybe raise always an error
@@ -68,17 +68,18 @@
result = []
filter = Conditions2Filter.convert(conditions)
@ldap.search( :base => "#{treebase},#{@ldap.base}",
:attributes => field_names,
:filter => filter ) do |res|
- map = to_map(res)
+ mapp = to_map(field_names, res)
+
#puts map[key_field.to_sym]
# TODO maybe make filter which removes this unless
# TODO move this into the ldap_Adapter to make it more general, so that
# all field with Integer gets converted, etc
- result << map if key_fields.detect do |key_field|
- map.member? key_field.to_sym
+ result << mapp if key_fields.detect do |key_field|
+ mapp.keys.detect {|k| k.to_s.downcase == key_field.downcase }
end
end
result
end
@@ -138,16 +139,22 @@
private
# helper to extract the Hash from the ldap search result
# @param Entry from the ldap_search
# @return Hash with name/value pairs of the entry
- def to_map(entry)
+ def to_map(field_names, entry)
+ fields = {:dn => :dn}
+ field_names.each { |f| fields[f.downcase.to_sym] = f.to_sym }
def entry.map
@myhash
end
- entry.map
+ result = {}
+ entry.map.each do |k,v|
+ result[fields[k]] = v
+ end
+ result
end
-
+
def ldap_error(method, dn)
"#{method} error: (#{@ldap.get_operation_result.code}) #{@ldap.get_operation_result.message}\n\tDN: #{dn}"
end
end
end