activeldap 1.0.2 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +32 -0
- data/README +8 -1
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/app/controllers/{application.rb → application_controller.rb} +3 -1
- data/examples/al-admin/app/views/account/sign_up.html.erb +6 -5
- data/examples/al-admin/config/boot.rb +1 -0
- data/examples/al-admin/config/environment.rb +4 -2
- data/examples/al-admin/config.ru +7 -0
- data/examples/al-admin/lib/ldap_test_helper.rb +38 -0
- data/examples/al-admin/lib/tasks/gettext.rake +3 -2
- data/examples/al-admin/lib/tasks/testing.rake +10 -0
- data/examples/al-admin/po/en/al-admin.po +4 -4
- data/examples/al-admin/po/ja/al-admin.po +4 -4
- data/examples/al-admin/po/nl/al-admin.po +3 -3
- data/examples/al-admin/public/dispatch.cgi +2 -2
- data/examples/al-admin/public/dispatch.fcgi +1 -1
- data/examples/al-admin/public/dispatch.rb +2 -2
- data/examples/al-admin/test/functional/account_controller_test.rb +2 -14
- data/examples/al-admin/test/functional/attributes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/directory_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/object_classes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/syntaxes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/users_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/welcome_controller_test.rb +2 -12
- data/examples/al-admin/test/integration/sign_up_test.rb +44 -0
- data/examples/al-admin/test/run-test.sh +1 -1
- data/examples/al-admin/test/test_helper.rb +25 -1
- data/examples/al-admin/test/unit/user_test.rb +1 -2
- data/examples/groupadd +2 -2
- data/examples/groupdel +2 -2
- data/examples/groupls +2 -2
- data/examples/groupmod +2 -2
- data/examples/lpasswd +2 -2
- data/examples/objects/group.rb +2 -2
- data/examples/objects/user.rb +1 -1
- data/examples/ouadd +2 -2
- data/examples/useradd +2 -2
- data/examples/useradd-binary +6 -3
- data/examples/userdel +2 -2
- data/examples/userls +2 -2
- data/examples/usermod +2 -2
- data/examples/usermod-binary-add +6 -3
- data/examples/usermod-binary-add-time +6 -3
- data/examples/usermod-binary-del +2 -2
- data/examples/usermod-lang-add +2 -2
- data/lib/active_ldap/adapter/base.rb +47 -23
- data/lib/active_ldap/adapter/jndi.rb +30 -28
- data/lib/active_ldap/adapter/jndi_connection.rb +6 -0
- data/lib/active_ldap/adapter/ldap.rb +25 -26
- data/lib/active_ldap/adapter/net_ldap.rb +28 -33
- data/lib/active_ldap/adapter/net_ldap_ext.rb +0 -6
- data/lib/active_ldap/association/proxy.rb +2 -1
- data/lib/active_ldap/attributes.rb +31 -0
- data/lib/active_ldap/base.rb +75 -31
- data/lib/active_ldap/compatible.rb +44 -0
- data/lib/active_ldap/configuration.rb +3 -3
- data/lib/active_ldap/connection.rb +41 -12
- data/lib/active_ldap/distinguished_name.rb +1 -0
- data/lib/active_ldap/get_text.rb +0 -7
- data/lib/active_ldap/ldif.rb +59 -44
- data/lib/active_ldap/operations.rb +41 -10
- data/lib/active_ldap/schema.rb +41 -6
- data/lib/active_ldap/user_password.rb +7 -7
- data/lib/active_ldap/validations.rb +24 -12
- data/lib/active_ldap/xml.rb +2 -2
- data/lib/active_ldap.rb +120 -139
- data/po/en/active-ldap.po +5 -5
- data/po/ja/active-ldap.po +5 -5
- data/rails/README +2 -2
- data/rails/init.rb +2 -2
- data/test/al-test-utils.rb +11 -4
- data/test/run-test.rb +6 -2
- data/test/test_associations.rb +4 -4
- data/test/test_attributes.rb +3 -1
- data/test/test_base.rb +75 -15
- data/test/test_base_per_instance.rb +7 -1
- data/test/test_bind.rb +4 -4
- data/test/test_connection.rb +36 -14
- data/test/test_connection_per_class.rb +5 -5
- data/test/test_connection_per_dn.rb +11 -5
- data/test/test_groupadd.rb +2 -2
- data/test/test_groupdel.rb +2 -2
- data/test/test_groupls.rb +1 -1
- data/test/test_groupmod.rb +2 -2
- data/test/test_ldif.rb +11 -1
- data/test/test_schema.rb +38 -2
- data/test/test_syntax.rb +12 -2
- data/test/test_useradd-binary.rb +1 -0
- data/test/test_usermod-binary-add-time.rb +1 -0
- data/test/test_usermod-binary-add.rb +1 -0
- data/test/test_validation.rb +24 -13
- data/test-unit/lib/test/unit/assertions.rb +97 -14
- data/test-unit/lib/test/unit/autorunner.rb +20 -4
- data/test-unit/lib/test/unit/priority.rb +21 -1
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +7 -4
- data/test-unit/test/test_assertions.rb +52 -5
- metadata +10 -14
- data/rails/plugin/active_ldap/README +0 -54
- data/rails/plugin/active_ldap/generators/README +0 -2
- data/rails/plugin/active_ldap/generators/model_active_ldap/USAGE +0 -17
- data/rails/plugin/active_ldap/generators/model_active_ldap/model_active_ldap_generator.rb +0 -70
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/fixtures.yml +0 -11
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/model_active_ldap.rb +0 -3
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/unit_test.rb +0 -10
- data/rails/plugin/active_ldap/generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +0 -7
- data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +0 -20
- data/rails/plugin/active_ldap/init.rb +0 -36
- data/rails_generators/scaffold_al/scaffold_al_generator.rb +0 -20
@@ -21,7 +21,6 @@ module ActiveLdap
|
|
21
21
|
}
|
22
22
|
|
23
23
|
def connect(options={})
|
24
|
-
@bound = false
|
25
24
|
super do |host, port, method|
|
26
25
|
config = {
|
27
26
|
:host => host,
|
@@ -41,11 +40,14 @@ module ActiveLdap
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def unbind(options={})
|
44
|
-
|
43
|
+
super do
|
44
|
+
log("unbind") do
|
45
|
+
@connection.close # Net::LDAP doesn't implement unbind.
|
46
|
+
end
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
def bind(options={})
|
48
|
-
@bound = false
|
49
51
|
begin
|
50
52
|
super
|
51
53
|
rescue Net::LDAP::LdapError
|
@@ -55,16 +57,11 @@ module ActiveLdap
|
|
55
57
|
|
56
58
|
def bind_as_anonymous(options={})
|
57
59
|
super do
|
58
|
-
@bound = false
|
59
60
|
execute(:bind, {:name => "bind: anonymous"}, {:method => :anonymous})
|
60
|
-
|
61
|
+
true
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
64
|
-
def bound?
|
65
|
-
connecting? and @bound
|
66
|
-
end
|
67
|
-
|
68
65
|
def search(options={}, &block)
|
69
66
|
super(options) do |base, scope, filter, attrs, limit, callback|
|
70
67
|
args = {
|
@@ -97,38 +94,38 @@ module ActiveLdap
|
|
97
94
|
end
|
98
95
|
|
99
96
|
def add(dn, entries, options={})
|
100
|
-
super do |
|
97
|
+
super do |_dn, _entries|
|
101
98
|
attributes = {}
|
102
|
-
|
99
|
+
_entries.each do |type, key, attrs|
|
103
100
|
attrs.each do |name, values|
|
104
101
|
attributes[name] = values
|
105
102
|
end
|
106
103
|
end
|
107
|
-
args = {:dn =>
|
104
|
+
args = {:dn => _dn, :attributes => attributes}
|
108
105
|
info = args.dup
|
109
106
|
execute(:add, info, args)
|
110
107
|
end
|
111
108
|
end
|
112
109
|
|
113
110
|
def modify(dn, entries, options={})
|
114
|
-
super do |
|
115
|
-
info = {:dn =>
|
111
|
+
super do |_dn, _entries|
|
112
|
+
info = {:dn => _dn, :attributes => _entries}
|
116
113
|
execute(:modify, info,
|
117
|
-
:dn =>
|
118
|
-
:operations => parse_entries(
|
114
|
+
:dn => _dn,
|
115
|
+
:operations => parse_entries(_entries))
|
119
116
|
end
|
120
117
|
end
|
121
118
|
|
122
119
|
def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
|
123
|
-
super do |
|
120
|
+
super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
|
124
121
|
info = {
|
125
|
-
:name => "modify: RDN",
|
126
|
-
:delete_old_rdn =>
|
122
|
+
:name => "modify: RDN",
|
123
|
+
:dn => _dn, :new_rdn => _new_rdn, :delete_old_rdn => _delete_old_rdn,
|
127
124
|
}
|
128
125
|
execute(:rename, info,
|
129
|
-
:olddn =>
|
130
|
-
:newrdn =>
|
131
|
-
:delete_attributes =>
|
126
|
+
:olddn => _dn,
|
127
|
+
:newrdn => _new_rdn,
|
128
|
+
:delete_attributes => _delete_old_rdn)
|
132
129
|
end
|
133
130
|
end
|
134
131
|
|
@@ -183,24 +180,23 @@ module ActiveLdap
|
|
183
180
|
end
|
184
181
|
|
185
182
|
def sasl_bind(bind_dn, options={})
|
186
|
-
super do |
|
183
|
+
super do |_bind_dn, mechanism, quiet|
|
187
184
|
normalized_mechanism = mechanism.downcase.gsub(/-/, '_')
|
188
185
|
sasl_bind_setup = "sasl_bind_setup_#{normalized_mechanism}"
|
189
186
|
next unless respond_to?(sasl_bind_setup, true)
|
190
187
|
initial_credential, challenge_response =
|
191
|
-
send(sasl_bind_setup,
|
188
|
+
send(sasl_bind_setup, _bind_dn, options)
|
192
189
|
args = {
|
193
190
|
:method => :sasl,
|
194
191
|
:initial_credential => initial_credential,
|
195
192
|
:mechanism => mechanism,
|
196
193
|
:challenge_response => challenge_response,
|
197
194
|
}
|
198
|
-
@bound = false
|
199
195
|
info = {
|
200
|
-
:name => "bind: SASL", :dn =>
|
196
|
+
:name => "bind: SASL", :dn => _bind_dn, :mechanism => mechanism,
|
201
197
|
}
|
202
198
|
execute(:bind, info, args)
|
203
|
-
|
199
|
+
true
|
204
200
|
end
|
205
201
|
end
|
206
202
|
|
@@ -264,15 +260,14 @@ module ActiveLdap
|
|
264
260
|
end
|
265
261
|
|
266
262
|
def simple_bind(bind_dn, options={})
|
267
|
-
super do |
|
263
|
+
super do |_bind_dn, password|
|
268
264
|
args = {
|
269
265
|
:method => :simple,
|
270
|
-
:username =>
|
271
|
-
:password =>
|
266
|
+
:username => _bind_dn,
|
267
|
+
:password => password,
|
272
268
|
}
|
273
|
-
|
274
|
-
|
275
|
-
@bound = true
|
269
|
+
execute(:bind, {:dn => _bind_dn}, args)
|
270
|
+
true
|
276
271
|
end
|
277
272
|
end
|
278
273
|
|
@@ -3,12 +3,13 @@ module ActiveLdap
|
|
3
3
|
class Proxy
|
4
4
|
alias_method :proxy_respond_to?, :respond_to?
|
5
5
|
alias_method :proxy_extend, :extend
|
6
|
+
delegate :to_param, :to => :target
|
6
7
|
|
7
8
|
def initialize(owner, options)
|
8
9
|
@owner = owner
|
9
10
|
@options = options
|
10
|
-
extend(options[:extend]) if options[:extend]
|
11
11
|
reset
|
12
|
+
extend(options[:extend]) if options[:extend]
|
12
13
|
end
|
13
14
|
|
14
15
|
def respond_to?(symbol, include_priv=false)
|
@@ -26,10 +26,41 @@ module ActiveLdap
|
|
26
26
|
value.values.all? {|val| blank_value?(val)}
|
27
27
|
when Array
|
28
28
|
value.all? {|val| blank_value?(val)}
|
29
|
+
when String
|
30
|
+
/\A\s*\z/ =~ value
|
31
|
+
when nil
|
32
|
+
true
|
29
33
|
else
|
30
34
|
value.blank?
|
31
35
|
end
|
32
36
|
end
|
37
|
+
|
38
|
+
def remove_blank_value(value)
|
39
|
+
case value
|
40
|
+
when Hash
|
41
|
+
result = {}
|
42
|
+
value.each do |k, v|
|
43
|
+
result[k] = remove_blank_value(v) || []
|
44
|
+
end
|
45
|
+
result
|
46
|
+
when Array
|
47
|
+
result = []
|
48
|
+
value.each do |v|
|
49
|
+
v = remove_blank_value(v)
|
50
|
+
next if v.nil?
|
51
|
+
result << v
|
52
|
+
end
|
53
|
+
result
|
54
|
+
when String
|
55
|
+
if /\A\s*\z/ =~ value
|
56
|
+
nil
|
57
|
+
else
|
58
|
+
value
|
59
|
+
end
|
60
|
+
else
|
61
|
+
value
|
62
|
+
end
|
63
|
+
end
|
33
64
|
end
|
34
65
|
|
35
66
|
module Normalizable
|
data/lib/active_ldap/base.rb
CHANGED
@@ -44,6 +44,24 @@ module ActiveLdap
|
|
44
44
|
# Multiple entries become lists.
|
45
45
|
# If this isn't read-only then lists become multiple entries, etc.
|
46
46
|
|
47
|
+
class << self
|
48
|
+
include GetTextSupport
|
49
|
+
def const_missing(id)
|
50
|
+
case id
|
51
|
+
when :ConnectionNotEstablished
|
52
|
+
message =
|
53
|
+
_("ActiveLdap::ConnectionNotEstablished has been deprecated " \
|
54
|
+
"since 1.1.0. " \
|
55
|
+
"Please use ActiveLdap::ConnectionNotSetup instead.")
|
56
|
+
ActiveSupport::Deprecation.warn(message)
|
57
|
+
const_set("ConnectionNotEstablished", ConnectionNotSetup)
|
58
|
+
ConnectionNotEstablished
|
59
|
+
else
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
47
65
|
class Error < StandardError
|
48
66
|
include GetTextSupport
|
49
67
|
end
|
@@ -155,13 +173,16 @@ module ActiveLdap
|
|
155
173
|
NEAREST_MARK = "|@|"
|
156
174
|
private
|
157
175
|
def detect_nearest(line, column)
|
158
|
-
|
176
|
+
lines = Compatible.string_to_lines(@ldif).to_a
|
177
|
+
nearest = lines[line - 1] || ""
|
159
178
|
if column - 1 == nearest.size # for JRuby 1.0.2 :<
|
160
179
|
nearest << NEAREST_MARK
|
161
180
|
else
|
162
181
|
nearest[column - 1, 0] = NEAREST_MARK
|
163
182
|
end
|
164
|
-
|
183
|
+
if nearest == NEAREST_MARK
|
184
|
+
nearest = "#{lines[line - 2]}#{nearest}"
|
185
|
+
end
|
165
186
|
nearest
|
166
187
|
end
|
167
188
|
|
@@ -182,7 +203,7 @@ module ActiveLdap
|
|
182
203
|
|
183
204
|
def numbered_ldif
|
184
205
|
return @ldif if @ldif.blank?
|
185
|
-
lines = @ldif
|
206
|
+
lines = Compatible.string_to_lines(@ldif)
|
186
207
|
format = "%#{Math.log10(lines.size).truncate + 1}d: %s"
|
187
208
|
i = 0
|
188
209
|
lines.collect do |line|
|
@@ -207,7 +228,7 @@ module ActiveLdap
|
|
207
228
|
class OperationNotPermitted < Error
|
208
229
|
end
|
209
230
|
|
210
|
-
class
|
231
|
+
class ConnectionNotSetup < Error
|
211
232
|
end
|
212
233
|
|
213
234
|
class AdapterNotSpecified < Error
|
@@ -288,7 +309,6 @@ module ActiveLdap
|
|
288
309
|
end
|
289
310
|
def #{sym}; self.class.#{sym}; end
|
290
311
|
def self.#{sym}=(value); @#{sym} = value; end
|
291
|
-
def #{sym}=(value); self.class.#{sym} = value; end
|
292
312
|
EOS
|
293
313
|
end
|
294
314
|
end
|
@@ -340,13 +360,24 @@ module ActiveLdap
|
|
340
360
|
# search() requests. Be warned.
|
341
361
|
# :retry_on_timeout - whether to reconnect when timeouts occur. Defaults
|
342
362
|
# to true
|
343
|
-
# See lib/configuration.rb for defaults for each option
|
344
|
-
def
|
363
|
+
# See lib/active_ldap/configuration.rb for defaults for each option
|
364
|
+
def setup_connection(config=nil)
|
345
365
|
super
|
346
366
|
ensure_logger
|
347
367
|
nil
|
348
368
|
end
|
349
369
|
|
370
|
+
# establish_connection is deprecated since 1.1.0. Please use
|
371
|
+
# setup_connection() instead.
|
372
|
+
def establish_connection(config=nil)
|
373
|
+
message =
|
374
|
+
_("ActiveLdap::Base.establish_connection has been deprecated " \
|
375
|
+
"since 1.1.0. " \
|
376
|
+
"Please use ActiveLdap::Base.setup_connection instead.")
|
377
|
+
ActiveSupport::Deprecation.warn(message)
|
378
|
+
setup_connection(config)
|
379
|
+
end
|
380
|
+
|
350
381
|
def create(attributes=nil, &block)
|
351
382
|
if attributes.is_a?(Array)
|
352
383
|
attributes.collect {|attrs| create(attrs, &block)}
|
@@ -473,7 +504,7 @@ module ActiveLdap
|
|
473
504
|
end
|
474
505
|
end
|
475
506
|
|
476
|
-
def
|
507
|
+
def self_and_descendants_from_active_ldap
|
477
508
|
klass = self
|
478
509
|
classes = [klass]
|
479
510
|
while klass != klass.base_class
|
@@ -483,11 +514,17 @@ module ActiveLdap
|
|
483
514
|
rescue
|
484
515
|
[self]
|
485
516
|
end
|
486
|
-
|
487
|
-
|
517
|
+
if ActiveRecord::Base.respond_to?(:self_and_descendents_from_active_record)
|
518
|
+
# ActiveRecord 2.2.2 has a typo. :<
|
519
|
+
alias_method(:self_and_descendents_from_active_record,
|
520
|
+
:self_and_descendants_from_active_ldap)
|
521
|
+
else
|
522
|
+
alias_method(:self_and_descendants_from_active_record,
|
523
|
+
:self_and_descendants_from_active_ldap)
|
524
|
+
end
|
488
525
|
|
489
526
|
def human_name(options={})
|
490
|
-
defaults =
|
527
|
+
defaults = self_and_descendants_from_active_ldap.collect do |klass|
|
491
528
|
if klass.name.blank?
|
492
529
|
nil
|
493
530
|
else
|
@@ -563,20 +600,16 @@ module ActiveLdap
|
|
563
600
|
end
|
564
601
|
|
565
602
|
def default_dn_attribute
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
dn_attribute = parent_class.dn_attribute
|
571
|
-
end
|
572
|
-
dn_attribute || "cn"
|
573
|
-
else
|
574
|
-
name.demodulize.underscore
|
603
|
+
dn_attribute = nil
|
604
|
+
parent_class = ancestors[1]
|
605
|
+
if parent_class.respond_to?(:dn_attribute)
|
606
|
+
dn_attribute = parent_class.dn_attribute
|
575
607
|
end
|
608
|
+
dn_attribute || "cn"
|
576
609
|
end
|
577
610
|
|
578
611
|
def default_prefix
|
579
|
-
if name.
|
612
|
+
if name.blank?
|
580
613
|
nil
|
581
614
|
else
|
582
615
|
"ou=#{name.demodulize.pluralize}"
|
@@ -666,7 +699,7 @@ module ActiveLdap
|
|
666
699
|
|
667
700
|
def attribute_present?(name)
|
668
701
|
values = get_attribute(name, true)
|
669
|
-
!values.empty? or values.any? {|x|
|
702
|
+
!values.empty? or values.any? {|x| !(x and x.empty?)}
|
670
703
|
end
|
671
704
|
|
672
705
|
# exist?
|
@@ -863,7 +896,7 @@ module ActiveLdap
|
|
863
896
|
|
864
897
|
def to_xml(options={})
|
865
898
|
options = options.dup
|
866
|
-
options[:root] ||= self.class.name.underscore
|
899
|
+
options[:root] ||= (self.class.name || '').underscore
|
867
900
|
except = options[:except]
|
868
901
|
if except
|
869
902
|
options[:except] = except.collect do |name|
|
@@ -883,7 +916,7 @@ module ActiveLdap
|
|
883
916
|
|
884
917
|
def have_attribute?(name, except=[])
|
885
918
|
real_name = to_real_attribute_name(name)
|
886
|
-
real_name and !except.include?(real_name)
|
919
|
+
!real_name.nil? and !except.include?(real_name)
|
887
920
|
end
|
888
921
|
alias_method :has_attribute?, :have_attribute?
|
889
922
|
|
@@ -930,7 +963,7 @@ module ActiveLdap
|
|
930
963
|
end
|
931
964
|
config = {:bind_dn => dn, :allow_anonymous => false}.merge(config)
|
932
965
|
config[:password_block] ||= block if block_given?
|
933
|
-
|
966
|
+
setup_connection(config)
|
934
967
|
|
935
968
|
before_connection = @connection
|
936
969
|
begin
|
@@ -970,8 +1003,8 @@ module ActiveLdap
|
|
970
1003
|
end.join(",")
|
971
1004
|
end
|
972
1005
|
|
973
|
-
undef_method :base=
|
974
1006
|
def base=(object_local_base)
|
1007
|
+
ensure_update_dn
|
975
1008
|
@dn = nil
|
976
1009
|
@base = object_local_base
|
977
1010
|
end
|
@@ -981,7 +1014,6 @@ module ActiveLdap
|
|
981
1014
|
@scope || scope_of_class
|
982
1015
|
end
|
983
1016
|
|
984
|
-
undef_method :scope=
|
985
1017
|
def scope=(scope)
|
986
1018
|
self.class.validate_scope(scope)
|
987
1019
|
@scope = scope
|
@@ -1061,6 +1093,8 @@ module ActiveLdap
|
|
1061
1093
|
|
1062
1094
|
def initialize_by_ldap_data(dn, attributes)
|
1063
1095
|
init_base
|
1096
|
+
dn = Compatible.convert_to_utf8_encoded_object(dn)
|
1097
|
+
attributes = Compatible.convert_to_utf8_encoded_object(attributes)
|
1064
1098
|
@dn = dn
|
1065
1099
|
@new_entry = false
|
1066
1100
|
@dn_is_base = false
|
@@ -1084,7 +1118,7 @@ module ActiveLdap
|
|
1084
1118
|
obj
|
1085
1119
|
end
|
1086
1120
|
|
1087
|
-
def to_real_attribute_name(name, allow_normalized_name=
|
1121
|
+
def to_real_attribute_name(name, allow_normalized_name=true)
|
1088
1122
|
return name if name.nil?
|
1089
1123
|
if allow_normalized_name
|
1090
1124
|
entry_attribute.normalize(name, allow_normalized_name) ||
|
@@ -1356,8 +1390,12 @@ module ActiveLdap
|
|
1356
1390
|
|
1357
1391
|
next if v == value
|
1358
1392
|
|
1393
|
+
x = value
|
1394
|
+
value = self.class.remove_blank_value(value) || []
|
1395
|
+
next if v == value
|
1396
|
+
|
1359
1397
|
# Create mod entries
|
1360
|
-
if
|
1398
|
+
if self.class.blank_value?(value)
|
1361
1399
|
# Since some types do not have equality matching rules,
|
1362
1400
|
# delete doesn't work
|
1363
1401
|
# Replacing with nothing is equivalent.
|
@@ -1372,7 +1410,11 @@ module ActiveLdap
|
|
1372
1410
|
end
|
1373
1411
|
data.each do |k, v|
|
1374
1412
|
value = v || []
|
1375
|
-
next if ldap_data.has_key?(k)
|
1413
|
+
next if ldap_data.has_key?(k)
|
1414
|
+
|
1415
|
+
value = self.class.remove_blank_value(value) || []
|
1416
|
+
next if self.class.blank_value?(value)
|
1417
|
+
|
1376
1418
|
|
1377
1419
|
# Detect subtypes and account for them
|
1378
1420
|
# REPLACE will function like ADD, but doesn't hit EQUALITY problems
|
@@ -1393,7 +1435,9 @@ module ActiveLdap
|
|
1393
1435
|
oc_value = data['objectClass']
|
1394
1436
|
attributes.push(['objectClass', oc_value])
|
1395
1437
|
data.each do |key, value|
|
1396
|
-
next if
|
1438
|
+
next if key == 'objectClass' or key == dn_attr
|
1439
|
+
value = self.class.remove_blank_value(value)
|
1440
|
+
next if self.class.blank_value?(value)
|
1397
1441
|
|
1398
1442
|
attributes.push([key, value])
|
1399
1443
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveLdap
|
2
|
+
module Compatible
|
3
|
+
module_function
|
4
|
+
if "".respond_to?(:force_encoding)
|
5
|
+
def convert_to_utf8_encoded_object(object)
|
6
|
+
case object
|
7
|
+
when Array
|
8
|
+
object.collect {|element| convert_to_utf8_encoded_object(element)}
|
9
|
+
when Hash
|
10
|
+
encoded = {}
|
11
|
+
object.each do |key, value|
|
12
|
+
key = convert_to_utf8_encoded_object(key)
|
13
|
+
value = convert_to_utf8_encoded_object(value)
|
14
|
+
encoded[key] = value
|
15
|
+
end
|
16
|
+
encoded
|
17
|
+
when String
|
18
|
+
encoded = object.dup
|
19
|
+
encoded.force_encoding("utf-8")
|
20
|
+
encoded = object unless encoded.valid_encoding?
|
21
|
+
encoded
|
22
|
+
else
|
23
|
+
object
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def convert_to_utf8_encoded_object(object)
|
28
|
+
object
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if "".respond_to?(:lines)
|
33
|
+
def string_to_lines(string)
|
34
|
+
string.lines.to_a
|
35
|
+
end
|
36
|
+
else
|
37
|
+
def string_to_lines(string)
|
38
|
+
ary = []
|
39
|
+
string.each_line{|l| ary << l}
|
40
|
+
ary
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -31,14 +31,14 @@ module ActiveLdap
|
|
31
31
|
DEFAULT_CONFIG[:password] = nil
|
32
32
|
DEFAULT_CONFIG[:store_password] = true
|
33
33
|
DEFAULT_CONFIG[:allow_anonymous] = true
|
34
|
-
DEFAULT_CONFIG[:sasl_quiet] =
|
34
|
+
DEFAULT_CONFIG[:sasl_quiet] = true
|
35
35
|
DEFAULT_CONFIG[:try_sasl] = false
|
36
36
|
# See http://www.iana.org/assignments/sasl-mechanisms
|
37
37
|
DEFAULT_CONFIG[:sasl_mechanisms] = ["GSSAPI", "DIGEST-MD5",
|
38
38
|
"CRAM-MD5", "EXTERNAL"]
|
39
39
|
|
40
|
-
DEFAULT_CONFIG[:retry_limit] =
|
41
|
-
DEFAULT_CONFIG[:retry_wait] =
|
40
|
+
DEFAULT_CONFIG[:retry_limit] = 1
|
41
|
+
DEFAULT_CONFIG[:retry_wait] = 1
|
42
42
|
DEFAULT_CONFIG[:timeout] = 0 # in seconds; 0 <= Never timeout
|
43
43
|
# Whether or not to retry on timeouts
|
44
44
|
DEFAULT_CONFIG[:retry_on_timeout] = true
|
@@ -55,7 +55,7 @@ module ActiveLdap
|
|
55
55
|
def clear_active_connection_name
|
56
56
|
@active_connection_name = nil
|
57
57
|
ObjectSpace.each_object(Class) do |klass|
|
58
|
-
if klass < self and !klass.name.
|
58
|
+
if klass < self and !klass.name.blank?
|
59
59
|
klass.instance_variable_set("@active_connection_name", nil)
|
60
60
|
end
|
61
61
|
end
|
@@ -81,9 +81,9 @@ module ActiveLdap
|
|
81
81
|
config = adapter
|
82
82
|
self.connection = instantiate_adapter(config)
|
83
83
|
elsif adapter.nil?
|
84
|
-
raise
|
84
|
+
raise ConnectionNotSetup
|
85
85
|
else
|
86
|
-
|
86
|
+
setup_connection(adapter)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -115,15 +115,15 @@ module ActiveLdap
|
|
115
115
|
def retrieve_connection
|
116
116
|
conn = nil
|
117
117
|
name = active_connection_name
|
118
|
-
raise
|
118
|
+
raise ConnectionNotSetup unless name
|
119
119
|
conn = active_connections[name]
|
120
120
|
if conn.nil?
|
121
121
|
config = configuration(name)
|
122
|
-
raise
|
122
|
+
raise ConnectionNotSetup unless config
|
123
123
|
self.connection = config
|
124
124
|
conn = active_connections[name]
|
125
125
|
end
|
126
|
-
raise
|
126
|
+
raise ConnectionNotSetup if conn.nil?
|
127
127
|
conn
|
128
128
|
end
|
129
129
|
|
@@ -136,12 +136,12 @@ module ActiveLdap
|
|
136
136
|
config = configuration(key)
|
137
137
|
conn = active_connections[key]
|
138
138
|
remove_configuration_by_configuration(config)
|
139
|
-
active_connections.delete_if {|
|
139
|
+
active_connections.delete_if {|_key, value| value == conn}
|
140
140
|
conn.disconnect! if conn
|
141
141
|
config
|
142
142
|
end
|
143
143
|
|
144
|
-
def
|
144
|
+
def setup_connection(config=nil)
|
145
145
|
config = ensure_configuration(config)
|
146
146
|
remove_connection
|
147
147
|
|
@@ -151,6 +151,15 @@ module ActiveLdap
|
|
151
151
|
define_configuration(key, merge_configuration(config))
|
152
152
|
end
|
153
153
|
|
154
|
+
def establish_connection(config=nil)
|
155
|
+
message =
|
156
|
+
_("ActiveLdap::Connection.establish_connection has been deprecated " \
|
157
|
+
"since 1.1.0. " \
|
158
|
+
"Please use ActiveLdap::Connection.setup_connection instead.")
|
159
|
+
ActiveSupport::Deprecation.warn(message)
|
160
|
+
setup_connection(config)
|
161
|
+
end
|
162
|
+
|
154
163
|
# Return the schema object
|
155
164
|
def schema
|
156
165
|
connection.schema
|
@@ -164,7 +173,7 @@ module ActiveLdap
|
|
164
173
|
|
165
174
|
private
|
166
175
|
def active_connection_key(k=self)
|
167
|
-
k.name.
|
176
|
+
k.name.blank? ? k.object_id : k.name
|
168
177
|
end
|
169
178
|
|
170
179
|
def determine_active_connection_name
|
@@ -191,11 +200,22 @@ module ActiveLdap
|
|
191
200
|
end
|
192
201
|
|
193
202
|
def guess_available_adapter
|
194
|
-
Object.respond_to?(:java)
|
203
|
+
if Object.respond_to?(:java)
|
204
|
+
"jndi"
|
205
|
+
else
|
206
|
+
ldap_ldif_path = $LOAD_PATH.find do |path|
|
207
|
+
File.exist?(File.join(path, "ldap", "ldif.rb"))
|
208
|
+
end
|
209
|
+
if ldap_ldif_path
|
210
|
+
"ldap"
|
211
|
+
else
|
212
|
+
"net-ldap"
|
213
|
+
end
|
214
|
+
end
|
195
215
|
end
|
196
216
|
end
|
197
217
|
|
198
|
-
def
|
218
|
+
def setup_connection(config=nil)
|
199
219
|
config = self.class.ensure_configuration(config)
|
200
220
|
config = self.class.configuration.merge(config)
|
201
221
|
config = self.class.merge_configuration(config, self)
|
@@ -204,6 +224,15 @@ module ActiveLdap
|
|
204
224
|
self.class.define_configuration(dn, config)
|
205
225
|
end
|
206
226
|
|
227
|
+
def establish_connection(config=nil)
|
228
|
+
message =
|
229
|
+
_("ActiveLdap::Connection#establish_connection has been deprecated " \
|
230
|
+
"since 1.1.0. " \
|
231
|
+
"Please use ActiveLdap::Connection#setup_connection instead.")
|
232
|
+
ActiveSupport::Deprecation.warn(message)
|
233
|
+
setup_connection(config)
|
234
|
+
end
|
235
|
+
|
207
236
|
def remove_connection
|
208
237
|
self.class.remove_connection(dn)
|
209
238
|
@connection = nil
|
@@ -235,7 +264,7 @@ module ActiveLdap
|
|
235
264
|
config = adapter
|
236
265
|
@connection = self.class.instantiate_adapter(config)
|
237
266
|
else
|
238
|
-
|
267
|
+
setup_connection(adapter)
|
239
268
|
end
|
240
269
|
end
|
241
270
|
|
data/lib/active_ldap/get_text.rb
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
if Object.const_defined?(:GetText)
|
2
|
-
require 'active_record/version'
|
3
|
-
active_record_version = [ActiveRecord::VERSION::MAJOR,
|
4
|
-
ActiveRecord::VERSION::MINOR,
|
5
|
-
ActiveRecord::VERSION::TINY]
|
6
|
-
if (active_record_version <=> [2, 2, 0]) < 0
|
7
|
-
require "gettext/active_record"
|
8
|
-
end
|
9
2
|
ActiveLdap.const_set("GetText", GetText)
|
10
3
|
end
|
11
4
|
|