activeldap 4.0.3 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68d1e26bd0a299b5afa18d537f9c0dc973798acb
4
- data.tar.gz: 354eae82bd94b70f77d0f3a62b66ec45cc69afef
3
+ metadata.gz: 4c12549921e8f9d7aa8674add95bc2f48f82afdd
4
+ data.tar.gz: dd5633df0f5fc5ce5241ff4d77545bc243b8becb
5
5
  SHA512:
6
- metadata.gz: 248bab09098603beb4c65c1a4a01461f2330a82a7bc1d65eaca4cd8c1ce393d9a6a7457dd6fbf5e653ca97af5c91b85c3d13c5f92aea487f839b589896f1f1d0
7
- data.tar.gz: 4d502e9d14654390f95c1d2dae264144e28490662dd3739c492b9413b107ba809ceb2aed0b0baa40ae3eb8adcc1b8d9627dad66f4b6701edf5446e986b83625d
6
+ metadata.gz: 8ef5b66f2ece4f6eea6b6c46db97df52e97dd72b3d80e47d4027ed135346780f90de594b3bce5a2cae221d1f186fb3e225627600a8bd786b2326713388064efa
7
+ data.tar.gz: 580ccd4daf6d3625358be6c7ccba2f3a64aee0722dd8e9d7b2bc354c32120915692d42c59287054b1edb6cb37aee42f6b2cacfd4b0d5ead69be200b6e75f2008
data/README.textile CHANGED
@@ -14,7 +14,7 @@ flexible as ActiveRecord, but it is still trivial to define
14
14
  new objects and manipulate them with minimal difficulty.
15
15
 
16
16
  For example and usage - read the
17
- "document":http://ruby-activeldap.rubyforge.org/.
17
+ "document":http://activeldap.github.io/.
18
18
 
19
19
  h2. Prerequisites
20
20
 
@@ -29,8 +29,8 @@ See the above links for installation.
29
29
  JRuby doesn't need to install new library because JRuby
30
30
  has builtin LDAP support. Ruby users need one of them:
31
31
 
32
- * "Ruby/LDAP":http://rubyforge.org/projects/ruby-ldap/
33
- * "Net::LDAP":http://rubyforge.org/projects/net-ldap/
32
+ * "Ruby/LDAP":http://ruby-ldap.sourceforge.net/
33
+ * "Net::LDAP":http://rubyldap.com/
34
34
 
35
35
  See the above links for installation.
36
36
  =:
@@ -1,5 +1,46 @@
1
1
  h1. News
2
2
 
3
+ h2(#release-4-0-4). 4.0.4: 2014-10-11
4
+
5
+ h3. Improvements
6
+
7
+ * Migrated to commit mail mailing list to "Google
8
+ Groups":https://groups.google.com/forum/?hl=ja#!forum/activeldap-commit
9
+ from RubyForge. Thanks to RubyForge! RubyForge was very helpful!
10
+ * Update project homepage URL in README.
11
+ [GitHub#103] [Patch by Adam Whittingham]
12
+ * Removed needless @Enumerable@ inclusion in @ActiveLdap::Base@.
13
+ [GitHub#104] [Patch by Murray Steele]
14
+ * {ActiveLdap::Populate.ensure_base}: Supported ou entry creation in base DN.
15
+ * Added @follow_referrals@ configuration. You can disable auto
16
+ referrals following by specifying @false@. It is useful when you
17
+ can't access referrals.
18
+
19
+ This configuration is enabled by default.
20
+
21
+ This configuration works only with ruby-ldap adapter.
22
+
23
+ [GitHub#99] [Suggested by hadmut]
24
+
25
+ * Supported @bindname@ extension in LDAP URL such as
26
+ @ldap://host/dc=base,dc=name????bindname=cn%3Dadmin%2Cdc%3Dexample%2Cdc%3Dcom%3F@.
27
+
28
+ h3. Fixes
29
+
30
+ * Fixed a bug logging is failed on removing a connection.
31
+ [GitHub#94] [Reported by Francisco Miguel Biete]
32
+ * Fixed homepage URL in RubyGems.
33
+ [GitHub#95] [Patch by Vít Ondruch]
34
+ * Fixed a bug that DN in LDAP URL is used as bind DN not base DN.
35
+
36
+ h3. Thanks
37
+
38
+ * Francisco Miguel Biete
39
+ * Vít Ondruch
40
+ * Adam Whittingham
41
+ * Murray Steele
42
+ * hadmut
43
+
3
44
  h2(#4-0-3). 4.0.3: 2014-05-15
4
45
 
5
46
  h3. Improvements
data/examples/useradd CHANGED
@@ -25,6 +25,8 @@ end
25
25
 
26
26
  ActiveLdap::Base.setup_connection(:password_block => pwb,
27
27
  :allow_anonymous => false)
28
+ ActiveLdap::Populate.ensure_base
29
+ ActiveLdap::Populate.ensure_ou(User.prefix)
28
30
 
29
31
  if User.exists?(name)
30
32
  $stderr.puts("User #{name} already exists.")
@@ -8,13 +8,26 @@ module ActiveLdap
8
8
  class Base
9
9
  include GetTextSupport
10
10
 
11
- VALID_ADAPTER_CONFIGURATION_KEYS = [:host, :port, :method, :timeout,
12
- :retry_on_timeout, :retry_limit,
13
- :retry_wait, :bind_dn, :password,
14
- :password_block, :try_sasl,
15
- :sasl_mechanisms, :sasl_quiet,
16
- :allow_anonymous, :store_password,
17
- :scope, :sasl_options]
11
+ VALID_ADAPTER_CONFIGURATION_KEYS = [
12
+ :host,
13
+ :port,
14
+ :method,
15
+ :timeout,
16
+ :retry_on_timeout,
17
+ :retry_limit,
18
+ :retry_wait,
19
+ :bind_dn,
20
+ :password,
21
+ :password_block,
22
+ :try_sasl,
23
+ :sasl_mechanisms,
24
+ :sasl_quiet,
25
+ :allow_anonymous,
26
+ :store_password,
27
+ :scope,
28
+ :sasl_options,
29
+ :follow_referrals,
30
+ ]
18
31
 
19
32
  @@row_even = true
20
33
 
@@ -24,12 +37,14 @@ module ActiveLdap
24
37
  @bound = false
25
38
  @bind_tried = false
26
39
  @entry_attributes = {}
40
+ @follow_referrals = nil
27
41
  @configuration = configuration.dup
28
42
  @logger = @configuration.delete(:logger)
29
43
  @configuration.assert_valid_keys(VALID_ADAPTER_CONFIGURATION_KEYS)
30
44
  VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
31
45
  instance_variable_set("@#{name}", configuration[name])
32
46
  end
47
+ @follow_referrals = true if @follow_referrals.nil?
33
48
  @instrumenter = ActiveSupport::Notifications.instrumenter
34
49
  end
35
50
 
@@ -246,6 +261,15 @@ module ActiveLdap
246
261
  end
247
262
  end
248
263
 
264
+ def follow_referrals?(options={})
265
+ option_follow_referrals = options[:follow_referrals]
266
+ if option_follow_referrals.nil?
267
+ @follow_referrals
268
+ else
269
+ option_follow_referrals
270
+ end
271
+ end
272
+
249
273
  def prepare_connection(options)
250
274
  end
251
275
 
@@ -658,8 +682,10 @@ module ActiveLdap
658
682
 
659
683
  def log(name, info=nil)
660
684
  result = nil
661
- payload = {:name => name}
662
- payload[:info] = info if info
685
+ payload = {
686
+ :name => name,
687
+ :info => info || {},
688
+ }
663
689
  @instrumenter.instrument("log_info.active_ldap", payload) do
664
690
  result = yield if block_given?
665
691
  end
@@ -189,6 +189,9 @@ module ActiveLdap
189
189
  def prepare_connection(options={})
190
190
  operation(options) do
191
191
  @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
192
+ unless follow_referrals?(options)
193
+ @connection.set_option(LDAP::LDAP_OPT_REFERRALS, 0)
194
+ end
192
195
  end
193
196
  end
194
197
 
@@ -656,8 +656,6 @@ module ActiveLdap
656
656
  self.recommended_classes = []
657
657
  self.excluded_classes = []
658
658
 
659
- include Enumerable
660
-
661
659
  ### All instance methods, etc
662
660
 
663
661
  # new
@@ -1,3 +1,5 @@
1
+ require "English"
2
+ require "cgi"
1
3
  require 'uri'
2
4
  begin
3
5
  require 'uri/ldaps'
@@ -43,6 +45,7 @@ module ActiveLdap
43
45
  DEFAULT_CONFIG[:timeout] = 0 # in seconds; 0 <= Never timeout
44
46
  # Whether or not to retry on timeouts
45
47
  DEFAULT_CONFIG[:retry_on_timeout] = true
48
+ DEFAULT_CONFIG[:follow_referrals] = true
46
49
 
47
50
  DEFAULT_CONFIG[:logger] = nil
48
51
 
@@ -96,7 +99,7 @@ module ActiveLdap
96
99
  def remove_connection_related_configuration(config)
97
100
  config.reject do |key, value|
98
101
  CONNECTION_CONFIGURATION_KEYS.include?(key)
99
- end
102
+ end
100
103
  end
101
104
 
102
105
  def merge_configuration(user_configuration, target=self)
@@ -135,12 +138,49 @@ module ActiveLdap
135
138
  raise ConfigurationError.new(_("not a LDAP URI: %s") % uri.to_s)
136
139
  end
137
140
 
138
- uri_configuration = {:port => uri.port}
139
- uri_configuration[:host] = uri.host if uri.host
140
- uri_configuration[:bind_dn] = uri.dn if uri.dn
141
- uri_configuration[:scope] = uri.scope if uri.scope
142
- uri_configuration[:method] = :ssl if uri.is_a?(URI::LDAPS)
143
- uri_configuration.merge(configuration)
141
+ merger = URIConfigurationMerger.new(uri)
142
+ merger.merge(configuration)
143
+ end
144
+
145
+ class URIConfigurationMerger
146
+ def initialize(uri)
147
+ @uri = uri
148
+ end
149
+
150
+ def merge(configuration)
151
+ uri_configuration = {:port => @uri.port}
152
+ uri_configuration[:host] = @uri.host if @uri.host
153
+ uri_configuration[:base] = @uri.dn if @uri.dn
154
+ extensions = parse_extensions
155
+ bindname_extension = extensions["bindname"]
156
+ if bindname_extension
157
+ uri_configuration[:bind_dn] = bindname_extension[:value]
158
+ uri_configuration[:allow_anonymous] = !bindname_extension[:critical]
159
+ end
160
+ uri_configuration[:scope] = @uri.scope if @uri.scope
161
+ uri_configuration[:method] = :ssl if @uri.is_a?(URI::LDAPS)
162
+ uri_configuration.merge(configuration)
163
+ end
164
+
165
+ private
166
+ def parse_extensions
167
+ extensions = {}
168
+ (@uri.extensions || "").split(",").collect do |extension|
169
+ name, value = extension.split("=", 2)
170
+ case name
171
+ when /\A!/
172
+ critical = true
173
+ name = $POSTMATCH
174
+ else
175
+ critical = false
176
+ end
177
+ extensions[name] = {
178
+ :critical => critical,
179
+ :value => CGI.unescape(value || ""),
180
+ }
181
+ end
182
+ extensions
183
+ end
144
184
  end
145
185
  end
146
186
  end
@@ -23,19 +23,20 @@ module ActiveLdap
23
23
  return unless logger.debug?
24
24
 
25
25
  payload = event.payload
26
+ info = payload[:info] || {}
26
27
  label = payload[:name]
27
- label += ": FAILED" if payload[:info][:exception]
28
+ label += ": FAILED" if info[:exception]
28
29
  name = 'LDAP: %s (%.1fms)' % [label, event.duration]
29
- info = payload[:info].inspect
30
+ inspected_info = info.inspect
30
31
 
31
32
  if odd?
32
33
  name = color(name, CYAN, true)
33
- info = color(info, nil, true)
34
+ inspected_info = color(inspected_info, nil, true)
34
35
  else
35
36
  name = color(name, MAGENTA, true)
36
37
  end
37
38
 
38
- debug " #{name} #{info}"
39
+ debug " #{name} #{inspected_info}"
39
40
  end
40
41
 
41
42
  def odd?
@@ -12,16 +12,27 @@ module ActiveLdap
12
12
  name, value = rdn.to_a[0]
13
13
  prefix = suffixes.join(",")
14
14
  suffixes.unshift("#{name}=#{value}")
15
- next unless name == "dc"
16
15
  begin
17
- ensure_dc(value, prefix, base_class)
16
+ case name.downcase
17
+ when "dc"
18
+ ensure_dc(value, prefix, base_class)
19
+ when "ou"
20
+ ensure_ou(value,
21
+ :base => prefix,
22
+ :base_class => base_class)
23
+ end
18
24
  rescue ActiveLdap::OperationNotPermitted
19
25
  end
20
26
  end
21
27
  end
22
28
 
23
- def ensure_ou(name, base_class=nil)
24
- base_class ||= Base
29
+ def ensure_ou(name, options={})
30
+ if options.is_a?(Class)
31
+ base_class = options
32
+ options = {}
33
+ else
34
+ base_class = options[:base_class] || Base
35
+ end
25
36
  name = name.to_s if name.is_a?(DN)
26
37
  name = name.gsub(/\Aou\s*=\s*/i, '')
27
38
 
@@ -29,6 +40,7 @@ module ActiveLdap
29
40
  ou_class.ldap_mapping(:dn_attribute => "ou",
30
41
  :prefix => "",
31
42
  :classes => ["top", "organizationalUnit"])
43
+ ou_class.base = options[:base]
32
44
  return if ou_class.exist?(name)
33
45
  ou_class.new(name).save!
34
46
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveLdap
2
- VERSION = "4.0.3"
2
+ VERSION = "4.0.4"
3
3
  end
@@ -82,7 +82,7 @@ module AlTestUtils
82
82
  @@certificate = nil
83
83
  def certificate
84
84
  return @@certificate if @@certificate
85
- if File.exists?(certificate_path)
85
+ if File.exist?(certificate_path)
86
86
  @@certificate = read_binary_file(certificate_path)
87
87
  return @@certificate
88
88
  end
data/test/test_base.rb CHANGED
@@ -811,7 +811,7 @@ class TestBase < Test::Unit::TestCase
811
811
  :classes => ["top", "organizationalUnit"])
812
812
  assert_equal(["ou=Groups,#{current_configuration['base']}",
813
813
  "ou=Users,#{current_configuration['base']}"],
814
- ou_class.find(:all).collect(&:dn).sort)
814
+ ou_class.find(:all).collect(&:dn).collect(&:to_s).sort)
815
815
  end
816
816
 
817
817
  def test_ldap_mapping_validation
@@ -6,25 +6,26 @@ class TestConfiguration < Test::Unit::TestCase
6
6
  priority :normal
7
7
  def test_prepare_configuration_with_silent_uri
8
8
  configuration = {
9
- :bind_dn => "cn=admin,dc=example,dc=com",
9
+ :base => "dc=example,dc=com",
10
10
  :password => "secret",
11
- :uri => "ldap://example.com/cn=ignore,dc=me"
11
+ :uri => "ldap://example.com/dc=ignore,dc=me"
12
12
  }
13
13
  prepared_configuration =
14
14
  ActiveLdap::Base.prepare_configuration(configuration)
15
15
  assert_equal({
16
16
  :host => "example.com",
17
17
  :port => 389,
18
- :bind_dn => "cn=admin,dc=example,dc=com",
18
+ :base => "dc=example,dc=com",
19
19
  :password => "secret",
20
20
  },
21
21
  prepared_configuration)
22
22
  end
23
23
 
24
24
  def test_prepare_configuration_with_detailed_uri
25
+ bind_dn = "cn=admin,dc=example,dc=com"
25
26
  configuration = {
26
27
  :host => "example.net",
27
- :uri => "ldaps://example.com/cn=admin,dc=example,dc=com??sub"
28
+ :uri => "ldaps://example.com/dc=example,dc=com??sub??!bindname=#{CGI.escape(bind_dn)}"
28
29
  }
29
30
  prepared_configuration =
30
31
  ActiveLdap::Base.prepare_configuration(configuration)
@@ -32,8 +33,10 @@ class TestConfiguration < Test::Unit::TestCase
32
33
  :host => "example.net",
33
34
  :port => 636,
34
35
  :method => :ssl,
35
- :bind_dn => "cn=admin,dc=example,dc=com",
36
+ :base => "dc=example,dc=com",
36
37
  :scope => "sub",
38
+ :bind_dn => "cn=admin,dc=example,dc=com",
39
+ :allow_anonymous => false,
37
40
  },
38
41
  prepared_configuration)
39
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Drewry
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2014-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -326,7 +326,7 @@ files:
326
326
  - test/test_usermod-lang-add.rb
327
327
  - test/test_usermod.rb
328
328
  - test/test_validation.rb
329
- homepage: http://ruby-activeldap.rubyforge.org/
329
+ homepage: http://activeldap.github.io/
330
330
  licenses:
331
331
  - Ruby's
332
332
  - GPLv2 or later