lib/active_ldap/adapter/base.rb in activeldap-1.0.1 vs lib/active_ldap/adapter/base.rb in activeldap-1.0.2
- old
+ new
@@ -38,12 +38,13 @@
runtime
end
def connect(options={})
host = options[:host] || @host
- port = options[:port] || @port
- method = ensure_method(options[:method] || @method)
+ method = options[:method] || @method || :plain
+ port = options[:port] || @port || ensure_port(method)
+ method = ensure_method(method)
@disconnected = false
@connection, @uri, @with_start_tls = yield(host, port, method)
prepare_connection(options)
bind(options)
end
@@ -165,11 +166,15 @@
return if targets.empty?
target = nil
begin
operation(options) do
targets.each do |target|
- yield(target)
+ begin
+ yield(target)
+ rescue LdapError::UnwillingToPerform, LdapError::InsufficientAccess
+ raise OperationNotPermitted, _("%s: %s") % [$!.message, target]
+ end
end
end
rescue LdapError::NoSuchObject
raise EntryNotFound, _("No such entry: %s") % target
end
@@ -196,11 +201,15 @@
end
def modify(dn, entries, options={})
begin
operation(options) do
- yield(dn, entries)
+ begin
+ yield(dn, entries)
+ rescue LdapError::UnwillingToPerform, LdapError::InsufficientAccess
+ raise OperationNotPermitted, _("%s: %s") % [$!.message, target]
+ end
end
rescue LdapError::UndefinedType
raise
rescue LdapError::ObjectClassViolation
raise RequiredAttributeMissed, _("%s: %s") % [$!.message, dn]
@@ -211,18 +220,26 @@
operation(options) do
yield(dn, new_rdn, delete_old_rdn, new_superior)
end
end
- def log_info(name, runtime, info=nil)
+ def log_info(name, runtime_in_seconds, info=nil)
return unless @logger
return unless @logger.debug?
- message = "LDAP: #{name} (#{'%f' % runtime})"
+ message = "LDAP: #{name} (#{'%.1f' % (runtime_in_seconds * 1000)}ms)"
@logger.debug(format_log_entry(message, info))
end
private
+ def ensure_port(method)
+ if method == :ssl
+ URI::LDAPS::DEFAULT_PORT
+ else
+ URI::LDAP::DEFAULT_PORT
+ end
+ end
+
def prepare_connection(options)
end
def operation(options)
retried = false
@@ -386,11 +403,11 @@
if value.is_a?(Array)
case value[0]
when Hash
options = value[0]
value = value[1]
- when "=", "~=", "<=", "=>"
+ when "=", "~=", "<=", ">="
options[:operator] = value[0]
if value.size > 2
value = value[1..-1]
else
value = value[1]
@@ -599,20 +616,16 @@
end
end
def log(name, info=nil)
if block_given?
- if @logger and @logger.debug?
- result = nil
- runtime = Benchmark.realtime {result = yield}
- @runtime += runtime
- log_info(name, runtime, info)
- result
- else
- yield
- end
+ result = nil
+ seconds = Benchmark.realtime {result = yield}
+ @runtime += seconds
+ log_info(name, seconds, info)
+ result
else
- log_info(name, info, 0)
+ log_info(name, 0, info)
nil
end
rescue Exception
log_info("#{name}: FAILED", 0,
(info || {}).merge(:error => $!.class.name,