Class Index [+]

Quicksearch

ActiveLdap::Operations::Common

Constants

VALID_SEARCH_OPTIONS

Public Instance Methods

count(options={}) click to toggle source
     # File lib/active_ldap/operations.rb, line 103
103:       def count(options={})
104:         search(options).size
105:       end
exist?(dn, options={}) click to toggle 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
Also aliased as: exists?
exists?(dn, options={}) click to toggle source
Alias for: exist?
search(options={}, &block) click to toggle 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. "                        "Use :scope instead.")
50:           ActiveSupport::Deprecation.warn(message)
51:           options[:scope] ||= options[:ldap_scope]
52:         end
53:         search_options = {
54:           :base => _base,
55:           :scope => options[:scope] || scope,
56:           :filter => filter,
57:           :limit => options[:limit],
58:           :attributes => options[:attributes],
59:           :sort_by => options[:sort_by] || sort_by,
60:           :order => options[:order] || order,
61:         }
62: 
63:         options[:connection] ||= connection
64:         values = options[:connection].search(search_options) do |dn, attrs|
65:           attributes = {}
66:           attrs.each do |key, _value|
67:             normalized_attr, normalized_value =
68:               normalize_attribute_options(key, _value)
69:             attributes[normalized_attr] ||= []
70:             attributes[normalized_attr].concat(normalized_value)
71:           end
72:           [dn, attributes]
73:         end
74:         values = values.collect {|_value| yield(_value)} if block_given?
75:         values
76:       end

Private Instance Methods

ensure_base(target) click to toggle 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
ensure_dn_attribute(target) click to toggle 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*/, '')
123:       end
ensure_search_attribute(*candidates) click to toggle source
     # File lib/active_ldap/operations.rb, line 116
116:       def ensure_search_attribute(*candidates)
117:         default_search_attribute || "objectClass"
118:       end
extract_options_from_args!(args) click to toggle 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
object_class_filters(classes=nil) click to toggle 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
prepare_search_base(components) click to toggle 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
split_search_value(value) click to toggle 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
truncate_base(target) click to toggle 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
validate_search_options(options) click to toggle 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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.