Class ActiveLdap::Adapter::Ldap
In: lib/active_ldap/adapter/ldap.rb
Parent: Base
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired NotImplemented AdapterNotFound TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError ConnectionNotSetup DistinguishedNameInvalid Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] Base DistinguishedName Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasMany HasManyWrap BelongsToMany Proxy BelongsTo Normalizable Common Find LDIF Delete Update GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/xml.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb LdapBenchmarking ActionController ClassMethods Associations Compatible ClassMethods Tree Acts lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association Populate Command ClassMethods Normalizable Attributes Escape GetTextSupport Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations ClassMethods Configuration lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks ClassMethods ObjectClass Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_45_0.png

Methods

Classes and Modules

Module ActiveLdap::Adapter::Ldap::Method

Public Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 124
124:       def add(dn, entries, options={})
125:         super do |_dn, _entries|
126:           controls = options[:controls]
127:           attributes = parse_entries(_entries)
128:           info = {:dn => _dn, :attributes => _entries}
129:           if controls
130:             info.merge!(:name => :add, :controls => controls)
131:             execute(:add_ext, info, _dn, attributes, controls, [])
132:           else
133:             execute(:add, info, _dn, attributes)
134:           end
135:         end
136:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 69
69:       def bind(options={})
70:         super do
71:           @connection.error_message
72:         end
73:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 75
75:       def bind_as_anonymous(options={})
76:         super do
77:           execute(:bind, :name => "bind: anonymous")
78:           true
79:         end
80:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 53
53:       def connect(options={})
54:         super do |host, port, method|
55:           uri = construct_uri(host, port, method.ssl?)
56:           with_start_tls = method.start_tls?
57:           info = {:uri => uri, :with_start_tls => with_start_tls}
58:           [log("connect", info) {method.connect(host, port)},
59:            uri, with_start_tls]
60:         end
61:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 110
110:       def delete(targets, options={})
111:         super do |target|
112:           controls = options[:controls]
113:           info = {:dn => target}
114:           if controls
115:             info.merge!(:name => :delete, :controls => controls)
116:             execute(:delete_ext, info,
117:                     target, controls, [])
118:           else
119:             execute(:delete, info, target)
120:           end
121:         end
122:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 138
138:       def modify(dn, entries, options={})
139:         super do |_dn, _entries|
140:           controls = options[:controls]
141:           attributes = parse_entries(_entries)
142:           info = {:dn => _dn, :attributes => _entries}
143:           if controls
144:             info.merge!(:name => :modify, :controls => controls)
145:             execute(:modify_ext, info, _dn, attributes, controls, [])
146:           else
147:             execute(:modify, info, _dn, attributes)
148:           end
149:         end
150:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 152
152:       def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
153:         super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
154:           if _new_superior
155:             raise NotImplemented.new(_("modify RDN with new superior"))
156:           end
157:           info = {
158:             :name => "modify: RDN",
159:             :dn => _dn,
160:             :new_rdn => _new_rdn,
161:             :new_superior => _new_superior,
162:             :delete_old_rdn => _delete_old_rdn
163:           }
164:           execute(:modrdn, info, _dn, _new_rdn, _delete_old_rdn)
165:         end
166:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 82
 82:       def search(options={}, &block)
 83:         super(options) do |base, scope, filter, attrs, limit, callback|
 84:           begin
 85:             info = {
 86:               :base => base, :scope => scope_name(scope),
 87:               :filter => filter, :attributes => attrs, :limit => limit,
 88:             }
 89:             execute(:search_with_limit,
 90:                     info, base, scope, filter, attrs, limit) do |entry|
 91:               attributes = {}
 92:               entry.attrs.each do |attr|
 93:                 attributes[attr] = entry.vals(attr)
 94:               end
 95:               callback.call([entry.dn, attributes], block)
 96:             end
 97:           rescue RuntimeError
 98:             if $!.message == "no result returned by search"
 99:               @logger.debug do
100:                 args = [filter, attrs.inspect]
101:                 _("No matches: filter: %s: attributes: %s") % args
102:               end
103:             else
104:               raise
105:             end
106:           end
107:         end
108:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 63
63:       def unbind(options={})
64:         super do
65:           execute(:unbind)
66:         end
67:       end

Private Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 185
185:       def ensure_method(method)
186:         normalized_method = method.to_s.downcase
187:         Method.constants.each do |name|
188:           if normalized_method == name.to_s.downcase
189:             return Method.const_get(name).new
190:           end
191:         end
192: 
193:         available_methods = Method.constants.collect do |name|
194:           name.downcase.to_sym.inspect
195:         end.join(", ")
196:         format = _("%s is not one of the available connect methods: %s")
197:         raise ConfigurationError, format % [method.inspect, available_methods]
198:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 275
275:       def ensure_mod_type(type)
276:         case type
277:         when :replace, :add, :delete
278:           LDAP.const_get("LDAP_MOD_#{type.to_s.upcase}")
279:         else
280:           raise ArgumentError, _("unknown type: %s") % type
281:         end
282:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 200
200:       def ensure_scope(scope)
201:         scope_map = {
202:           :base => LDAP::LDAP_SCOPE_BASE,
203:           :sub => LDAP::LDAP_SCOPE_SUBTREE,
204:           :one => LDAP::LDAP_SCOPE_ONELEVEL,
205:         }
206:         value = scope_map[scope || :sub]
207:         if value.nil?
208:           available_scopes = scope_map.keys.inspect
209:           format = _("%s is not one of the available LDAP scope: %s")
210:           raise ArgumentError, format % [scope.inspect, available_scopes]
211:         end
212:         value
213:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 175
175:       def execute(method, info=nil, *args, &block)
176:         begin
177:           name = (info || {}).delete(:name) || method
178:           log(name, info) {@connection.send(method, *args, &block)}
179:         rescue LDAP::ResultError
180:           @connection.assert_error_code
181:           raise $!.message
182:         end
183:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 258
258:       def parse_entries(entries)
259:         result = []
260:         entries.each do |type, key, attributes|
261:           mod_type = ensure_mod_type(type)
262:           binary = schema.attribute(key).binary?
263:           mod_type |= LDAP::LDAP_MOD_BVALUES if binary
264:           attributes.each do |name, values|
265:             additional_mod_type = 0
266:             if values.any? {|value| Ldif::Attribute.binary_value?(value)}
267:               additional_mod_type |= LDAP::LDAP_MOD_BVALUES
268:             end
269:             result << LDAP.mod(mod_type | additional_mod_type, name, values)
270:           end
271:         end
272:         result
273:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 169
169:       def prepare_connection(options={})
170:         operation(options) do
171:           @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
172:         end
173:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 223
223:       def sasl_bind(bind_dn, options={})
224:         super do |_bind_dn, mechanism, quiet|
225:           begin
226:             _bind_dn ||= ''
227:             sasl_quiet = @connection.sasl_quiet
228:             @connection.sasl_quiet = quiet unless quiet.nil?
229:             args = [_bind_dn, mechanism]
230:             credential = nil
231:             if need_credential_sasl_mechanism?(mechanism)
232:               credential = password(_bind_dn, options)
233:             end
234:             if @sasl_options
235:               credential ||= ""
236:               args.concat([credential, nil, nil, @sasl_options])
237:             else
238:               args << credential if credential
239:             end
240:             info = {
241:               :name => "bind: SASL", :dn => _bind_dn, :mechanism => mechanism
242:             }
243:             execute(:sasl_bind, info, *args)
244:             true
245:           ensure
246:             @connection.sasl_quiet = sasl_quiet
247:           end
248:         end
249:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 215
215:       def scope_name(scope)
216:         {
217:           LDAP::LDAP_SCOPE_BASE => :base,
218:           LDAP::LDAP_SCOPE_SUBTREE => :sub,
219:           LDAP::LDAP_SCOPE_ONELEVEL => :one,
220:         }[scope]
221:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 251
251:       def simple_bind(bind_dn, options={})
252:         super do |_bind_dn, password|
253:           execute(:bind, {:dn => _bind_dn}, _bind_dn, password)
254:           true
255:         end
256:       end

[Validate]