lib/active_ldap/adapter/base.rb in activeldap-1.2.0 vs lib/active_ldap/adapter/base.rb in activeldap-1.2.1
- old
+ new
@@ -65,11 +65,11 @@
end
def bind(options={})
@bind_tried = true
- bind_dn = options[:bind_dn] || @bind_dn
+ bind_dn = ensure_dn_string(options[:bind_dn] || @bind_dn)
try_sasl = options.has_key?(:try_sasl) ? options[:try_sasl] : @try_sasl
if options.has_key?(:allow_anonymous)
allow_anonymous = options[:allow_anonymous]
else
allow_anonymous = @allow_anonymous
@@ -162,10 +162,11 @@
callback = Proc.new do |value, block|
value = block.call(value) if block
values << value
end
+ base = ensure_dn_string(base)
begin
operation(options) do
yield(base, scope, filter, attrs, limit, callback)
end
rescue LdapError
@@ -183,10 +184,11 @@
targets = [targets] unless targets.is_a?(Array)
return if targets.empty?
begin
operation(options) do
targets.each do |target|
+ target = ensure_dn_string(target)
begin
yield(target)
rescue LdapError::UnwillingToPerform, LdapError::InsufficientAccess
raise OperationNotPermitted, _("%s: %s") % [$!.message, target]
end
@@ -196,10 +198,11 @@
raise EntryNotFound, _("No such entry: %s") % target
end
end
def add(dn, entries, options={})
+ dn = ensure_dn_string(dn)
begin
operation(options) do
yield(dn, entries)
end
rescue LdapError::NoSuchObject
@@ -216,10 +219,11 @@
raise OperationNotPermitted, _("%s: %s") % [$!.message, dn]
end
end
def modify(dn, entries, options={})
+ dn = ensure_dn_string(dn)
begin
operation(options) do
begin
yield(dn, entries)
rescue LdapError::UnwillingToPerform, LdapError::InsufficientAccess
@@ -232,10 +236,11 @@
raise RequiredAttributeMissed, _("%s: %s") % [$!.message, dn]
end
end
def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
+ dn = ensure_dn_string(dn)
operation(options) do
yield(dn, new_rdn, delete_old_rdn, new_superior)
end
end
@@ -681,9 +686,17 @@
log_entry
else
log_entry = message
log_entry += ": #{info.inspect}" if info
log_entry
+ end
+ end
+
+ def ensure_dn_string(dn)
+ if dn.is_a?(DN)
+ dn.to_s
+ else
+ dn
end
end
end
end
end