def bind(options={})
bind_dn = 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
end
options = options.merge(:allow_anonymous => allow_anonymous)
if try_sasl and sasl_bind(bind_dn, options)
@logger.info {_('Bound to %s by SASL as %s') % [target, bind_dn]}
elsif simple_bind(bind_dn, options)
@logger.info {_('Bound to %s by simple as %s') % [target, bind_dn]}
elsif allow_anonymous and bind_as_anonymous(options)
@logger.info {_('Bound to %s as anonymous') % target}
else
message = yield if block_given?
message ||= _('All authentication methods for %s exhausted.') % target
raise AuthenticationError, message
end
bound?
end