active_directory 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/active_directory.gemspec +2 -2
- data/lib/active_directory/base.rb +74 -5
- data/lib/active_directory/field_type/member_dn_array.rb +5 -2
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/active_directory.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active_directory}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam T Kerr"]
|
12
|
-
s.date = %q{2011-02
|
12
|
+
s.date = %q{2011-03-02}
|
13
13
|
s.description = %q{ActiveDirectory uses Net::LDAP to provide a means of accessing and modifying an Active Directory data store. This is a fork of the activedirectory gem.}
|
14
14
|
s.email = %q{ajrkerr@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,9 @@ module ActiveDirectory
|
|
32
32
|
NIL_FILTER = Net::LDAP::Filter.pres('cn')
|
33
33
|
|
34
34
|
@@ldap = nil
|
35
|
+
@@ldap_connected = false
|
36
|
+
@@caching = false
|
37
|
+
@@cache = {}
|
35
38
|
|
36
39
|
#
|
37
40
|
# Configures the connection for the Ruby/ActiveDirectory library.
|
@@ -88,12 +91,39 @@ module ActiveDirectory
|
|
88
91
|
# This method will try to connect, if we haven't already
|
89
92
|
def self.connected?
|
90
93
|
begin
|
91
|
-
@@ldap.
|
94
|
+
@@ldap_connected ||= @@ldap.bind unless @@ldap.nil?
|
95
|
+
@@ldap_connected
|
92
96
|
rescue Net::LDAP::LdapError => e
|
93
97
|
false
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
101
|
+
##
|
102
|
+
# Check to see if result caching is enabled
|
103
|
+
def self.cache?
|
104
|
+
@@caching
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Clears the cache
|
109
|
+
def self.clear_cache
|
110
|
+
@@cache = {}
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Enable caching for queries against the DN only
|
115
|
+
# This is to prevent membership lookups from hitting the
|
116
|
+
# AD unnecessarilly
|
117
|
+
def self.enable_cache
|
118
|
+
@@caching = true
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Disable caching
|
123
|
+
def self.disable_cache
|
124
|
+
@@caching = false
|
125
|
+
end
|
126
|
+
|
97
127
|
def self.filter # :nodoc:
|
98
128
|
NIL_FILTER
|
99
129
|
end
|
@@ -208,7 +238,9 @@ module ActiveDirectory
|
|
208
238
|
:in => ''
|
209
239
|
}
|
210
240
|
|
211
|
-
|
241
|
+
cached_results = find_cached_results(args[1])
|
242
|
+
return cached_results unless cached_results.nil?
|
243
|
+
|
212
244
|
options[:in] = [ options[:in].to_s, @@settings[:base] ].delete_if { |part| part.empty? }.join(",")
|
213
245
|
|
214
246
|
if options[:filter].is_a? Hash
|
@@ -216,7 +248,7 @@ module ActiveDirectory
|
|
216
248
|
end
|
217
249
|
|
218
250
|
options[:filter] = options[:filter] & filter unless self.filter == NIL_FILTER
|
219
|
-
|
251
|
+
|
220
252
|
if (args.first == :all)
|
221
253
|
find_all(options)
|
222
254
|
elsif (args.first == :first)
|
@@ -226,17 +258,54 @@ module ActiveDirectory
|
|
226
258
|
end
|
227
259
|
end
|
228
260
|
|
261
|
+
##
|
262
|
+
# Filters the cache result by the object type we're looking for
|
263
|
+
#
|
264
|
+
def self.filter_cache_result(result)
|
265
|
+
result.delete_if { |entry| !entry.kind_of? self }
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# Searches the cache and returns the result
|
270
|
+
#
|
271
|
+
def self.find_cached_results(filters)
|
272
|
+
return nil unless cache?
|
273
|
+
|
274
|
+
#Check to see if we're only looking for :distinguishedname
|
275
|
+
if filters.is_a? Hash and filters.keys == [:distinguishedname]
|
276
|
+
#Find keys we're looking up, convert to array
|
277
|
+
dns = filters[:distinguishedname]
|
278
|
+
|
279
|
+
if dns.kind_of? Array
|
280
|
+
#Check to see if all of the results are in teh cache
|
281
|
+
return nil unless (dns & @@cache.keys == dns)
|
282
|
+
|
283
|
+
result = []
|
284
|
+
|
285
|
+
dns.each { |dn| result << @@cache[dn] }
|
286
|
+
|
287
|
+
return filter_cache_result(result) if result.size == dns.size
|
288
|
+
else
|
289
|
+
return @@cache[dns] if @@cache.key? dns and @@cache[dns].is_a? self.class
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
229
294
|
def self.find_all(options)
|
230
295
|
results = []
|
231
296
|
@@ldap.search(:filter => options[:filter], :base => options[:in], :return_result => false) do |entry|
|
232
|
-
|
297
|
+
ad_entry = new(entry)
|
298
|
+
@@cache[ad_entry.dn] = ad_entry
|
299
|
+
results << ad_entry
|
233
300
|
end
|
234
301
|
results
|
235
302
|
end
|
236
303
|
|
237
304
|
def self.find_first(options)
|
238
305
|
@@ldap.search(:filter => options[:filter], :base => options[:in], :return_result => false) do |entry|
|
239
|
-
|
306
|
+
ad_entry = new(entry)
|
307
|
+
@@cache[ad_entry.dn] = ad_entry
|
308
|
+
return ad_entry
|
240
309
|
end
|
241
310
|
end
|
242
311
|
|
@@ -32,8 +32,11 @@ module ActiveDirectory
|
|
32
32
|
# Decodes a list of DNs into the objects that they are
|
33
33
|
#
|
34
34
|
def self.decode(dn_array)
|
35
|
-
#
|
36
|
-
User.find( :all, :distinguishedname => dn_array)
|
35
|
+
# Ensures that the objects are cast correctly
|
36
|
+
users = [User.find( :all, :distinguishedname => dn_array)].flatten
|
37
|
+
groups = [Group.find(:all, :distinguishedname => dn_array)].flatten
|
38
|
+
|
39
|
+
users + groups
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_directory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 1.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam T Kerr
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02
|
18
|
+
date: 2011-03-02 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|