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] 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

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 103
103:       def count(options={})
104:         search(options).size
105:       end

[Source]

     # File lib/active_ldap/operations.rb, line 79
 79:       def exist?(dn, options={})
 80:         attr, value, prefix = split_search_value(dn)
 81: 
 82:         options_for_leaf = {
 83:           :attribute => attr,
 84:           :value => value,
 85:           :prefix => prefix,
 86:           :limit => 1,
 87:         }
 88: 
 89:         attribute = attr || ensure_search_attribute
 90:         options_for_non_leaf = {
 91:           :attribute => attr,
 92:           :value => value,
 93:           :prefix => ["#{attribute}=#{value}", prefix].compact.join(","),
 94:           :limit => 1,
 95:           :scope => :base,
 96:         }
 97: 
 98:         !search(options_for_leaf.merge(options)).empty? or
 99:           !search(options_for_non_leaf.merge(options)).empty?
100:       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 = options[:connection].search(search_options) do |dn, attrs|
66:           attributes = {}
67:           attrs.each do |key, _value|
68:             normalized_attr, normalized_value =
69:               normalize_attribute_options(key, _value)
70:             attributes[normalized_attr] ||= []
71:             attributes[normalized_attr].concat(normalized_value)
72:           end
73:           [dn, attributes]
74:         end
75:         values = values.collect {|_value| yield(_value)} if block_given?
76:         values
77:       end

Private Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]