Class ActiveLdap::Adapter::Ldap
In: lib/active_ldap/adapter/ldap.rb
Parent: Base
Error DeleteError LdapError AdapterNotSpecified OperationNotPermitted RequiredAttributeMissed LdifInvalid AttributeAssignmentError RequiredObjectClassMissed DistinguishedNameNotSetError StrongAuthenticationRequired ConnectionError SaveError EntryNotFound AuthenticationError EntryNotSaved UnknownAttribute ConnectionNotEstablished TimeoutError ConfigurationError AdapterNotFound DistinguishedNameInvalid ObjectClassError EntryInvalid EntryAlreadyExist Base DistinguishedName Ldif Reloadable::Deprecated Reloadable::Subclasses Enumerable Collection StandardError Children HasMany HasManyWrap BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update GetText Parser GetTextSupport Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Ldap NetLdap Normalize ActiveRecord::Callbacks ActiveRecord::Validations Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/ldif.rb lib/active_ldap/distinguished_name.rb lib/active_ldap/ldap_error.rb ClassMethods Associations ClassMethods HumanReadable lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/has_many.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb HasManyUtils Association ClassMethods Tree Acts Common LDIF Delete Find Update Operations lib/active_ldap/get_text/parser.rb GetText ClassMethods Configuration Command lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb Adapter GetTextSupport Normalize ClassMethods Attributes Escape Callbacks ClassMethods ObjectClass Helper Validations ClassMethods Connection GetTextFallback Populate Salt UserPassword ActiveLdap dot/m_40_0.png

Methods

Classes and Modules

Module ActiveLdap::Adapter::Ldap::Method

Public Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 113
113:       def add(dn, entries, options={})
114:         super do |dn, entries|
115:           execute(:add, dn, parse_entries(entries))
116:         end
117:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 48
48:       def bind(options={})
49:         super do
50:           @connection.error_message
51:         end
52:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 54
54:       def bind_as_anonymous(options={})
55:         super do
56:           execute(:bind)
57:           true
58:         end
59:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 61
61:       def bound?
62:         connecting? and @connection.bound?
63:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 35
35:       def connect(options={})
36:         super do |host, port, method|
37:           method.connect(host, port)
38:         end
39:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 107
107:       def delete(targets, options={})
108:         super do |target|
109:           execute(:delete, target)
110:         end
111:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 101
101:       def load(ldifs, options={})
102:         super do |ldif|
103:           LDAP::LDIF.parse_entry(ldif).send(@connection)
104:         end
105:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 119
119:       def modify(dn, entries, options={})
120:         super do |dn, entries|
121:           execute(:modify, dn, parse_entries(entries))
122:         end
123:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 65
65:       def search(options={}, &block)
66:         super(options) do |base, scope, filter, attrs, limit, callback|
67:           begin
68:             i = 0
69:             execute(:search, base, scope, filter, attrs) do |entry|
70:               i += 1
71:               attributes = {}
72:               entry.attrs.each do |attr|
73:                 attributes[attr] = entry.vals(attr)
74:               end
75:               callback.call([entry.dn, attributes], block)
76:               break if limit and limit <= i
77:             end
78:           rescue RuntimeError
79:             if $!.message == "no result returned by search"
80:               @logger.debug do
81:                 args = [filter, attrs.inspect]
82:                 _("No matches: filter: %s: attributes: %s") % args
83:               end
84:             else
85:               raise
86:             end
87:           end
88:         end
89:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 91
91:       def to_ldif(dn, attributes)
92:         ldif = LDAP::LDIF.to_ldif("dn", [dn.dup])
93:         attributes.sort_by do |key, value|
94:           key
95:         end.each do |key, values|
96:           ldif << LDAP::LDIF.to_ldif(key, values)
97:         end
98:         ldif
99:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 41
41:       def unbind(options={})
42:         return unless bound?
43:         operation(options) do
44:           execute(:unbind)
45:         end
46:       end

Private Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 157
157:       def ensure_method(method)
158:         Method.constants.each do |name|
159:           if method.to_s.downcase == name.downcase
160:             return Method.const_get(name).new
161:           end
162:         end
163: 
164:         available_methods = Method.constants.collect do |name|
165:           name.downcase.to_sym.inspect
166:         end.join(", ")
167:         format = _("%s is not one of the available connect methods: %s")
168:         raise ConfigurationError, format % [method.inspect, available_methods]
169:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 221
221:       def ensure_mod_type(type)
222:         case type
223:         when :replace, :add
224:           LDAP.const_get("LDAP_MOD_#{type.to_s.upcase}")
225:         else
226:           raise ArgumentError, _("unknown type: %s") % type
227:         end
228:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 171
171:       def ensure_scope(scope)
172:         scope_map = {
173:           :base => LDAP::LDAP_SCOPE_BASE,
174:           :sub => LDAP::LDAP_SCOPE_SUBTREE,
175:           :one => LDAP::LDAP_SCOPE_ONELEVEL,
176:         }
177:         value = scope_map[scope || :sub]
178:         if value.nil?
179:           available_scopes = scope_map.keys.inspect
180:           format = _("%s is not one of the available LDAP scope: %s")
181:           raise ArgumentError, format % [scope.inspect, available_scopes]
182:         end
183:         value
184:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 138
138:       def execute(method, *args, &block)
139:         begin
140:           @connection.send(method, *args, &block)
141:         rescue LDAP::ResultError
142:           @connection.assert_error_code
143:           raise $!.message
144:         end
145:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 208
208:       def parse_entries(entries)
209:         result = []
210:         entries.each do |type, key, attributes|
211:           mod_type = ensure_mod_type(type)
212:           binary = schema.attribute(key).binary?
213:           mod_type |= LDAP::LDAP_MOD_BVALUES if binary
214:           attributes.each do |name, values|
215:             result << LDAP.mod(mod_type, name, values)
216:           end
217:         end
218:         result
219:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 126
126:       def prepare_connection(options={})
127:         operation(options) do
128:           @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
129:         end
130:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 132
132:       def root_dse(attributes, options={})
133:         sec = options[:sec] || 0
134:         usec = options[:usec] || 0
135:         @connection.root_dse(attributes, sec, usec)
136:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 186
186:       def sasl_bind(bind_dn, options={})
187:         super do |bind_dn, mechanism, quiet|
188:           begin
189:             sasl_quiet = @connection.sasl_quiet
190:             @connection.sasl_quiet = quiet unless quiet.nil?
191:             args = [bind_dn, mechanism]
192:             if need_credential_sasl_mechanism?(mechanism)
193:               args << password(bind_dn, options)
194:             end
195:             execute(:sasl_bind, *args)
196:           ensure
197:             @connection.sasl_quiet = sasl_quiet
198:           end
199:         end
200:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 202
202:       def simple_bind(bind_dn, options={})
203:         super do |bind_dn, passwd|
204:           execute(:bind, bind_dn, passwd)
205:         end
206:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 147
147:       def with_timeout(try_reconnect=true, options={}, &block)
148:         begin
149:           super
150:         rescue LDAP::ServerDown => e
151:           @logger.error {_("LDAP server is down: %s") % e.message}
152:           retry if try_reconnect and reconnect(options)
153:           raise ConnectionError.new(e.message)
154:         end
155:       end

[Validate]