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
-
.for(options) ⇒ Object
Returns a new adapter for a given set of options.
-
.register(name, mod) ⇒ Object
Internally used by adapters to make themselves available.
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() require 'ldaptic/adapters/abstract_adapter' # Allow an adapter to be passed directly in for backwards compatibility. if defined?(::LDAP::Conn) && .kind_of?(::LDAP::Conn) = {:adapter => :ldap_conn, :connection => } elsif defined?(::Net::LDAP) && .kind_of?(::Net::LDAP) = {:adapter => :net_ldap, :connection => } end if .kind_of?(Hash) = .inject({}) {|h,(k,v)| h[k.to_sym] = v; h} if .has_key?(:connection) && !.has_key?(:adapter) [:adapter] = [:connection].class.name.downcase.gsub('::','_') end [:adapter] ||= default_adapter unless [:adapter] Ldaptic::Errors.raise(ArgumentError.new("No adapter specfied")) end begin require "ldaptic/adapters/#{[:adapter]}_adapter" rescue LoadError end if adapter = @adapters[[:adapter].to_sym] adapter.new() else Ldaptic::Errors.raise(ArgumentError.new("Adapter #{[:adapter]} not found")) end else if .kind_of?(::Ldaptic::Adapters::AbstractAdapter) else Ldaptic::Errors.raise(TypeError.new("#{.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 |