Class | ActiveLdap::Adapter::Jndi |
In: |
lib/active_ldap/adapter/jndi.rb
|
Parent: | Base |
METHOD | = | { :ssl => :ssl, :tls => :start_tls, :plain => nil, } |
# File lib/active_ldap/adapter/jndi.rb, line 65 65: def add(dn, entries, options={}) 66: super do |dn, entries| 67: info = {:dn => dn, :attributes => entries} 68: execute(:add, info, dn, parse_entries(entries)) 69: end 70: end
# File lib/active_ldap/adapter/jndi.rb, line 38 38: def bind_as_anonymous(options={}) 39: super do 40: execute(:bind_as_anonymous, :name => "bind: anonymous") 41: end 42: end
# File lib/active_ldap/adapter/jndi.rb, line 44 44: def bound? 45: connecting? and @connection.bound? 46: end
# File lib/active_ldap/adapter/jndi.rb, line 21 21: def connect(options={}) 22: super do |host, port, method| 23: uri = construct_uri(host, port, method == :ssl) 24: with_start_tls = method == :start_tls 25: info = {:uri => uri, :with_start_tls => with_start_tls} 26: [log("connect", info) {JndiConnection.new(host, port, method)}, 27: uri, with_start_tls] 28: end 29: end
# File lib/active_ldap/adapter/jndi.rb, line 59 59: def delete(targets, options={}) 60: super do |target| 61: execute(:delete, {:dn => target}, target) 62: end 63: end
# File lib/active_ldap/adapter/jndi.rb, line 72 72: def modify(dn, entries, options={}) 73: super do |dn, entries| 74: info = {:dn => dn, :attributes => entries} 75: execute(:modify, info, dn, parse_entries(entries)) 76: end 77: end
# File lib/active_ldap/adapter/jndi.rb, line 79 79: def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={}) 80: super do |dn, new_rdn, delete_old_rdn, new_superior| 81: info = { 82: :name => "modify: RDN", :dn => dn, :new_rdn => new_rdn, 83: :delete_old_rdn => delete_old_rdn, 84: } 85: execute(:modify_rdn, info, dn, new_rdn, delete_old_rdn) 86: end 87: end
# File lib/active_ldap/adapter/jndi.rb, line 48 48: def search(options={}, &block) 49: super(options) do |base, scope, filter, attrs, limit, callback| 50: info = { 51: :base => base, :scope => scope_name(scope), :filter => filter, 52: :attributes => attrs, 53: } 54: execute(:search, info, 55: base, scope, filter, attrs, limit, callback, &block) 56: end 57: end
# File lib/active_ldap/adapter/jndi.rb, line 31 31: def unbind(options={}) 32: return unless bound? 33: operation(options) do 34: execute(:unbind) 35: end 36: end
# File lib/active_ldap/adapter/jndi.rb, line 103 103: def ensure_method(method) 104: method ||= "plain" 105: normalized_method = method.to_s.downcase.to_sym 106: return METHOD[normalized_method] if METHOD.has_key?(normalized_method) 107: 108: available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ") 109: format = _("%s is not one of the available connect methods: %s") 110: raise ConfigurationError, format % [method.inspect, available_methods] 111: end
# File lib/active_ldap/adapter/jndi.rb, line 163 163: def ensure_mod_type(type) 164: case type 165: when :replace, :add 166: type 167: when :delete 168: :remove 169: else 170: raise ArgumentError, _("unknown type: %s") % type 171: end 172: end
# File lib/active_ldap/adapter/jndi.rb, line 113 113: def ensure_scope(scope) 114: scope_map = { 115: :base => 0, 116: :one => 1, 117: :sub => 2, 118: } 119: value = scope_map[scope || :sub] 120: if value.nil? 121: available_scopes = scope_map.keys.inspect 122: format = _("%s is not one of the available LDAP scope: %s") 123: raise ArgumentError, format % [scope.inspect, available_scopes] 124: end 125: value 126: end
# File lib/active_ldap/adapter/jndi.rb, line 90 90: def execute(method, info=nil, *args, &block) 91: name = (info || {}).delete(:name) || method 92: log(name, info) {@connection.send(method, *args, &block)} 93: rescue JndiConnection::NamingException 94: if /\[LDAP: error code (\d+) - ([^\]]+)\]/ =~ $!.to_s 95: message = $2 96: klass = LdapError::ERRORS[Integer($1)] 97: klass ||= ActiveLdap::LdapError 98: raise klass, message 99: end 100: raise 101: end
# File lib/active_ldap/adapter/jndi.rb, line 150 150: def parse_entries(entries) 151: result = [] 152: entries.each do |type, key, attributes| 153: mod_type = ensure_mod_type(type) 154: binary = schema.attribute(key).binary? 155: attributes.each do |name, values| 156: result << JndiConnection::ModifyRecord.new(mod_type, name, 157: values, binary) 158: end 159: end 160: result 161: end
# File lib/active_ldap/adapter/jndi.rb, line 136 136: def sasl_bind(bind_dn, options={}) 137: super do |bind_dn, mechanism, quiet| 138: info = {:name => "bind: SASL", :dn => bind_dn, :mechanism => mechanism} 139: execute(:sasl_bind, info, bind_dn, mechanism, quiet) 140: end 141: end
# File lib/active_ldap/adapter/jndi.rb, line 128 128: def scope_name(scope) 129: { 130: 0 => :base, 131: 1 => :one, 132: 2 => :sub, 133: }[scope] 134: end