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 61 61: def add(dn, entries, options={}) 62: super do |_dn, _entries| 63: info = {:dn => _dn, :attributes => _entries} 64: execute(:add, info, _dn, parse_entries(_entries)) 65: end 66: end
# File lib/active_ldap/adapter/jndi.rb, line 37 37: def bind_as_anonymous(options={}) 38: super do 39: execute(:bind_as_anonymous, :name => "bind: anonymous") 40: true 41: end 42: 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 55 55: def delete(targets, options={}) 56: super do |target| 57: execute(:delete, {:dn => target}, target) 58: end 59: end
# File lib/active_ldap/adapter/jndi.rb, line 68 68: def modify(dn, entries, options={}) 69: super do |_dn, _entries| 70: info = {:dn => _dn, :attributes => _entries} 71: execute(:modify, info, _dn, parse_entries(_entries)) 72: end 73: end
# File lib/active_ldap/adapter/jndi.rb, line 75 75: def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={}) 76: super do |_dn, _new_rdn, _delete_old_rdn, _new_superior| 77: info = { 78: :name => "modify: RDN", 79: :dn => _dn, :new_rdn => _new_rdn, :delete_old_rdn => _delete_old_rdn, 80: } 81: execute(:modify_rdn, info, _dn, _new_rdn, _delete_old_rdn) 82: end 83: end
# File lib/active_ldap/adapter/jndi.rb, line 44 44: def search(options={}, &block) 45: super(options) do |base, scope, filter, attrs, limit, callback| 46: info = { 47: :base => base, :scope => scope_name(scope), :filter => filter, 48: :attributes => attrs, 49: } 50: execute(:search, info, 51: base, scope, filter, attrs, limit, callback, &block) 52: end 53: end
# File lib/active_ldap/adapter/jndi.rb, line 31 31: def unbind(options={}) 32: super do 33: execute(:unbind) 34: end 35: end
# File lib/active_ldap/adapter/jndi.rb, line 99 99: def ensure_method(method) 100: method ||= "plain" 101: normalized_method = method.to_s.downcase.to_sym 102: return METHOD[normalized_method] if METHOD.has_key?(normalized_method) 103: 104: available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ") 105: format = _("%s is not one of the available connect methods: %s") 106: raise ConfigurationError, format % [method.inspect, available_methods] 107: end
# File lib/active_ldap/adapter/jndi.rb, line 169 169: def ensure_mod_type(type) 170: case type 171: when :replace, :add 172: type 173: when :delete 174: :remove 175: else 176: raise ArgumentError, _("unknown type: %s") % type 177: end 178: end
# File lib/active_ldap/adapter/jndi.rb, line 109 109: def ensure_scope(scope) 110: scope_map = { 111: :base => JndiConnection::Scope::OBJECT, 112: :one => JndiConnection::Scope::ONE_LEVEL, 113: :sub => JndiConnection::Scope::SUBTREE, 114: } 115: value = scope_map[scope || :sub] 116: if value.nil? 117: available_scopes = scope_map.keys.inspect 118: format = _("%s is not one of the available LDAP scope: %s") 119: raise ArgumentError, format % [scope.inspect, available_scopes] 120: end 121: value 122: end
# File lib/active_ldap/adapter/jndi.rb, line 86 86: def execute(method, info=nil, *args, &block) 87: name = (info || {}).delete(:name) || method 88: log(name, info) {@connection.send(method, *args, &block)} 89: rescue JndiConnection::NamingException 90: if /\[LDAP: error code (\d+) - ([^\]]+)\]/ =~ $!.to_s 91: message = $2 92: klass = LdapError::ERRORS[Integer($1)] 93: klass ||= ActiveLdap::LdapError 94: raise klass, message 95: end 96: raise 97: end
# File lib/active_ldap/adapter/jndi.rb, line 152 152: def parse_entries(entries) 153: result = [] 154: entries.each do |type, key, attributes| 155: mod_type = ensure_mod_type(type) 156: binary = schema.attribute(key).binary? 157: attributes.each do |name, values| 158: real_binary = binary 159: if values.any? {|value| Ldif::Attribute.binary_value?(value)} 160: real_binary = true 161: end 162: result << JndiConnection::ModifyRecord.new(mod_type, name, 163: values, real_binary) 164: end 165: end 166: result 167: end
# File lib/active_ldap/adapter/jndi.rb, line 132 132: def sasl_bind(bind_dn, options={}) 133: super do |_bind_dn, mechanism, quiet| 134: info = { 135: :name => "bind: SASL", 136: :dn => _bind_dn, 137: :mechanism => mechanism 138: } 139: execute(:sasl_bind, info, _bind_dn, mechanism, quiet) 140: true 141: end 142: end
# File lib/active_ldap/adapter/jndi.rb, line 124 124: def scope_name(scope) 125: { 126: JndiConnection::Scope::OBJECT => :base, 127: JndiConnection::Scope::ONE_LEVEL => :one, 128: JndiConnection::Scope::SUBTREE => :sub, 129: }[scope] 130: end