# File lib/active_ldap/adapter/base.rb, line 48
      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

        # Rough bind loop:
        # Attempt 1: SASL if available
        # Attempt 2: SIMPLE with credentials if password block
        # Attempt 3: SIMPLE ANONYMOUS if 1 and 2 fail (or pwblock returns '')
        if try_sasl and sasl_bind(bind_dn, options)
          @logger.info {_('Bound by SASL as %s') % bind_dn}
        elsif simple_bind(bind_dn, options)
          @logger.info {_('Bound by simple as %s') % bind_dn}
        elsif allow_anonymous and bind_as_anonymous(options)
          @logger.info {_('Bound as anonymous')}
        else
          message = yield if block_given?
          message ||= _('All authentication methods exhausted.')
          raise AuthenticationError, message
        end

        bound?
      end