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] DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update GetText::Translation Normalizable 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/schema/syntaxes.rb lib/active_ldap/xml.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb Compatible ClassMethods Associations LdapBenchmarking ActionController Populate 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 ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks 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/jndi.rb Adapter Helper Translation GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_46_0.png

Methods

Classes and Modules

Module ActiveLdap::Adapter::Ldap::Method

Public Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 125
125:       def add(dn, entries, options={})
126:         super do |_dn, _entries|
127:           controls = options[:controls]
128:           attributes = parse_entries(_entries)
129:           info = {:dn => _dn, :attributes => _entries}
130:           if controls
131:             info.merge!(:name => :add, :controls => controls)
132:             execute(:add_ext, info, _dn, attributes, controls, [])
133:           else
134:             execute(:add, info, _dn, attributes)
135:           end
136:         end
137:       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 111
111:       def delete(targets, options={})
112:         super do |target|
113:           controls = options[:controls]
114:           info = {:dn => target}
115:           if controls
116:             info.merge!(:name => :delete, :controls => controls)
117:             execute(:delete_ext, info,
118:                     target, controls, [])
119:           else
120:             execute(:delete, info, target)
121:           end
122:         end
123:       end

[Source]

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

[Source]

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

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 82
 82:       def search(options={})
 83:         super(options) do |base, scope, filter, attrs, limit|
 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:                 value = entry.vals(attr)
 94:                 attributes[attr] = value if value
 95:               end
 96:               yield([entry.dn, attributes])
 97:             end
 98:           rescue RuntimeError
 99:             if $!.message == "no result returned by search"
100:               @logger.debug do
101:                 args = [filter, attrs.inspect]
102:                 _("No matches: filter: %s: attributes: %s") % args
103:               end
104:             else
105:               raise
106:             end
107:           end
108:         end
109:       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 186
186:       def do_in_timeout(timeout, &block)
187:         Timeout.timeout(timeout, &block)
188:       end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 220
220:       def scope_name(scope)
221:         {
222:           LDAP::LDAP_SCOPE_BASE => :base,
223:           LDAP::LDAP_SCOPE_SUBTREE => :sub,
224:           LDAP::LDAP_SCOPE_ONELEVEL => :one,
225:         }[scope]
226:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 256
256:       def simple_bind(bind_dn, options={})
257:         super do |_bind_dn, password|
258:           execute(:bind, {:dn => _bind_dn}, _bind_dn, password)
259:           true
260:         end
261:       end

[Validate]