dm-ldap-adapter 0.3.3 → 0.3.4
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/README.txt +25 -8
- data/Rakefile +2 -2
- data/lib/adapters/ldap_adapter.rb +23 -6
- data/lib/ldap/net_ldap_facade.rb +4 -4
- data/lib/ldap/ruby_ldap_facade.rb +5 -5
- data/lib/ldap/version.rb +1 -1
- data/spec/ldap_adapter_spec.rb +1 -0
- data/spec/multi_repository_spec.rb +1 -1
- data/spec/sorting_spec.rb +37 -33
- data/spec/spec_helper.rb +6 -2
- metadata +4 -4
data/README.txt
CHANGED
@@ -16,9 +16,31 @@ the usecase for that implementation was using an ldap server for user authentica
|
|
16
16
|
|
17
17
|
=== low level ldap library
|
18
18
|
|
19
|
-
the ldap library which does the actual ldap protocol stuff is [http://rubyforge.org/projects/net-ldap] which is the default. the other ldap library is [http://rubyforge.org/projects/ruby-ldap].
|
19
|
+
the ldap library which does the actual ldap protocol stuff is [http://rubyforge.org/projects/net-ldap] which is the default. the other ldap library is [http://rubyforge.org/projects/ruby-ldap]. just add a facade parameter when setting up DataMapper
|
20
20
|
|
21
|
-
|
21
|
+
DataMapper.setup(:ldap, {
|
22
|
+
:adapter => 'ldap',
|
23
|
+
:facade => :ruby_ldap,
|
24
|
+
.... })
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
DataMapper.setup(:ldap, {
|
29
|
+
:adapter => 'ldap',
|
30
|
+
:facade => :net_ldap,
|
31
|
+
.... })
|
32
|
+
|
33
|
+
=== setup DataMapper
|
34
|
+
|
35
|
+
DataMapper.setup(:ldap, {
|
36
|
+
:adapter => 'ldap',
|
37
|
+
:host => 'localhost',
|
38
|
+
:port => '389',
|
39
|
+
:base => "dc=example,dc=com",
|
40
|
+
:facade => :ruby_ldap,
|
41
|
+
:bind_name => "cn=admin,dc=example,dc=com",
|
42
|
+
:password => "behappy"
|
43
|
+
})
|
22
44
|
|
23
45
|
=== examples
|
24
46
|
|
@@ -96,12 +118,6 @@ or-conditions can be done with :conditions option but only of the form "<propert
|
|
96
118
|
|
97
119
|
Contact.all(:name.like => "A%", :conditions => ["phone like '+49%' or mobile like '+49%'"])
|
98
120
|
|
99
|
-
=== using the ruby-ldap gem
|
100
|
-
|
101
|
-
just require the right facade before require the adapter:
|
102
|
-
|
103
|
-
require 'ldap/ruby_ldap_facade'
|
104
|
-
|
105
121
|
=== multiple repositories
|
106
122
|
|
107
123
|
most probably you have to work with ldap as one repository and a database as a second repository. for me it worked best to define the `default_repository` for each model in the model itself:
|
@@ -187,6 +203,7 @@ let's say your LDAP has multiple email values for a users then you can define yo
|
|
187
203
|
|
188
204
|
* slf4r the logging facade
|
189
205
|
* net-ldap pure ruby ldap library
|
206
|
+
* ruby-ldap (optional) ruby with native ldap code
|
190
207
|
* logging (optional) if logging via logging is desired
|
191
208
|
* log4r (optional) if logging via log4r is desired
|
192
209
|
|
data/Rakefile
CHANGED
@@ -8,10 +8,10 @@ require 'spec'
|
|
8
8
|
require 'spec/rake/spectask'
|
9
9
|
require 'pathname'
|
10
10
|
|
11
|
-
Hoe.
|
11
|
+
Hoe.spec('dm-ldap-adapter') do |p|
|
12
12
|
p.developer('mkristian', 'm.kristian@web.de')
|
13
13
|
p.url = "http://dm-ldap-adapter.rubyforge.org"
|
14
|
-
p.extra_deps = [['ruby-net-ldap', '=0.0.4'],'slf4r', ['dm-core', '<0.10.0']]
|
14
|
+
p.extra_deps = [['ruby-net-ldap', '=0.0.4'],['slf4r', '>=0'], ['dm-core', '<0.10.0']]
|
15
15
|
p.remote_rdoc_dir = '' # Release to root
|
16
16
|
end
|
17
17
|
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'adapters/simple_adapter'
|
2
|
-
# load the ldap facade only if NOT loaded before
|
3
|
-
require 'ldap/net_ldap_facade' unless Object.const_defined?('Ldap') and Ldap.const_defined?('LdapFacade')
|
4
2
|
|
5
3
|
module Ldap
|
6
4
|
|
@@ -11,6 +9,22 @@ module Ldap
|
|
11
9
|
include ::Slf4r::Logger
|
12
10
|
|
13
11
|
def initialize(uri)
|
12
|
+
if uri[:facade].nil?
|
13
|
+
require 'ldap/net_ldap_facade'
|
14
|
+
@facade = ::Ldap::NetLdapFacade
|
15
|
+
else
|
16
|
+
case uri[:facade].to_sym
|
17
|
+
when :ruby_ldap
|
18
|
+
require 'ldap/ruby_ldap_facade'
|
19
|
+
@facade = ::Ldap::RubyLdapFacade
|
20
|
+
when :net_ldap
|
21
|
+
require 'ldap/net_ldap_facade'
|
22
|
+
@facade = ::Ldap::NetLdapFacade
|
23
|
+
else
|
24
|
+
"please add a :facade parameter to the adapter setup. possible values are :ruby_ldap or net_ldap"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
logger.info("using #{@facade}")
|
14
28
|
@ldaps = { }
|
15
29
|
auth = {
|
16
30
|
:method => :simple,
|
@@ -29,8 +43,8 @@ module Ldap
|
|
29
43
|
# given block.
|
30
44
|
def open
|
31
45
|
begin
|
32
|
-
|
33
|
-
@ldaps[Thread.current] =
|
46
|
+
@facade.open(@config) do |ldap|
|
47
|
+
@ldaps[Thread.current] = @facade.new(ldap)
|
34
48
|
yield
|
35
49
|
end
|
36
50
|
ensure
|
@@ -45,7 +59,7 @@ module Ldap
|
|
45
59
|
if ldap
|
46
60
|
ldap
|
47
61
|
else
|
48
|
-
|
62
|
+
@facade.new(@config)
|
49
63
|
end
|
50
64
|
end
|
51
65
|
end
|
@@ -273,11 +287,14 @@ module DataMapper
|
|
273
287
|
# @see SimpleAdapter#read_resources
|
274
288
|
def read_resources(query)
|
275
289
|
order_by = query.order.first.property.field
|
290
|
+
order_by_sym = order_by.to_sym
|
276
291
|
field_names = query.fields.collect {|f| f.field }
|
277
292
|
result = ldap.read_objects(query.model.treebase,
|
278
293
|
query.model.key.collect { |k| k.field },
|
279
294
|
to_ldap_conditions(query),
|
280
|
-
field_names, order_by)
|
295
|
+
field_names, order_by).sort! do |u1, u2|
|
296
|
+
u1[order_by_sym].first.upcase <=> u2[order_by_sym].first.upcase rescue -1
|
297
|
+
end
|
281
298
|
if query.model.multivalue_field
|
282
299
|
props_result = []
|
283
300
|
result.each do |props|
|
data/lib/ldap/net_ldap_facade.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'net/ldap'
|
2
2
|
|
3
3
|
module Ldap
|
4
|
-
class
|
4
|
+
class NetLdapFacade
|
5
5
|
|
6
6
|
# @param config Hash for the ldap connection
|
7
7
|
def self.open(config)
|
@@ -75,11 +75,11 @@ module Ldap
|
|
75
75
|
when :eql
|
76
76
|
Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s )
|
77
77
|
when :gte
|
78
|
-
|
78
|
+
Net::LDAP::Filter.ge( cc[1].to_s, cc[2].to_s )
|
79
79
|
when :lte
|
80
|
-
|
80
|
+
Net::LDAP::Filter.le( cc[1].to_s, cc[2].to_s )
|
81
81
|
when :like
|
82
|
-
|
82
|
+
Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s.gsub(/%/, "*").gsub(/_/, "*").gsub(/\*\*/, "*") )
|
83
83
|
else
|
84
84
|
logger.error(cc[0].to_s + " needs coding")
|
85
85
|
end
|
@@ -17,7 +17,7 @@ module Ldap
|
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
-
class
|
20
|
+
class RubyLdapFacade
|
21
21
|
|
22
22
|
# @param config Hash for the ldap connection
|
23
23
|
def self.open(config)
|
@@ -95,11 +95,11 @@ module Ldap
|
|
95
95
|
when :eql
|
96
96
|
Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s )
|
97
97
|
when :gte
|
98
|
-
|
98
|
+
Net::LDAP::Filter.ge( cc[1].to_s, cc[2].to_s )
|
99
99
|
when :lte
|
100
|
-
|
100
|
+
Net::LDAP::Filter.le( cc[1].to_s, cc[2].to_s )
|
101
101
|
when :like
|
102
|
-
|
102
|
+
Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s.gsub(/%/, "*").gsub(/_/, "*").gsub(/\*\*/, "*") )
|
103
103
|
else
|
104
104
|
logger.error(cc[0].to_s + " needs coding")
|
105
105
|
end
|
@@ -154,7 +154,7 @@ module Ldap
|
|
154
154
|
end
|
155
155
|
filters << f if f
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
filter = nil
|
159
159
|
filters.each do |f|
|
160
160
|
if filter.nil?
|
data/lib/ldap/version.rb
CHANGED
data/spec/ldap_adapter_spec.rb
CHANGED
@@ -130,6 +130,7 @@ require 'spec_helper'
|
|
130
130
|
User.all(:conditions => ["name like 'Bl%'"]).should == [@user1, @user3]
|
131
131
|
User.all(:conditions => ["name like 'B%'"]).should == [@user1, @user2, @user3]
|
132
132
|
User.all(:conditions => ["name like 'X%X_X'"]).should == []
|
133
|
+
User.all(:conditions => ["name like 'Bla%' or name like 'Br%'"]).should == [@user1, @user2]
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|
data/spec/sorting_spec.rb
CHANGED
@@ -1,47 +1,51 @@
|
|
1
1
|
$LOAD_PATH << File.dirname(__FILE__)
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
describe DataMapper.repository(:ldap).adapter do
|
5
|
+
|
6
|
+
describe 'belongs_to association' do
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@user2 = User.create(:login => "brown", :name => 'Brown', :age => 25)
|
14
|
-
@user3 = User.create(:login => "blue", :name => 'Blue', :age => nil)
|
15
|
-
end
|
8
|
+
before do
|
9
|
+
DataMapper.repository(:ldap) do
|
10
|
+
User.all.destroy!
|
11
|
+
@user1 = User.create(:login => "black", :name => 'Black', :age => 0)
|
12
|
+
@user2 = User.create(:login => "brown", :name => 'brown', :age => 25)
|
13
|
+
@user3 = User.create(:login => "blue", :name => 'Yellow', :age => nil)
|
16
14
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
DataMapper.repository(:ldap) do
|
19
|
+
@user1.destroy
|
20
|
+
@user2.destroy
|
21
|
+
@user3.destroy
|
24
22
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
User.all.should == expected
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should sort descending without order option' do
|
26
|
+
DataMapper.repository(:ldap) do
|
27
|
+
expected = User.all().sort do |u1, u2|
|
28
|
+
u1.id <=> u2.id
|
32
29
|
end
|
30
|
+
User.all.should == expected
|
33
31
|
end
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
it 'should sort descending with order option' do
|
35
|
+
DataMapper.repository(:ldap) do
|
36
|
+
expected = User.all().sort do |u1, u2|
|
37
|
+
u1.login <=> u2.login
|
38
|
+
end
|
39
|
+
User.all(:order => [:login]).should == expected
|
40
|
+
end
|
41
|
+
end
|
42
|
+
it 'should sort case insensitive with order option' do
|
43
|
+
DataMapper.repository(:ldap) do
|
44
|
+
expected = User.all().sort do |u1, u2|
|
45
|
+
u1.name.upcase <=> u2.name.upcase
|
41
46
|
end
|
47
|
+
User.all(:order => [:name]).should == expected
|
42
48
|
end
|
43
49
|
end
|
44
50
|
end
|
45
|
-
else
|
46
|
-
puts 'skip sorting spec for non "ruby-ldap" library'
|
47
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
require 'slf4r/ruby_logger'
|
4
|
-
Slf4r::LoggerFacade4RubyLogger.level =
|
4
|
+
Slf4r::LoggerFacade4RubyLogger.level = :info
|
5
|
+
|
6
|
+
gem 'dm-core', "<0.10.0"
|
7
|
+
gem 'do_sqlite3', "<0.10.0"
|
8
|
+
|
5
9
|
require 'do_sqlite3'
|
6
10
|
require 'pathname'
|
7
11
|
$LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
|
8
12
|
|
9
|
-
#require 'ldap/ruby_ldap_facade'
|
10
13
|
require 'ldap_resource'
|
11
14
|
require 'adapters/ldap_adapter'
|
12
15
|
require 'adapters/memory_adapter'
|
@@ -17,6 +20,7 @@ DataMapper.setup(:ldap, {
|
|
17
20
|
:host => 'localhost',
|
18
21
|
:port => '389',
|
19
22
|
:base => "dc=example,dc=com",
|
23
|
+
:facade => :net_ldap,
|
20
24
|
:bind_name => "cn=admin,dc=example,dc=com",
|
21
25
|
:password => "behappy"
|
22
26
|
})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-ldap-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkristian
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-20 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 2.3.3
|
54
54
|
version:
|
55
55
|
description: ""
|
56
56
|
email:
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
requirements: []
|
120
120
|
|
121
121
|
rubyforge_project: dm-ldap-adapter
|
122
|
-
rubygems_version: 1.3.
|
122
|
+
rubygems_version: 1.3.5
|
123
123
|
signing_key:
|
124
124
|
specification_version: 3
|
125
125
|
summary: ""
|