Module: Ldaptic::Adapters

Defined in:
lib/ldaptic/adapters.rb,
lib/ldaptic/adapters/abstract_adapter.rb,
lib/ldaptic/adapters/net_ldap_adapter.rb,
lib/ldaptic/adapters/ldap_conn_adapter.rb,
lib/ldaptic/adapters/active_directory_adapter.rb

Overview

RFC1823 - The LDAP Application Program Interface

Defined Under Namespace

Classes: AbstractAdapter, ActiveDirectoryAdapter, LDAPConnAdapter, NetLDAPAdapter

Class Method Summary collapse

Class Method Details

.for(options) ⇒ Object

Returns a new adapter for a given set of options. This method is not for end user use but is instead called by the Ldaptic::Class, Ldaptic::Module, and Ldaptic::Object methods.

The :adapter key of the options hash selects which adapter to use. The following adapters are included with Ldaptic.

  • :ldap_conn: a Ruby/LDAP LDAP::Conn connection.

  • :ldap_sslconn: a Ruby/LDAP LDAP::SSLConn connection.

  • :active_directory: A wrapper around Ruby/LDAP which takes into account some of the idiosyncrasies of Active Directory.

  • :net_ldap: a net-ldap Net::LDAP connection.

All other options given are passed directly to the adapter. While different adapters support different options, the following are typically supported.

  • :host: The host to connect to. The default is localhost.

  • :port: The TCP port to use. Default is provided by the underlying connection.

  • :username: The DN to bind with. If not given, an anonymous bind is used.

  • :password: Password for binding.

  • :base: The default base DN. Derived from the server by default.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ldaptic/adapters.rb', line 40

def for(options)
  require 'ldaptic/adapters/abstract_adapter'
  # Allow an adapter to be passed directly in for backwards compatibility.
  if defined?(::LDAP::Conn) && options.kind_of?(::LDAP::Conn)
    options = {:adapter => :ldap_conn, :connection => options}
  elsif defined?(::Net::LDAP) && options.kind_of?(::Net::LDAP)
    options = {:adapter => :net_ldap, :connection => options}
  end
  if options.kind_of?(Hash)
    options = options.inject({}) {|h,(k,v)| h[k.to_sym] = v; h}
    if options.has_key?(:connection) && !options.has_key?(:adapter)
      options[:adapter] = options[:connection].class.name.downcase.gsub('::','_')
    end
    options[:adapter] ||= default_adapter
    unless options[:adapter]
      Ldaptic::Errors.raise(ArgumentError.new("No adapter specfied"))
    end
    begin
      require "ldaptic/adapters/#{options[:adapter]}_adapter"
    rescue LoadError
    end
    if adapter = @adapters[options[:adapter].to_sym]
      adapter.new(options)
    else
      Ldaptic::Errors.raise(ArgumentError.new("Adapter #{options[:adapter]} not found"))
    end
  else
    if options.kind_of?(::Ldaptic::Adapters::AbstractAdapter)
      options
    else
      Ldaptic::Errors.raise(TypeError.new("#{options.class} is not a valid connection type"))
    end
  end
end

.register(name, mod) ⇒ Object

Internally used by adapters to make themselves available.



10
11
12
13
# File 'lib/ldaptic/adapters.rb', line 10

def register(name, mod) #:nodoc:
  @adapters[name.to_sym] = mod
  @adapters
end