### Home Classes Methods

### In Files

- lib/active_ldap/adapter/ldap.rb

### Parent

ActiveLdap::Adapter::Base

### Namespace

- MODULE ActiveLdap::Adapter::Ldap::Method

### Methods

- #add
- #bind
- #bind_as_anonymous
- #connect
- #delete
- #ensure_method
- #ensure_mod_type
- #ensure_scope
- #execute
- #modify
- #modify_rdn
- #parse_entries
- #prepare_connection
- #sasl_bind
- #scope_name
- #search
- #simple_bind
- #unbind

### Files

- USAGE

### Class/Module Index

Quicksearch

- ActiveLdap
- ActiveLdap::ActionController
- ActiveLdap::ActionController::LdapBenchmarking
- ActiveLdap::Acts
- ActiveLdap::Acts::Tree
- ActiveLdap::Acts::Tree::ClassMethods
- ActiveLdap::Adapter
- ActiveLdap::Adapter::Base
- ActiveLdap::Adapter::Jndi
- ActiveLdap::Adapter::JndiConnection
- ActiveLdap::Adapter::JndiConnection::ModifyRecord
- ActiveLdap::Adapter::JndiConnection::Scope
- ActiveLdap::Adapter::Ldap
- ActiveLdap::Adapter::Ldap::Method
- ActiveLdap::Adapter::Ldap::Method::Base
- ActiveLdap::Adapter::Ldap::Method::Plain
- ActiveLdap::Adapter::Ldap::Method::SSL
- ActiveLdap::Adapter::Ldap::Method::TLS
- ActiveLdap::Adapter::NetLdap
- ActiveLdap::Association
- ActiveLdap::Association::BelongsTo
- ActiveLdap::Association::BelongsToMany
- ActiveLdap::Association::Children
- ActiveLdap::Association::Collection
- ActiveLdap::Association::HasMany
- ActiveLdap::Association::HasManyUtils
- ActiveLdap::Association::HasManyWrap
- ActiveLdap::Association::Proxy
- ActiveLdap::Associations
- ActiveLdap::Associations::ClassMethods
- ActiveLdap::AttributeMethods
- ActiveLdap::AttributeMethods::BeforeTypeCast
- ActiveLdap::AttributeMethods::Dirty
- ActiveLdap::AttributeMethods::Query
- ActiveLdap::AttributeMethods::Read
- ActiveLdap::AttributeMethods::Write
- ActiveLdap::Attributes
- ActiveLdap::Attributes::ClassMethods
- ActiveLdap::Attributes::Normalizable
- ActiveLdap::Callbacks
- ActiveLdap::Callbacks::ClassMethods
- ActiveLdap::Command
- ActiveLdap::Compatible
- ActiveLdap::Configuration
- ActiveLdap::Configuration::ClassMethods
- ActiveLdap::Connection
- ActiveLdap::Connection::ClassMethods
- ActiveLdap::DN
- ActiveLdap::DistinguishedName
- ActiveLdap::DistinguishedName::Parser
- ActiveLdap::Entry
- ActiveLdap::EntryAttribute
- ActiveLdap::Escape
- ActiveLdap::Generators
- ActiveLdap::Generators::ModelGenerator
- ActiveLdap::Generators::ScaffoldGenerator
- ActiveLdap::GetText
- ActiveLdap::GetText::Parser
- ActiveLdap::GetTextSupport
- ActiveLdap::Helper
- ActiveLdap::HumanReadable
- ActiveLdap::HumanReadable::ClassMethods
- ActiveLdap::LDIF
- ActiveLdap::LdapError
- ActiveLdap::Ldif
- ActiveLdap::Ldif::AddRecord
- ActiveLdap::Ldif::Attribute
- ActiveLdap::Ldif::Attributes
- ActiveLdap::Ldif::ChangeRecord
- ActiveLdap::Ldif::ChangeRecord::Control
- ActiveLdap::Ldif::ContentRecord
- ActiveLdap::Ldif::DeleteRecord
- ActiveLdap::Ldif::ModifyDNRecord
- ActiveLdap::Ldif::ModifyNameRecord
- ActiveLdap::Ldif::ModifyRDNRecord
- ActiveLdap::Ldif::ModifyRecord
- ActiveLdap::Ldif::ModifyRecord::AddOperation
- ActiveLdap::Ldif::ModifyRecord::DeleteOperation
- ActiveLdap::Ldif::ModifyRecord::Operation
- ActiveLdap::Ldif::ModifyRecord::ReplaceOperation
- ActiveLdap::Ldif::Parser
- ActiveLdap::Ldif::Record
- ActiveLdap::Ldif::Scanner
- ActiveLdap::LogSubscriber
- ActiveLdap::ObjectClass
- ActiveLdap::ObjectClass::ClassMethods
- ActiveLdap::Operations
- ActiveLdap::Operations::ClassOnlyDelete
- ActiveLdap::Operations::ClassOnlyUpdate
- ActiveLdap::Operations::Common
- ActiveLdap::Operations::Delete
- ActiveLdap::Operations::Find
- ActiveLdap::Operations::LDIF
- ActiveLdap::Operations::LDIF::AddRecordLoadable
- ActiveLdap::Operations::LDIF::ContentRecordLoadable
- ActiveLdap::Operations::LDIF::DeleteRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyNameRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::AddOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::DeleteOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::ReplaceOperationModifiable
- ActiveLdap::Operations::Update
- ActiveLdap::Persistence
- ActiveLdap::Populate
- ActiveLdap::Railtie
- ActiveLdap::Railties
- ActiveLdap::Railties::ControllerRuntime
- ActiveLdap::Railties::ControllerRuntime::ClassMethods
- ActiveLdap::Schema
- ActiveLdap::Schema::Attribute
- ActiveLdap::Schema::Entry
- ActiveLdap::Schema::ObjectClass
- ActiveLdap::Schema::Syntax
- ActiveLdap::Schema::Syntaxes
- ActiveLdap::Schema::Syntaxes::Base
- ActiveLdap::Schema::Syntaxes::BitString
- ActiveLdap::Schema::Syntaxes::Boolean
- ActiveLdap::Schema::Syntaxes::CountryString
- ActiveLdap::Schema::Syntaxes::DirectoryString
- ActiveLdap::Schema::Syntaxes::DistinguishedName
- ActiveLdap::Schema::Syntaxes::GeneralizedTime
- ActiveLdap::Schema::Syntaxes::Integer
- ActiveLdap::Schema::Syntaxes::JPEG
- ActiveLdap::Schema::Syntaxes::NameAndOptionalUID
- ActiveLdap::Schema::Syntaxes::NumericString
- ActiveLdap::Schema::Syntaxes::OID
- ActiveLdap::Schema::Syntaxes::ObjectSecurityDescriptor
- ActiveLdap::Schema::Syntaxes::OctetString
- ActiveLdap::Schema::Syntaxes::OtherMailbox
- ActiveLdap::Schema::Syntaxes::PostalAddress
- ActiveLdap::Schema::Syntaxes::PrintableString
- ActiveLdap::Schema::Syntaxes::TelephoneNumber
- ActiveLdap::UserPassword
- ActiveLdap::UserPassword::Salt
- ActiveLdap::Validations
- ActiveLdap::XML
- ActiveLdap::Xml
- ActiveLdap::Xml::Serializer
- LDAP
- LDAP::Conn
- LDAP::Mod
- Net
- Net::LDAP
- Net::LDAP::Entry
- ActionView
- ActionView::Base
- URI
- URI::LDAPS
- Object
- Timeout

No matching classes.

# ActiveLdap::Adapter::Ldap

### Public Instance Methods

add(dn, entries, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 125
    def add(dn, entries, options={})
      super do |_dn, _entries|
        controls = options[:controls]
        attributes = parse_entries(_entries)
        info = {:dn => _dn, :attributes => _entries}
        if controls
          info.merge!(:name => :add, :controls => controls)
          execute(:add_ext, info, _dn, attributes, controls, [])
        else
          execute(:add, info, _dn, attributes)
        end
      end
    end

bind(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 69
    def bind(options={})
      super do
        @connection.error_message
      end
    end

bind_as_anonymous(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 75
    def bind_as_anonymous(options={})
      super do
        execute(:bind, :name => "bind: anonymous")
        true
      end
    end

connect(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 53
    def connect(options={})
      super do |host, port, method|
        uri = construct_uri(host, port, method.ssl?)
        with_start_tls = method.start_tls?
        info = {:uri => uri, :with_start_tls => with_start_tls}
        [log("connect", info) {method.connect(host, port)},
         uri, with_start_tls]
      end
    end

delete(targets, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 111
    def delete(targets, options={})
      super do |target|
        controls = options[:controls]
        info = {:dn => target}
        if controls
          info.merge!(:name => :delete, :controls => controls)
          execute(:delete_ext, info,
                  target, controls, [])
        else
          execute(:delete, info, target)
        end
      end
    end

modify(dn, entries, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 139
    def modify(dn, entries, options={})
      super do |_dn, _entries|
        controls = options[:controls]
        attributes = parse_entries(_entries)
        info = {:dn => _dn, :attributes => _entries}
        if controls
          info.merge!(:name => :modify, :controls => controls)
          execute(:modify_ext, info, _dn, attributes, controls, [])
        else
          execute(:modify, info, _dn, attributes)
        end
      end
    end

modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 153
    def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
      super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
        rename_available_p = @connection.respond_to?(:rename)
        if _new_superior and not rename_available_p
          raise NotImplemented.new(_("modify RDN with new superior"))
        end
        info = {
          :name => "modify: RDN",
          :dn => _dn,
          :new_rdn => _new_rdn,
          :new_superior => _new_superior,
          :delete_old_rdn => _delete_old_rdn
        }
        if rename_available_p
          execute(:rename, info,
                  _dn, _new_rdn, _new_superior, _delete_old_rdn, [], [])
        else
          execute(:modrdn, info, _dn, _new_rdn, _delete_old_rdn)
        end
      end
    end

search(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 82
    def search(options={})
      super(options) do |base, scope, filter, attrs, limit|
        begin
          info = {
            :base => base, :scope => scope_name(scope),
            :filter => filter, :attributes => attrs, :limit => limit,
          }
          execute(:search_with_limit,
                  info, base, scope, filter, attrs, limit) do |entry|
            attributes = {}
            entry.attrs.each do |attr|
              value = entry.vals(attr)
              attributes[attr] = value if value
            end
            yield([entry.dn, attributes])
          end
        rescue RuntimeError
          if $!.message == "no result returned by search"
            @logger.debug do
              args = [filter, attrs.inspect]
              _("No matches: filter: %s: attributes: %s") % args
            end
          else
            raise
          end
        end
      end
    end

unbind(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 63
    def unbind(options={})
      super do
        execute(:unbind)
      end
    end

### Private Instance Methods

ensure_method(method) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 192
    def ensure_method(method)
      normalized_method = method.to_s.downcase
      Method.constants.each do |name|
        if normalized_method == name.to_s.downcase
          return Method.const_get(name).new
        end
      end

      available_methods = Method.constants.collect do |name|
        name.downcase.to_sym.inspect
      end.join(", ")
      format = _("%s is not one of the available connect methods: %s")
      raise ConfigurationError, format % [method.inspect, available_methods]
    end

ensure_mod_type(type) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 282
    def ensure_mod_type(type)
      case type
      when :replace, :add, :delete
        LDAP.const_get("LDAP_MOD_#{type.to_s.upcase}")
      else
        raise ArgumentError, _("unknown type: %s") % type
      end
    end

ensure_scope(scope) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 207
    def ensure_scope(scope)
      scope_map = {
        :base => LDAP::LDAP_SCOPE_BASE,
        :sub => LDAP::LDAP_SCOPE_SUBTREE,
        :one => LDAP::LDAP_SCOPE_ONELEVEL,
      }
      value = scope_map[scope || :sub]
      if value.nil?
        available_scopes = scope_map.keys.inspect
        format = _("%s is not one of the available LDAP scope: %s")
        raise ArgumentError, format % [scope.inspect, available_scopes]
      end
      value
    end

execute(method, info=nil, *args, &block) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 182
    def execute(method, info=nil, *args, &block)
      begin
        name = (info || {}).delete(:name) || method
        log(name, info) {@connection.send(method, *args, &block)}
      rescue LDAP::ResultError
        @connection.assert_error_code
        raise $!.message
      end
    end

parse_entries(entries) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 265
    def parse_entries(entries)
      result = []
      entries.each do |type, key, attributes|
        mod_type = ensure_mod_type(type)
        binary = schema.attribute(key).binary?
        mod_type |= LDAP::LDAP_MOD_BVALUES if binary
        attributes.each do |name, values|
          additional_mod_type = 0
          if values.any? {|value| Ldif::Attribute.binary_value?(value)}
            additional_mod_type |= LDAP::LDAP_MOD_BVALUES
          end
          result << LDAP.mod(mod_type | additional_mod_type, name, values)
        end
      end
      result
    end

prepare_connection(options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 176
    def prepare_connection(options={})
      operation(options) do
        @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
      end
    end

sasl_bind(bind_dn, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 230
    def sasl_bind(bind_dn, options={})
      super do |_bind_dn, mechanism, quiet|
        begin
          _bind_dn ||= ''
          sasl_quiet = @connection.sasl_quiet
          @connection.sasl_quiet = quiet unless quiet.nil?
          args = [_bind_dn, mechanism]
          credential = nil
          if need_credential_sasl_mechanism?(mechanism)
            credential = password(_bind_dn, options)
          end
          if @sasl_options
            credential ||= ""
            args.concat([credential, nil, nil, @sasl_options])
          else
            args << credential if credential
          end
          info = {
            :name => "bind: SASL", :dn => _bind_dn, :mechanism => mechanism
          }
          execute(:sasl_bind, info, *args)
          true
        ensure
          @connection.sasl_quiet = sasl_quiet
        end
      end
    end

scope_name(scope) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 222
    def scope_name(scope)
      {
        LDAP::LDAP_SCOPE_BASE => :base,
        LDAP::LDAP_SCOPE_SUBTREE => :sub,
        LDAP::LDAP_SCOPE_ONELEVEL => :one,
      }[scope]
    end

simple_bind(bind_dn, options={}) click to toggle source

    # File lib/active_ldap/adapter/ldap.rb, line 258
    def simple_bind(bind_dn, options={})
      super do |_bind_dn, password|
        execute(:bind, {:dn => _bind_dn}, _bind_dn, password)
        true
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.