active_directory 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_directory}
8
- s.version = "1.2.5"
8
+ s.version = "1.3.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-22}
12
+ s.date = %q{2011-02-25}
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 = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/active_directory/container.rb",
27
27
  "lib/active_directory/field_type/binary.rb",
28
28
  "lib/active_directory/field_type/date.rb",
29
+ "lib/active_directory/field_type/dn_array.rb",
29
30
  "lib/active_directory/field_type/password.rb",
30
31
  "lib/active_directory/field_type/timestamp.rb",
31
32
  "lib/active_directory/group.rb",
@@ -32,6 +32,7 @@ require 'active_directory/field_type/password.rb'
32
32
  require 'active_directory/field_type/binary.rb'
33
33
  require 'active_directory/field_type/date.rb'
34
34
  require 'active_directory/field_type/timestamp.rb'
35
+ require 'active_directory/field_type/dn_array.rb'
35
36
 
36
37
  module ActiveDirectory
37
38
 
@@ -47,31 +48,35 @@ module ActiveDirectory
47
48
  @@special_fields = {
48
49
 
49
50
  #All objects in the AD
50
- # :Base => {
51
- # :objectguid => :binary,
52
- # :whencreated => :date,
53
- # :whenchanged => :date
54
- # },
51
+ :Base => {
52
+ :objectguid => :Binary,
53
+ :whencreated => :Date,
54
+ :whenchanged => :Date,
55
+ :memberof => :DnArray,
56
+ },
55
57
 
56
58
  #User objects
57
59
  :User => {
58
- :objectguid => :binary,
59
- :whencreated => :date,
60
- :whenchanged => :date,
61
- :objectsid => :binary,
62
- :msexchmailboxguid => :binary,
63
- :msexchmailboxsecuritydescriptor => :binary,
64
- :lastlogontimestamp => :timestamp,
65
- :pwdlastset => :timestamp,
66
- :accountexpires => :timestamp
60
+ :objectguid => :Binary,
61
+ :whencreated => :Date,
62
+ :whenchanged => :Date,
63
+ :objectsid => :Binary,
64
+ :msexchmailboxguid => :Binary,
65
+ :msexchmailboxsecuritydescriptor => :Binary,
66
+ :lastlogontimestamp => :Timestamp,
67
+ :pwdlastset => :Timestamp,
68
+ :accountexpires => :Timestamp,
69
+ :memberof => :DnArray,
67
70
  },
68
71
 
69
72
  #Group objects
70
73
  :Group => {
71
- :objectguid => :binary,
72
- :whencreated => :date,
73
- :whenchanged => :date,
74
- :objectsid => :binary,
74
+ :objectguid => :Binary,
75
+ :whencreated => :Date,
76
+ :whenchanged => :Date,
77
+ :objectsid => :Binary,
78
+ :memberof => :DnArray,
79
+ :member => :DnArray,
75
80
  },
76
81
  }
77
82
  end
@@ -144,19 +144,35 @@ module ActiveDirectory
144
144
  !@attributes.empty?
145
145
  end
146
146
 
147
+ ##
148
+ # Makes a single filter from a given key and value
149
+ # It will try to encode an array if there is a process for it
150
+ # Otherwise, it will treat it as an or condition
151
+ def self.make_filter(key, value)
152
+ #Join arrays using OR condition
153
+ if value.is_a? Array
154
+ filter = ~NIL_FILTER
155
+
156
+ value.each do |v|
157
+ filter |= Net::LDAP::Filter.eq(key, encode_field(key, v).to_s)
158
+ end
159
+ else
160
+ filter = Net::LDAP::Filter.eq(key, encode_field(key, value).to_s)
161
+ end
162
+
163
+ return filter
164
+ end
165
+
147
166
  def self.make_filter_from_hash(hash) # :nodoc:
148
167
  return NIL_FILTER if hash.nil? || hash.empty?
149
168
 
150
- #I'm sure there's a better way to do this
151
- #Grab the first one, then do the rest
152
- key, value = hash.shift
153
- f = Net::LDAP::Filter.eq(key, encode_field(key, value).to_s)
154
-
169
+ filter = NIL_FILTER
170
+
155
171
  hash.each do |key, value|
156
- f = f & Net::LDAP::Filter.eq(key, encode_field(key, value).to_s)
172
+ filter &= make_filter(key, value)
157
173
  end
158
174
 
159
- return f
175
+ return filter
160
176
  end
161
177
 
162
178
  #
@@ -177,7 +193,7 @@ module ActiveDirectory
177
193
  # method, partial searches are allowed.
178
194
  #
179
195
  # This method always returns an array if the caller specifies
180
- # :all for the search type (first argument). If no results
196
+ # :all for the search e (first argument). If no results
181
197
  # are found, the array will be empty.
182
198
  #
183
199
  # If you call find(:first, ...), you will either get an object
@@ -188,14 +204,17 @@ module ActiveDirectory
188
204
  return false unless connected?
189
205
 
190
206
  options = {
191
- :filter => NIL_FILTER,
207
+ :filter => (args[1].nil?) ? NIL_FILTER : args[1],
192
208
  :in => ''
193
209
  }
194
- options.merge!(:filter => args[1]) unless args[1].nil?
210
+
211
+ #
195
212
  options[:in] = [ options[:in].to_s, @@settings[:base] ].delete_if { |part| part.empty? }.join(",")
213
+
196
214
  if options[:filter].is_a? Hash
197
215
  options[:filter] = make_filter_from_hash(options[:filter])
198
216
  end
217
+
199
218
  options[:filter] = options[:filter] & filter unless self.filter == NIL_FILTER
200
219
 
201
220
  if (args.first == :all)
@@ -411,19 +430,19 @@ module ActiveDirectory
411
430
  # Takes the field name as a parameter
412
431
  def self.get_field_type(name)
413
432
  #Extract class name
433
+ throw "Invalid field name" if name.nil?
414
434
  klass = self.name.include?('::') ? self.name[/.*::(.*)/, 1] : self.name
415
- type = ::ActiveDirectory.special_fields[klass.classify.to_sym][name.to_s.downcase.to_sym]
416
- type.to_s.classify unless type.nil?
435
+ type = ::ActiveDirectory.special_fields[klass.to_sym][name.to_s.downcase.to_sym]
436
+ type.to_s unless type.nil?
417
437
  end
418
438
 
419
- def self.decode_field(name, value)
420
- #Extract class name
439
+ def self.decode_field(name, value) # :nodoc:
421
440
  type = get_field_type name
422
441
  return ::ActiveDirectory::FieldType::const_get(type).decode(value) if !type.nil? and ::ActiveDirectory::FieldType::const_defined? type
423
442
  return value
424
443
  end
425
444
 
426
- def self.encode_field(name, value)
445
+ def self.encode_field(name, value) # :nodoc:
427
446
  type = get_field_type name
428
447
  return ::ActiveDirectory::FieldType::const_get(type).encode(value) if !type.nil? and ::ActiveDirectory::FieldType::const_defined? type
429
448
  return value
@@ -445,7 +464,7 @@ module ActiveDirectory
445
464
  value = value.first if value.kind_of?(Array) && value.size == 1
446
465
  value = value.to_s if value.nil? || value.size == 1
447
466
  return self.class.decode_field(name, value)
448
- rescue NoMethodError
467
+ rescue NoMethodError => e
449
468
  return nil
450
469
  end
451
470
  end
@@ -0,0 +1,39 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class DnArray
24
+ #
25
+ # Encodes an array of objects into a list of dns
26
+ #
27
+ def self.encode(obj_array)
28
+ obj_array.collect { |obj| obj.dn }
29
+ end
30
+
31
+ #
32
+ # Decodes a list of DNs into the objects that they are
33
+ #
34
+ def self.decode(dn_array)
35
+ Base.find( :all, :distinguishedname => dn_array)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -116,7 +116,7 @@ module ActiveDirectory
116
116
  end
117
117
  return @member_users_r
118
118
  else
119
- @member_users_non_r ||= @entry.member.collect { |dn| User.find_by_distinguishedName(dn) }.delete_if { |u| u.nil? }
119
+ @member_users_non_r ||= User.find(:all, :distinguishedname => @entry.member).delete_if { |u| u.nil? }
120
120
  end
121
121
  end
122
122
 
@@ -144,7 +144,7 @@ module ActiveDirectory
144
144
  end
145
145
  return @member_groups_r
146
146
  else
147
- @member_groups_non_r ||= @entry.member.collect { |dn| Group.find_by_distinguishedName(dn) }.delete_if { |g| g.nil? }
147
+ @member_groups_non_r ||= Group.find(:all, :distinguishedname => @entry.member).delete_if { |g| g.nil? }
148
148
  end
149
149
  end
150
150
 
@@ -153,7 +153,7 @@ module ActiveDirectory
153
153
  #
154
154
  def groups
155
155
  return [] if memberOf.nil?
156
- @groups ||= memberOf.collect { |group_dn| Group.find_by_distinguishedName(group_dn) }
156
+ @groups ||= Group.find(:all, :distinguishedname => @entry.memberOf).delete_if { |g| g.nil? }
157
157
  end
158
158
  end
159
159
  end
@@ -75,7 +75,7 @@ module ActiveDirectory
75
75
  # called Marketting, this method would only return the Sales group.
76
76
  #
77
77
  def groups
78
- @groups ||= memberOf.collect { |dn| Group.find_by_distinguishedName(dn) }
78
+ @groups ||= Group.find(:all, :distinguishedname => @entry.memberOf)
79
79
  end
80
80
 
81
81
  #
@@ -84,7 +84,7 @@ module ActiveDirectory
84
84
  #
85
85
  def direct_reports
86
86
  return [] if @entry.directReports.nil?
87
- @direct_reports ||= @entry.directReports.collect { |dn| User.find_by_distinguishedName(dn) }
87
+ @direct_reports ||= User.find(:all, @entry.directReports)
88
88
  end
89
89
 
90
90
  #
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: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 5
10
- version: 1.2.5
8
+ - 3
9
+ - 0
10
+ version: 1.3.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-22 00:00:00 -05:00
18
+ date: 2011-02-25 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -53,6 +53,7 @@ files:
53
53
  - lib/active_directory/container.rb
54
54
  - lib/active_directory/field_type/binary.rb
55
55
  - lib/active_directory/field_type/date.rb
56
+ - lib/active_directory/field_type/dn_array.rb
56
57
  - lib/active_directory/field_type/password.rb
57
58
  - lib/active_directory/field_type/timestamp.rb
58
59
  - lib/active_directory/group.rb