Module ActiveLdap::Operations::Common
In: lib/active_ldap/operations.rb
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

Constants

VALID_SEARCH_OPTIONS = [:attribute, :value, :filter, :prefix, :classes, :scope, :limit, :attributes, :sort_by, :order, :connection, :base]

Public Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 104
104:       def count(options={})
105:         search(options).size
106:       end

[Source]

     # File lib/active_ldap/operations.rb, line 80
 80:       def exist?(dn, options={})
 81:         attr, value, prefix = split_search_value(dn)
 82: 
 83:         options_for_leaf = {
 84:           :attribute => attr,
 85:           :value => value,
 86:           :prefix => prefix,
 87:           :limit => 1,
 88:         }
 89: 
 90:         attribute = attr || ensure_search_attribute
 91:         options_for_non_leaf = {
 92:           :attribute => attr,
 93:           :value => value,
 94:           :prefix => ["#{attribute}=#{value}", prefix].compact.join(","),
 95:           :limit => 1,
 96:           :scope => :base,
 97:         }
 98: 
 99:         !search(options_for_leaf.merge(options)).empty? or
100:           !search(options_for_non_leaf.merge(options)).empty?
101:       end
exists?(dn, options={})

Alias for exist?

[Source]

    # File lib/active_ldap/operations.rb, line 27
27:       def search(options={}, &block)
28:         validate_search_options(options)
29:         attr = options[:attribute]
30:         value = options[:value] || '*'
31:         filter = options[:filter]
32:         prefix = options[:prefix]
33:         classes = options[:classes]
34: 
35:         value = value.first if value.is_a?(Array) and value.first.size == 1
36: 
37:         _attr = nil
38:         _prefix = nil
39:         if attr.nil? or attr == dn_attribute
40:           _attr, value, _prefix = split_search_value(value)
41:         end
42:         attr ||= _attr || ensure_search_attribute
43:         prefix ||= _prefix
44:         filter ||= [attr, value]
45:         filter = [:and, filter, *object_class_filters(classes)]
46:         _base = options[:base] ? [options[:base]] : [prefix, base]
47:         _base = prepare_search_base(_base)
48:         if options.has_key?(:ldap_scope)
49:           message = _(":ldap_scope search option is deprecated. " \
50:                       "Use :scope instead.")
51:           ActiveSupport::Deprecation.warn(message)
52:           options[:scope] ||= options[:ldap_scope]
53:         end
54:         search_options = {
55:           :base => _base,
56:           :scope => options[:scope] || scope,
57:           :filter => filter,
58:           :limit => options[:limit],
59:           :attributes => options[:attributes],
60:           :sort_by => options[:sort_by] || sort_by,
61:           :order => options[:order] || order,
62:         }
63: 
64:         options[:connection] ||= connection
65:         values = []
66:         options[:connection].search(search_options) do |dn, attrs|
67:           attributes = {}
68:           attrs.each do |key, _value|
69:             normalized_attr, normalized_value =
70:               normalize_attribute_options(key, _value)
71:             attributes[normalized_attr] ||= []
72:             attributes[normalized_attr].concat(normalized_value)
73:           end
74:           values << [dn, attributes]
75:         end
76:         values = values.collect {|_value| yield(_value)} if block_given?
77:         values
78:       end

Private Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 126
126:       def ensure_base(target)
127:         [truncate_base(target), base.to_s].reject do |component|
128:           component.blank?
129:         end.join(',')
130:       end

[Source]

     # File lib/active_ldap/operations.rb, line 121
121:       def ensure_dn_attribute(target)
122:         "#{dn_attribute}=" +
123:           target.gsub(/^\s*#{Regexp.escape(dn_attribute)}\s*=\s*/i, '')
124:       end

[Source]

     # File lib/active_ldap/operations.rb, line 117
117:       def ensure_search_attribute(*candidates)
118:         default_search_attribute || "objectClass"
119:       end

[Source]

     # File lib/active_ldap/operations.rb, line 113
113:       def extract_options_from_args!(args)
114:         args.last.is_a?(Hash) ? args.pop : {}
115:       end

[Source]

     # File lib/active_ldap/operations.rb, line 167
167:       def object_class_filters(classes=nil)
168:         expected_classes = (classes || required_classes).collect do |name|
169:           Escape.ldap_filter_escape(name)
170:         end
171:         unexpected_classes = excluded_classes.collect do |name|
172:           Escape.ldap_filter_escape(name)
173:         end
174:         filters = []
175:         unless expected_classes.empty?
176:           filters << ["objectClass", "=", *expected_classes]
177:         end
178:         unless unexpected_classes.empty?
179:           filters << [:not, [:or, ["objectClass", "=", *unexpected_classes]]]
180:         end
181:         filters
182:       end

[Source]

     # File lib/active_ldap/operations.rb, line 154
154:       def prepare_search_base(components)
155:         components.compact.collect do |component|
156:           case component
157:           when String
158:             component
159:           when DN
160:             component.to_s
161:           else
162:             DN.new(*component).to_s
163:           end
164:         end.reject{|x| x.empty?}.join(",")
165:       end

[Source]

     # File lib/active_ldap/operations.rb, line 184
184:       def split_search_value(value)
185:         attr = prefix = nil
186: 
187:         begin
188:           dn = DN.parse(value)
189:           attr, value = dn.rdns.first.to_a.first
190:           rest = dn.rdns[1..-1]
191:           prefix = DN.new(*rest).to_s unless rest.empty?
192:         rescue DistinguishedNameInputInvalid
193:           return [attr, value, prefix]
194:         rescue DistinguishedNameInvalid
195:           begin
196:             dn = DN.parse("DUMMY=#{value}")
197:             _, value = dn.rdns.first.to_a.first
198:             rest = dn.rdns[1..-1]
199:             prefix = DN.new(*rest).to_s unless rest.empty?
200:           rescue DistinguishedNameInvalid
201:           end
202:         end
203: 
204:         prefix = nil if prefix == base
205:         prefix = truncate_base(prefix) if prefix
206:         [attr, value, prefix]
207:       end

[Source]

     # File lib/active_ldap/operations.rb, line 132
132:       def truncate_base(target)
133:         return nil if target.blank?
134:         return target if base.nil?
135: 
136:         parsed_target = nil
137:         if target.is_a?(DN)
138:           parsed_target = target
139:         elsif /,/ =~ target
140:           begin
141:             parsed_target = DN.parse(target)
142:           rescue DistinguishedNameInvalid
143:           end
144:         end
145: 
146:         return target if parsed_target.nil?
147:         begin
148:           (parsed_target - base).to_s
149:         rescue ArgumentError
150:           target
151:         end
152:       end

[Source]

     # File lib/active_ldap/operations.rb, line 109
109:       def validate_search_options(options)
110:         options.assert_valid_keys(VALID_SEARCH_OPTIONS)
111:       end

[Validate]