Class ActiveLdap::Adapter::Ldap
In: lib/active_ldap/adapter/ldap.rb
Parent: Base
Error DeleteError AdapterNotSpecified OperationNotPermitted LdapError RequiredAttributeMissed AttributeAssignmentError RequiredObjectClassMissed DistinguishedNameNotSetError StrongAuthenticationRequired ConnectionError SaveError EntryNotFound AuthenticationError EntryNotSaved UnknownAttribute ConnectionNotEstablished TimeoutError ConfigurationError AdapterNotFound DistinguishedNameInvalid ObjectClassError EntryInvalid EntryAlreadyExist Reloadable::Deprecated Base Reloadable::Subclasses Enumerable Collection StandardError HasMany HasManyWrap BelongsToMany Proxy BelongsTo Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Ldap NetLdap ActiveRecord::Callbacks ActiveRecord::Validations Schema DistinguishedName lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/distinguished_name.rb lib/active_ldap/ldap_error.rb ClassMethods Associations 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/collection.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb Association ClassMethods Configuration Command lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb Adapter ClassMethods Attributes ClassMethods ObjectClass Callbacks ClassMethods Connection Validations Salt UserPassword ActiveLdap dot/m_26_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 50
50:       def bind(options={})
51:         super do
52:           @connection.error_message
53:         end
54:       end

[Source]

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

[Source]

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

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 37
37:       def connect(options={})
38:         super do |host, port, method|
39:           method.connect(host, port)
40:         end
41:       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 67
67:       def search(options={}, &block)
68:         super(options) do |base, scope, filter, attrs, limit, callback|
69:           begin
70:             i = 0
71:             execute(:search, base, scope, filter, attrs) do |entry|
72:               i += 1
73:               attributes = {}
74:               entry.attrs.each do |attr|
75:                 attributes[attr] = entry.vals(attr)
76:               end
77:               callback.call([entry.dn, attributes], block)
78:               break if limit and limit >= i
79:             end
80:           rescue RuntimeError
81:             if $!.message == "no result returned by search"
82:               @logger.debug {"No matches for #{filter} and attrs " +
83:                              "#{attrs.inspect}"}
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 43
43:       def unbind(options={})
44:         return unless bound?
45:         operation(options) do
46:           execute(:unbind)
47:         end
48:       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:         raise ConfigurationError,
168:                 "#{method.inspect} is not one of the available connect " +
169:                 "methods #{available_methods}"
170:       end

[Source]

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

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 172
172:       def ensure_scope(scope)
173:         scope_map = {
174:           :base => LDAP::LDAP_SCOPE_BASE,
175:           :sub => LDAP::LDAP_SCOPE_SUBTREE,
176:           :one => LDAP::LDAP_SCOPE_ONELEVEL,
177:         }
178:         value = scope_map[scope || :sub]
179:         if value.nil?
180:           available_scopes = scope_map.keys.inspect
181:           raise ArgumentError, "#{scope.inspect} is not one of the available " +
182:                                "LDAP scope #{available_scopes}"
183:         end
184:         value
185:       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 209
209:       def parse_entries(entries)
210:         result = []
211:         entries.each do |type, key, attributes|
212:           mod_type = ensure_mod_type(type)
213:           binary = schema.binary?(key)
214:           mod_type |= LDAP::LDAP_MOD_BVALUES if binary
215:           attributes.each do |name, values|
216:             result << LDAP.mod(mod_type, name, values)
217:           end
218:         end
219:         result
220:       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 187
187:       def sasl_bind(bind_dn, options={})
188:         super do |bind_dn, mechanism, quiet|
189:           begin
190:             sasl_quiet = @connection.sasl_quiet
191:             @connection.sasl_quiet = quiet unless quiet.nil?
192:             args = [bind_dn, mechanism]
193:             if need_credential_sasl_mechanism?(mechanism)
194:               args << password(bind_dn, options)
195:             end
196:             execute(:sasl_bind, *args)
197:           ensure
198:             @connection.sasl_quiet = sasl_quiet
199:           end
200:         end
201:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 203
203:       def simple_bind(bind_dn, options={})
204:         super do |bind_dn, passwd|
205:           execute(:bind, bind_dn, passwd)
206:         end
207:       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: #{e.message}"}
152:           retry if try_reconnect and reconnect(options)
153:           raise ConnectionError.new(e.message)
154:         end
155:       end

[Validate]