Files

Class/Module Index [+]

Quicksearch

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.