activeldap 1.0.2 → 1.0.9
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/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
data/examples/useradd
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
if User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} already exists.")
|
data/examples/useradd-binary
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
if User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} already exists.")
|
|
@@ -40,7 +40,10 @@ user.gid_number = uid
|
|
|
40
40
|
user.home_directory = "/home/#{name}"
|
|
41
41
|
user.add_class('strongAuthenticationUser')
|
|
42
42
|
cert_file = File.join(File.dirname(__FILE__), 'example.der')
|
|
43
|
-
|
|
43
|
+
File.open(cert_file) do |input|
|
|
44
|
+
input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
|
|
45
|
+
user.user_certificate = input.read
|
|
46
|
+
end
|
|
44
47
|
|
|
45
48
|
unless user.save
|
|
46
49
|
puts "failed"
|
data/examples/userdel
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
data/examples/userls
CHANGED
|
@@ -25,8 +25,8 @@ pwb = Proc.new do |user|
|
|
|
25
25
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
ActiveLdap::Base.
|
|
29
|
-
|
|
28
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
29
|
+
:allow_anonymous => false)
|
|
30
30
|
|
|
31
31
|
unless User.exists?(name)
|
|
32
32
|
$stderr.puts("User #{name} doesn't exist.")
|
data/examples/usermod
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
data/examples/usermod-binary-add
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
|
@@ -38,7 +38,10 @@ user.gid_number = uid
|
|
|
38
38
|
|
|
39
39
|
user.add_class('strongAuthenticationUser')
|
|
40
40
|
cert_file = File.join(File.dirname(__FILE__), 'example.der')
|
|
41
|
-
|
|
41
|
+
File.open(cert_file) do |input|
|
|
42
|
+
input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
|
|
43
|
+
user.user_certificate = input.read
|
|
44
|
+
end
|
|
42
45
|
|
|
43
46
|
unless user.save
|
|
44
47
|
puts "failed"
|
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
|
@@ -39,7 +39,10 @@ end
|
|
|
39
39
|
|
|
40
40
|
user.add_class('strongAuthenticationUser')
|
|
41
41
|
cert_file = File.join(File.dirname(__FILE__), 'example.der')
|
|
42
|
-
|
|
42
|
+
File.open(cert_file) do |input|
|
|
43
|
+
input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
|
|
44
|
+
user.user_certificate = input.read
|
|
45
|
+
end
|
|
43
46
|
|
|
44
47
|
unless user.save
|
|
45
48
|
puts "failed #{i}"
|
data/examples/usermod-binary-del
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
data/examples/usermod-lang-add
CHANGED
|
@@ -23,8 +23,8 @@ pwb = Proc.new do |user|
|
|
|
23
23
|
ActiveLdap::Command.read_password("[#{user}] Password: ")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
ActiveLdap::Base.
|
|
27
|
-
|
|
26
|
+
ActiveLdap::Base.setup_connection(:password_block => pwb,
|
|
27
|
+
:allow_anonymous => false)
|
|
28
28
|
|
|
29
29
|
unless User.exists?(name)
|
|
30
30
|
$stderr.puts("User #{name} doesn't exist.")
|
|
@@ -24,6 +24,8 @@ module ActiveLdap
|
|
|
24
24
|
@runtime = 0
|
|
25
25
|
@connection = nil
|
|
26
26
|
@disconnected = false
|
|
27
|
+
@bound = false
|
|
28
|
+
@bind_tried = false
|
|
27
29
|
@entry_attributes = {}
|
|
28
30
|
@configuration = configuration.dup
|
|
29
31
|
@logger = @configuration.delete(:logger)
|
|
@@ -44,15 +46,17 @@ module ActiveLdap
|
|
|
44
46
|
port = options[:port] || @port || ensure_port(method)
|
|
45
47
|
method = ensure_method(method)
|
|
46
48
|
@disconnected = false
|
|
49
|
+
@bound = false
|
|
50
|
+
@bind_tried = false
|
|
47
51
|
@connection, @uri, @with_start_tls = yield(host, port, method)
|
|
48
52
|
prepare_connection(options)
|
|
49
53
|
bind(options)
|
|
50
54
|
end
|
|
51
55
|
|
|
52
56
|
def disconnect!(options={})
|
|
53
|
-
return if @connection.nil?
|
|
54
57
|
unbind(options)
|
|
55
58
|
@connection = @uri = @with_start_tls = nil
|
|
59
|
+
@disconnected = true
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
def rebind(options={})
|
|
@@ -61,6 +65,8 @@ module ActiveLdap
|
|
|
61
65
|
end
|
|
62
66
|
|
|
63
67
|
def bind(options={})
|
|
68
|
+
@bind_tried = true
|
|
69
|
+
|
|
64
70
|
bind_dn = options[:bind_dn] || @bind_dn
|
|
65
71
|
try_sasl = options.has_key?(:try_sasl) ? options[:try_sasl] : @try_sasl
|
|
66
72
|
if options.has_key?(:allow_anonymous)
|
|
@@ -86,19 +92,27 @@ module ActiveLdap
|
|
|
86
92
|
raise AuthenticationError, message
|
|
87
93
|
end
|
|
88
94
|
|
|
89
|
-
bound
|
|
95
|
+
@bound = true
|
|
96
|
+
@bound
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def unbind(options={})
|
|
100
|
+
yield if @connection and (@bind_tried or bound?)
|
|
101
|
+
@bind_tried = @bound = false
|
|
90
102
|
end
|
|
91
103
|
|
|
92
104
|
def bind_as_anonymous(options={})
|
|
93
|
-
|
|
94
|
-
yield
|
|
95
|
-
end
|
|
105
|
+
yield
|
|
96
106
|
end
|
|
97
107
|
|
|
98
108
|
def connecting?
|
|
99
109
|
!@connection.nil? and !@disconnected
|
|
100
110
|
end
|
|
101
111
|
|
|
112
|
+
def bound?
|
|
113
|
+
connecting? and @bound
|
|
114
|
+
end
|
|
115
|
+
|
|
102
116
|
def schema(options={})
|
|
103
117
|
@schema ||= operation(options) do
|
|
104
118
|
base = options[:base]
|
|
@@ -164,7 +178,6 @@ module ActiveLdap
|
|
|
164
178
|
def delete(targets, options={})
|
|
165
179
|
targets = [targets] unless targets.is_a?(Array)
|
|
166
180
|
return if targets.empty?
|
|
167
|
-
target = nil
|
|
168
181
|
begin
|
|
169
182
|
operation(options) do
|
|
170
183
|
targets.each do |target|
|
|
@@ -293,11 +306,19 @@ module ActiveLdap
|
|
|
293
306
|
end
|
|
294
307
|
|
|
295
308
|
def with_timeout(try_reconnect=true, options={}, &block)
|
|
309
|
+
n_retries = 0
|
|
310
|
+
retry_limit = options[:retry_limit] || @retry_limit
|
|
296
311
|
begin
|
|
297
312
|
Timeout.alarm(@timeout, &block)
|
|
298
313
|
rescue Timeout::Error => e
|
|
299
314
|
@logger.error {_('Requested action timed out.')}
|
|
300
|
-
|
|
315
|
+
if @retry_on_timeout and retry_limit < 0 and n_retries <= retry_limit
|
|
316
|
+
if connecting?
|
|
317
|
+
retry
|
|
318
|
+
elsif try_reconnect
|
|
319
|
+
retry if with_timeout(false, options) {reconnect(options)}
|
|
320
|
+
end
|
|
321
|
+
end
|
|
301
322
|
@logger.error {e.message}
|
|
302
323
|
raise TimeoutError, e.message
|
|
303
324
|
end
|
|
@@ -318,10 +339,7 @@ module ActiveLdap
|
|
|
318
339
|
sasl_mechanisms = options[:sasl_mechanisms] || @sasl_mechanisms
|
|
319
340
|
sasl_mechanisms.each do |mechanism|
|
|
320
341
|
next unless mechanisms.include?(mechanism)
|
|
321
|
-
|
|
322
|
-
yield(bind_dn, mechanism, sasl_quiet)
|
|
323
|
-
return true if bound?
|
|
324
|
-
end
|
|
342
|
+
return true if yield(bind_dn, mechanism, sasl_quiet)
|
|
325
343
|
end
|
|
326
344
|
false
|
|
327
345
|
end
|
|
@@ -343,10 +361,7 @@ module ActiveLdap
|
|
|
343
361
|
end
|
|
344
362
|
|
|
345
363
|
begin
|
|
346
|
-
|
|
347
|
-
yield(bind_dn, passwd)
|
|
348
|
-
bound?
|
|
349
|
-
end
|
|
364
|
+
yield(bind_dn, passwd)
|
|
350
365
|
rescue LdapError::InvalidDnSyntax
|
|
351
366
|
raise DistinguishedNameInvalid.new(bind_dn)
|
|
352
367
|
rescue LdapError::InvalidCredentials
|
|
@@ -484,7 +499,11 @@ module ActiveLdap
|
|
|
484
499
|
s
|
|
485
500
|
else
|
|
486
501
|
s = "*" if s == "**"
|
|
487
|
-
|
|
502
|
+
if s.respond_to?(:getbyte)
|
|
503
|
+
"\\%02X" % s.getbyte(0)
|
|
504
|
+
else
|
|
505
|
+
"\\%02X" % s[0]
|
|
506
|
+
end
|
|
488
507
|
end
|
|
489
508
|
end
|
|
490
509
|
end
|
|
@@ -544,11 +563,6 @@ module ActiveLdap
|
|
|
544
563
|
options[:reconnect_attempts] ||= 0
|
|
545
564
|
|
|
546
565
|
loop do
|
|
547
|
-
unless can_reconnect?(options)
|
|
548
|
-
raise ConnectionError,
|
|
549
|
-
_('Giving up trying to reconnect to LDAP server.')
|
|
550
|
-
end
|
|
551
|
-
|
|
552
566
|
@logger.debug {_('Attempting to reconnect')}
|
|
553
567
|
disconnect!
|
|
554
568
|
|
|
@@ -558,6 +572,8 @@ module ActiveLdap
|
|
|
558
572
|
begin
|
|
559
573
|
connect(options)
|
|
560
574
|
break
|
|
575
|
+
rescue AuthenticationError
|
|
576
|
+
raise
|
|
561
577
|
rescue => detail
|
|
562
578
|
@logger.error do
|
|
563
579
|
_("Reconnect to server failed: %s\n" \
|
|
@@ -568,6 +584,11 @@ module ActiveLdap
|
|
|
568
584
|
raise ConnectionError, detail.message if force
|
|
569
585
|
end
|
|
570
586
|
|
|
587
|
+
unless can_reconnect?(options)
|
|
588
|
+
raise ConnectionError,
|
|
589
|
+
_('Giving up trying to reconnect to LDAP server.')
|
|
590
|
+
end
|
|
591
|
+
|
|
571
592
|
# Sleep before looping
|
|
572
593
|
sleep retry_wait
|
|
573
594
|
end
|
|
@@ -576,7 +597,10 @@ module ActiveLdap
|
|
|
576
597
|
end
|
|
577
598
|
|
|
578
599
|
def reconnect_if_need(options={})
|
|
579
|
-
|
|
600
|
+
return if connecting?
|
|
601
|
+
with_timeout(false, options) do
|
|
602
|
+
reconnect(options)
|
|
603
|
+
end
|
|
580
604
|
end
|
|
581
605
|
|
|
582
606
|
# Determine if we have exceed the retry limit or not.
|
|
@@ -585,7 +609,7 @@ module ActiveLdap
|
|
|
585
609
|
retry_limit = options[:retry_limit] || @retry_limit
|
|
586
610
|
reconnect_attempts = options[:reconnect_attempts] || 0
|
|
587
611
|
|
|
588
|
-
retry_limit < 0 or reconnect_attempts
|
|
612
|
+
retry_limit < 0 or reconnect_attempts <= retry_limit
|
|
589
613
|
end
|
|
590
614
|
|
|
591
615
|
def root_dse_values(key, options={})
|
|
@@ -29,8 +29,7 @@ module ActiveLdap
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def unbind(options={})
|
|
32
|
-
|
|
33
|
-
operation(options) do
|
|
32
|
+
super do
|
|
34
33
|
execute(:unbind)
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -38,13 +37,10 @@ module ActiveLdap
|
|
|
38
37
|
def bind_as_anonymous(options={})
|
|
39
38
|
super do
|
|
40
39
|
execute(:bind_as_anonymous, :name => "bind: anonymous")
|
|
40
|
+
true
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def bound?
|
|
45
|
-
connecting? and @connection.bound?
|
|
46
|
-
end
|
|
47
|
-
|
|
48
44
|
def search(options={}, &block)
|
|
49
45
|
super(options) do |base, scope, filter, attrs, limit, callback|
|
|
50
46
|
info = {
|
|
@@ -63,26 +59,26 @@ module ActiveLdap
|
|
|
63
59
|
end
|
|
64
60
|
|
|
65
61
|
def add(dn, entries, options={})
|
|
66
|
-
super do |
|
|
67
|
-
info = {:dn =>
|
|
68
|
-
execute(:add, info,
|
|
62
|
+
super do |_dn, _entries|
|
|
63
|
+
info = {:dn => _dn, :attributes => _entries}
|
|
64
|
+
execute(:add, info, _dn, parse_entries(_entries))
|
|
69
65
|
end
|
|
70
66
|
end
|
|
71
67
|
|
|
72
68
|
def modify(dn, entries, options={})
|
|
73
|
-
super do |
|
|
74
|
-
info = {:dn =>
|
|
75
|
-
execute(:modify, info,
|
|
69
|
+
super do |_dn, _entries|
|
|
70
|
+
info = {:dn => _dn, :attributes => _entries}
|
|
71
|
+
execute(:modify, info, _dn, parse_entries(_entries))
|
|
76
72
|
end
|
|
77
73
|
end
|
|
78
74
|
|
|
79
75
|
def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
|
|
80
|
-
super do |
|
|
76
|
+
super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
|
|
81
77
|
info = {
|
|
82
|
-
:name => "modify: RDN",
|
|
83
|
-
:delete_old_rdn =>
|
|
78
|
+
:name => "modify: RDN",
|
|
79
|
+
:dn => _dn, :new_rdn => _new_rdn, :delete_old_rdn => _delete_old_rdn,
|
|
84
80
|
}
|
|
85
|
-
execute(:modify_rdn, info,
|
|
81
|
+
execute(:modify_rdn, info, _dn, _new_rdn, _delete_old_rdn)
|
|
86
82
|
end
|
|
87
83
|
end
|
|
88
84
|
|
|
@@ -112,9 +108,9 @@ module ActiveLdap
|
|
|
112
108
|
|
|
113
109
|
def ensure_scope(scope)
|
|
114
110
|
scope_map = {
|
|
115
|
-
:base =>
|
|
116
|
-
:one =>
|
|
117
|
-
:sub =>
|
|
111
|
+
:base => JndiConnection::Scope::OBJECT,
|
|
112
|
+
:one => JndiConnection::Scope::ONE_LEVEL,
|
|
113
|
+
:sub => JndiConnection::Scope::SUBTREE,
|
|
118
114
|
}
|
|
119
115
|
value = scope_map[scope || :sub]
|
|
120
116
|
if value.nil?
|
|
@@ -127,23 +123,29 @@ module ActiveLdap
|
|
|
127
123
|
|
|
128
124
|
def scope_name(scope)
|
|
129
125
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
JndiConnection::Scope::OBJECT => :base,
|
|
127
|
+
JndiConnection::Scope::ONE_LEVEL => :one,
|
|
128
|
+
JndiConnection::Scope::SUBTREE => :sub,
|
|
133
129
|
}[scope]
|
|
134
130
|
end
|
|
135
131
|
|
|
136
132
|
def sasl_bind(bind_dn, options={})
|
|
137
|
-
super do |
|
|
138
|
-
info = {
|
|
139
|
-
|
|
133
|
+
super do |_bind_dn, mechanism, quiet|
|
|
134
|
+
info = {
|
|
135
|
+
:name => "bind: SASL",
|
|
136
|
+
:dn => _bind_dn,
|
|
137
|
+
:mechanism => mechanism
|
|
138
|
+
}
|
|
139
|
+
execute(:sasl_bind, info, _bind_dn, mechanism, quiet)
|
|
140
|
+
true
|
|
140
141
|
end
|
|
141
142
|
end
|
|
142
143
|
|
|
143
144
|
def simple_bind(bind_dn, options={})
|
|
144
|
-
super do |
|
|
145
|
-
info = {:name => "bind", :dn =>
|
|
146
|
-
execute(:simple_bind, info,
|
|
145
|
+
super do |_bind_dn, password|
|
|
146
|
+
info = {:name => "bind", :dn => _bind_dn}
|
|
147
|
+
execute(:simple_bind, info, _bind_dn, password)
|
|
148
|
+
true
|
|
147
149
|
end
|
|
148
150
|
end
|
|
149
151
|
|
|
@@ -29,6 +29,12 @@ module ActiveLdap
|
|
|
29
29
|
NamingException = naming.NamingException
|
|
30
30
|
NameNotFoundException = naming.NameNotFoundException
|
|
31
31
|
|
|
32
|
+
module Scope
|
|
33
|
+
OBJECT = SearchControls::OBJECT_SCOPE
|
|
34
|
+
ONE_LEVEL = SearchControls::ONELEVEL_SCOPE
|
|
35
|
+
SUBTREE = SearchControls::SUBTREE_SCOPE
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
class ModifyRecord
|
|
33
39
|
directory = javax.naming.directory
|
|
34
40
|
DirContext = directory.DirContext
|
|
@@ -61,8 +61,7 @@ module ActiveLdap
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def unbind(options={})
|
|
64
|
-
|
|
65
|
-
operation(options) do
|
|
64
|
+
super do
|
|
66
65
|
execute(:unbind)
|
|
67
66
|
end
|
|
68
67
|
end
|
|
@@ -80,10 +79,6 @@ module ActiveLdap
|
|
|
80
79
|
end
|
|
81
80
|
end
|
|
82
81
|
|
|
83
|
-
def bound?
|
|
84
|
-
connecting? and @connection.bound?
|
|
85
|
-
end
|
|
86
|
-
|
|
87
82
|
def search(options={}, &block)
|
|
88
83
|
super(options) do |base, scope, filter, attrs, limit, callback|
|
|
89
84
|
begin
|
|
@@ -134,40 +129,40 @@ module ActiveLdap
|
|
|
134
129
|
end
|
|
135
130
|
|
|
136
131
|
def add(dn, entries, options={})
|
|
137
|
-
super do |
|
|
132
|
+
super do |_dn, _entries|
|
|
138
133
|
controls = options[:controls]
|
|
139
|
-
attributes = parse_entries(
|
|
140
|
-
info = {:dn =>
|
|
134
|
+
attributes = parse_entries(_entries)
|
|
135
|
+
info = {:dn => _dn, :attributes => _entries}
|
|
141
136
|
if controls
|
|
142
137
|
info.merge!(:name => :add, :controls => controls)
|
|
143
|
-
execute(:add_ext, info,
|
|
138
|
+
execute(:add_ext, info, _dn, attributes, controls, [])
|
|
144
139
|
else
|
|
145
|
-
execute(:add, info,
|
|
140
|
+
execute(:add, info, _dn, attributes)
|
|
146
141
|
end
|
|
147
142
|
end
|
|
148
143
|
end
|
|
149
144
|
|
|
150
145
|
def modify(dn, entries, options={})
|
|
151
|
-
super do |
|
|
146
|
+
super do |_dn, _entries|
|
|
152
147
|
controls = options[:controls]
|
|
153
|
-
attributes = parse_entries(
|
|
154
|
-
info = {:dn =>
|
|
148
|
+
attributes = parse_entries(_entries)
|
|
149
|
+
info = {:dn => _dn, :attributes => _entries}
|
|
155
150
|
if controls
|
|
156
151
|
info.merge!(:name => :modify, :controls => controls)
|
|
157
|
-
execute(:modify_ext, info,
|
|
152
|
+
execute(:modify_ext, info, _dn, attributes, controls, [])
|
|
158
153
|
else
|
|
159
|
-
execute(:modify, info,
|
|
154
|
+
execute(:modify, info, _dn, attributes)
|
|
160
155
|
end
|
|
161
156
|
end
|
|
162
157
|
end
|
|
163
158
|
|
|
164
159
|
def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
|
|
165
|
-
super do |
|
|
160
|
+
super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
|
|
166
161
|
info = {
|
|
167
162
|
:name => "modify: RDN",
|
|
168
|
-
:dn =>
|
|
163
|
+
:dn => _dn, :new_rdn => _new_rdn, :delete_old_rdn => _delete_old_rdn
|
|
169
164
|
}
|
|
170
|
-
execute(:modrdn, info,
|
|
165
|
+
execute(:modrdn, info, _dn, _new_rdn, _delete_old_rdn)
|
|
171
166
|
end
|
|
172
167
|
end
|
|
173
168
|
|
|
@@ -189,8 +184,9 @@ module ActiveLdap
|
|
|
189
184
|
end
|
|
190
185
|
|
|
191
186
|
def ensure_method(method)
|
|
187
|
+
normalized_method = method.to_s.downcase
|
|
192
188
|
Method.constants.each do |name|
|
|
193
|
-
if
|
|
189
|
+
if normalized_method == name.to_s.downcase
|
|
194
190
|
return Method.const_get(name).new
|
|
195
191
|
end
|
|
196
192
|
end
|
|
@@ -226,18 +222,20 @@ module ActiveLdap
|
|
|
226
222
|
end
|
|
227
223
|
|
|
228
224
|
def sasl_bind(bind_dn, options={})
|
|
229
|
-
super do |
|
|
225
|
+
super do |_bind_dn, mechanism, quiet|
|
|
230
226
|
begin
|
|
227
|
+
_bind_dn ||= ''
|
|
231
228
|
sasl_quiet = @connection.sasl_quiet
|
|
232
229
|
@connection.sasl_quiet = quiet unless quiet.nil?
|
|
233
|
-
args = [
|
|
230
|
+
args = [_bind_dn, mechanism]
|
|
234
231
|
if need_credential_sasl_mechanism?(mechanism)
|
|
235
|
-
args << password(
|
|
232
|
+
args << password(_bind_dn, options)
|
|
236
233
|
end
|
|
237
234
|
info = {
|
|
238
|
-
:name => "bind: SASL", :dn =>
|
|
235
|
+
:name => "bind: SASL", :dn => _bind_dn, :mechanism => mechanism
|
|
239
236
|
}
|
|
240
237
|
execute(:sasl_bind, info, *args)
|
|
238
|
+
true
|
|
241
239
|
ensure
|
|
242
240
|
@connection.sasl_quiet = sasl_quiet
|
|
243
241
|
end
|
|
@@ -245,8 +243,9 @@ module ActiveLdap
|
|
|
245
243
|
end
|
|
246
244
|
|
|
247
245
|
def simple_bind(bind_dn, options={})
|
|
248
|
-
super do |
|
|
249
|
-
execute(:bind, {:dn =>
|
|
246
|
+
super do |_bind_dn, password|
|
|
247
|
+
execute(:bind, {:dn => _bind_dn}, _bind_dn, password)
|
|
248
|
+
true
|
|
250
249
|
end
|
|
251
250
|
end
|
|
252
251
|
|