### Home Classes Methods

### In Files

- lib/active_ldap/adapter/jndi.rb

### Parent

ActiveLdap::Adapter::Base

### Methods

- #add
- #bind_as_anonymous
- #connect
- #connecting?
- #delete
- #ensure_method
- #ensure_mod_type
- #ensure_scope
- #execute
- #modify
- #modify_rdn
- #parse_entries
- #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::Jndi

### Constants

METHOD

### Public Instance Methods

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

    # File lib/active_ldap/adapter/jndi.rb, line 64
    def add(dn, entries, options={})
      super do |_dn, _entries|
        info = {:dn => _dn, :attributes => _entries}
        execute(:add, info, _dn, parse_entries(_entries))
      end
    end

bind_as_anonymous(options={}) click to toggle source

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

connect(options={}) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 21
    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) {JndiConnection.new(host, port, method, @timeout)},
         uri, with_start_tls]
      end
    end

connecting?() click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 31
    def connecting?
      super and @connection.bound?
    end

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

    # File lib/active_ldap/adapter/jndi.rb, line 58
    def delete(targets, options={})
      super do |target|
        execute(:delete, {:dn => target}, target)
      end
    end

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

    # File lib/active_ldap/adapter/jndi.rb, line 71
    def modify(dn, entries, options={})
      super do |_dn, _entries|
        info = {:dn => _dn, :attributes => _entries}
        execute(:modify, info, _dn, parse_entries(_entries))
      end
    end

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

    # File lib/active_ldap/adapter/jndi.rb, line 78
    def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
      super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
        info = {
          :name => "modify: RDN",
          :dn => _dn,
          :new_rdn => _new_rdn,
          :new_superior => _new_superior,
          :delete_old_rdn => _delete_old_rdn
        }
        _new_rdn = "#{_new_rdn},#{_new_superior}" if _new_superior
        execute(:modify_rdn, info, _dn, _new_rdn, _delete_old_rdn)
      end
    end

search(options={}, &block) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 48
    def search(options={}, &block)
      super(options) do |base, scope, filter, attrs, limit|
        info = {
          :base => base, :scope => scope_name(scope), :filter => filter,
          :attributes => attrs, :limit => limit,
        }
        execute(:search, info, base, scope, filter, attrs, limit, &block)
      end
    end

unbind(options={}) click to toggle source

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

### Private Instance Methods

ensure_method(method) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 115
    def ensure_method(method)
      method ||= "plain"
      normalized_method = method.to_s.downcase.to_sym
      return METHOD[normalized_method] if METHOD.has_key?(normalized_method)

      available_methods = METHOD.keys.collect {|m| m.inspect}.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/jndi.rb, line 185
    def ensure_mod_type(type)
      case type
      when :replace, :add
        type
      when :delete
        :remove
      else
        raise ArgumentError, _("unknown type: %s") % type
      end
    end

ensure_scope(scope) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 125
    def ensure_scope(scope)
      scope_map = {
        :base => JndiConnection::Scope::OBJECT,
        :one => JndiConnection::Scope::ONE_LEVEL,
        :sub => JndiConnection::Scope::SUBTREE,
      }
      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/jndi.rb, line 93
    def execute(method, info=nil, *args, &block)
      name = (info || {}).delete(:name) || method
      log(name, info) {@connection.send(method, *args, &block)}
    rescue JndiConnection::CommunicationException, JndiConnection::ServiceUnavailableException => e
      disconnect! if connecting?

      raise ActiveLdap::ConnectionError.new(e.getMessage())
    rescue JndiConnection::NamingException
      if /\[LDAP: error code (\d+) - ([^\]]+)\]/ =~ $!.to_s
        message = $2
        klass = LdapError::ERRORS[Integer($1)]
        klass ||= ActiveLdap::LdapError
        raise klass, message
      elsif /LDAP response read timed out/ =~ $!.to_s
        disconnect! if connecting?

        raise Timeout::Error.new($!.to_s)
      end

      raise
    end

parse_entries(entries) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 168
    def parse_entries(entries)
      result = []
      entries.each do |type, key, attributes|
        mod_type = ensure_mod_type(type)
        binary = schema.attribute(key).binary?
        attributes.each do |name, values|
          real_binary = binary
          if values.any? {|value| Ldif::Attribute.binary_value?(value)}
            real_binary = true
          end
          result << JndiConnection::ModifyRecord.new(mod_type, name,
                                                     values, real_binary)
        end
      end
      result
    end

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

    # File lib/active_ldap/adapter/jndi.rb, line 148
    def sasl_bind(bind_dn, options={})
      super do |_bind_dn, mechanism, quiet|
        info = {
          :name => "bind: SASL",
          :dn => _bind_dn,
          :mechanism => mechanism
        }
        execute(:sasl_bind, info, _bind_dn, mechanism, quiet)
        true
      end
    end

scope_name(scope) click to toggle source

    # File lib/active_ldap/adapter/jndi.rb, line 140
    def scope_name(scope)
      {
        JndiConnection::Scope::OBJECT => :base,
        JndiConnection::Scope::ONE_LEVEL => :one,
        JndiConnection::Scope::SUBTREE => :sub,
      }[scope]
    end

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.