dm-ldap-adapter 0.4.3-java
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/History.txt +75 -0
- data/MIT-LICENSE +20 -0
- data/README.md +247 -0
- data/ldap-commands.txt +17 -0
- data/lib/adapters/ldap_adapter.rb +370 -0
- data/lib/adapters/noop_transaction.rb +35 -0
- data/lib/dm-ldap-adapter.rb +1 -0
- data/lib/dummy_ldap_resource.rb +60 -0
- data/lib/ldap/array.rb +122 -0
- data/lib/ldap/conditions_2_filter.rb +95 -0
- data/lib/ldap/digest.rb +30 -0
- data/lib/ldap/net_ldap_facade.rb +161 -0
- data/lib/ldap/ruby_ldap_facade.rb +201 -0
- data/lib/ldap/transactions.rb +2 -0
- data/lib/ldap/unboundid_ldap_facade.rb +188 -0
- data/lib/ldap/version.rb +3 -0
- data/lib/ldap_resource.rb +189 -0
- data/spec/assiociations_ldap_adapter_spec.rb +179 -0
- data/spec/authentication_ldap_adapter_spec.rb +32 -0
- data/spec/contact.rb +58 -0
- data/spec/ldap_adapter_spec.rb +239 -0
- data/spec/ldap_array_spec.rb +119 -0
- data/spec/multi_repository_spec.rb +79 -0
- data/spec/multi_value_attributes_spec.rb +161 -0
- data/spec/performance_spec.rb.omit +67 -0
- data/spec/sorting_spec.rb +61 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +163 -0
- metadata +354 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
$LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
|
2
|
+
|
3
|
+
require 'ldap/array'
|
4
|
+
require 'dm-migrations'
|
5
|
+
require 'dm-sqlite-adapter'
|
6
|
+
|
7
|
+
class A
|
8
|
+
|
9
|
+
include DataMapper::Resource
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
property :list, ::Ldap::LdapArray, :accessor => :public
|
13
|
+
property :hidden_list, ::Ldap::LdapArray, :accessor => :private
|
14
|
+
property :write_list, ::Ldap::LdapArray, :reader => :private, :writer => :public
|
15
|
+
property :read_list, ::Ldap::LdapArray, :reader => :public, :writer => :private
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'fileutils'
|
19
|
+
FileUtils.mkdir_p("target")
|
20
|
+
DataMapper.setup(:default, 'sqlite3:target/test.sqlite3')
|
21
|
+
DataMapper.finalize
|
22
|
+
DataMapper.auto_migrate!(:default)
|
23
|
+
|
24
|
+
describe Ldap::LdapArray do
|
25
|
+
before { @resource = A.new }
|
26
|
+
|
27
|
+
it 'should create new with array' do
|
28
|
+
@resource.list = ["1", "2"]
|
29
|
+
@resource.dirty?.should be_true
|
30
|
+
@resource.save
|
31
|
+
resource = A.first(:id => @resource.id)
|
32
|
+
resource.list.should == ["1", "2"]
|
33
|
+
resource.list.class.should == Ldap::Array
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have empty array on new resource' do
|
37
|
+
@resource.list << "1"
|
38
|
+
@resource.dirty?.should be_true
|
39
|
+
@resource.save
|
40
|
+
resource = A.first(:id => @resource.id)
|
41
|
+
resource.list.should == ["1"]
|
42
|
+
resource.list.class.should == Ldap::Array
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should save after adding an element' do
|
46
|
+
@resource.list = ["1", "2"]
|
47
|
+
@resource.save
|
48
|
+
@resource.list << "4"
|
49
|
+
@resource.save
|
50
|
+
resource = A.first(:id => @resource.id)
|
51
|
+
resource.list.should == ["1", "2", "4"]
|
52
|
+
resource.list.class.should == Ldap::Array
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should save after changing an element' do
|
56
|
+
@resource.list = ["1", "2"]
|
57
|
+
@resource.save
|
58
|
+
@resource.list[1] = "4"
|
59
|
+
@resource.save
|
60
|
+
resource = A.first(:id => @resource.id)
|
61
|
+
resource.list.should == ["1", "4"]
|
62
|
+
resource.list.class.should == Ldap::Array
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should save after deleting element from list' do
|
66
|
+
@resource.list = ["1", "2"]
|
67
|
+
@resource.save
|
68
|
+
@resource.list.delete("1")
|
69
|
+
@resource.save
|
70
|
+
resource = A.first(:id => @resource.id)
|
71
|
+
resource.list.should == ["2"]
|
72
|
+
resource.list.class.should == Ldap::Array
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when :accessor property is set to :private' do
|
76
|
+
it 'should not create a write accessor' do
|
77
|
+
@resource.should_not respond_to(:hidden_list=)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should not create a reade accessor' do
|
81
|
+
@resource.should_not respond_to(:hidden_list)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when :accessor property is set to :public' do
|
86
|
+
it 'should create a write accessor' do
|
87
|
+
@resource.should respond_to(:list=)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should create a reade accessor' do
|
91
|
+
@resource.should respond_to(:list)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when :writer property is set to :public' do
|
96
|
+
it 'should create a write accessor' do
|
97
|
+
@resource.should respond_to(:write_list=)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when :writer property is set to :private' do
|
102
|
+
it 'should not create a write accessor' do
|
103
|
+
@resource.should_not respond_to(:read_list=)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when :reader property is set to :public' do
|
108
|
+
it 'should create a read accessor' do
|
109
|
+
@resource.should respond_to(:read_list)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when :reader property is set to :private' do
|
114
|
+
it 'should not create a read accessor' do
|
115
|
+
@resource.should_not respond_to(:write_list)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class Order
|
5
|
+
include DataMapper::Resource
|
6
|
+
|
7
|
+
property :id, Serial
|
8
|
+
|
9
|
+
belongs_to :user, :required => false, :repository => :ldap
|
10
|
+
end
|
11
|
+
|
12
|
+
class Order2
|
13
|
+
include DataMapper::Resource
|
14
|
+
|
15
|
+
def self.repository_name
|
16
|
+
:default
|
17
|
+
end
|
18
|
+
|
19
|
+
property :id, Serial
|
20
|
+
|
21
|
+
belongs_to :user, :required => false
|
22
|
+
end
|
23
|
+
|
24
|
+
class User
|
25
|
+
def self.repository_name
|
26
|
+
:ldap
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Order.auto_migrate!(:default)
|
31
|
+
Order2.auto_migrate!(:default)
|
32
|
+
|
33
|
+
describe DataMapper.repository(:ldap).adapter do
|
34
|
+
|
35
|
+
describe 'belongs_to association' do
|
36
|
+
|
37
|
+
before do
|
38
|
+
DataMapper.repository(:ldap) do
|
39
|
+
begin
|
40
|
+
User.all.destroy!
|
41
|
+
@user = User.new(:login => "beige", :name => 'Beige')
|
42
|
+
@user.password = "asd123"
|
43
|
+
@user.save
|
44
|
+
rescue => e
|
45
|
+
puts e.backtrace.join("\n\t")
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
after do
|
52
|
+
DataMapper.repository(:ldap) do
|
53
|
+
@user.destroy
|
54
|
+
end
|
55
|
+
@order.destroy
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should create and load the association' do
|
59
|
+
@order = Order.create
|
60
|
+
@order.user = @user
|
61
|
+
@order.save
|
62
|
+
order = Order.get!(@order.id)
|
63
|
+
DataMapper.repository(:ldap) do
|
64
|
+
order.user.should == @user
|
65
|
+
end
|
66
|
+
end
|
67
|
+
it 'should create and load the association with fixed repositories' do
|
68
|
+
DataMapper.repository(:default) do
|
69
|
+
DataMapper.repository(:ldap) do
|
70
|
+
@order = Order2.create
|
71
|
+
@order.user = @user
|
72
|
+
@order.save
|
73
|
+
order = Order2.get!(@order.id)
|
74
|
+
order.user.should == @user
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class TestContact
|
5
|
+
include DataMapper::Resource
|
6
|
+
|
7
|
+
property :id, Serial, :field => "uidNumber"
|
8
|
+
property :login, String, :field => "uid", :unique_index => true
|
9
|
+
property :hashed_password, String, :field => "userPassword", :lazy => true
|
10
|
+
property :name, String, :field => "cn"
|
11
|
+
property :mail, ::Ldap::LdapArray
|
12
|
+
|
13
|
+
dn_prefix { |contact| "uid=#{contact.login}"}
|
14
|
+
|
15
|
+
treebase "ou=people"
|
16
|
+
|
17
|
+
ldap_properties do |contact|
|
18
|
+
properties = { :objectclass => ["inetOrgPerson", "posixAccount", "shadowAccount"], :loginshell => "/bin/bash", :gidnumber => "10000" }
|
19
|
+
properties[:sn] = "#{contact.name.sub(/.*\ /, "")}"
|
20
|
+
properties[:givenname] = "#{contact.name.sub(/\ .*/, "")}"
|
21
|
+
properties[:homedirectory] = "/home/#{contact.login}"
|
22
|
+
properties
|
23
|
+
end
|
24
|
+
|
25
|
+
def password=(password)
|
26
|
+
attribute_set(:hashed_password, Ldap::Digest.ssha(password, "--#{Time.now}--#{login}--")) if password
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe DataMapper.repository(:ldap).adapter.class do
|
31
|
+
|
32
|
+
describe 'LdapArray' do
|
33
|
+
|
34
|
+
before :each do
|
35
|
+
DataMapper.repository(:ldap) do
|
36
|
+
begin
|
37
|
+
TestContact.all(:login.like => "b%").destroy!
|
38
|
+
@contact = TestContact.new(:login => "beige", :name => 'Beige')
|
39
|
+
@contact.password = "asd123"
|
40
|
+
@contact.save
|
41
|
+
rescue => e
|
42
|
+
puts e.backtrace.join("\n\t")
|
43
|
+
raise e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should add many values to a LdapArray' do
|
49
|
+
DataMapper.repository(:ldap) do
|
50
|
+
@contact.mail.should == []
|
51
|
+
|
52
|
+
@contact.mail = ["email1"]
|
53
|
+
@contact.save
|
54
|
+
end
|
55
|
+
DataMapper.repository(:ldap) do
|
56
|
+
@contact = TestContact.get!(@contact.id)
|
57
|
+
@contact.mail.should == ["email1"]
|
58
|
+
@contact.mail << "email2"
|
59
|
+
@contact.save
|
60
|
+
end
|
61
|
+
DataMapper.repository(:ldap) do
|
62
|
+
@contact = TestContact.get!(@contact.id)
|
63
|
+
@contact.mail.should == ["email1", "email2"]
|
64
|
+
@contact.mail.delete("email1")
|
65
|
+
@contact.save
|
66
|
+
end
|
67
|
+
DataMapper.repository(:ldap) do
|
68
|
+
@contact = TestContact.get!(@contact.id)
|
69
|
+
@contact.mail.should == ["email2"]
|
70
|
+
|
71
|
+
mail = @contact.mail.dup
|
72
|
+
mail.delete("email2")
|
73
|
+
@contact.mail = mail
|
74
|
+
@contact.save
|
75
|
+
end
|
76
|
+
DataMapper.repository(:ldap) do
|
77
|
+
@contact = TestContact.get!(@contact.id)
|
78
|
+
@contact.mail.should == []
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should get an LdapArray on retrieving collection' do
|
83
|
+
DataMapper.repository(:ldap) do
|
84
|
+
@contact.mail.should == []
|
85
|
+
|
86
|
+
@contact.mail = ["email1"]
|
87
|
+
@contact.save
|
88
|
+
end
|
89
|
+
DataMapper.repository(:ldap) do
|
90
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
91
|
+
@contact.mail.should == ["email1"]
|
92
|
+
|
93
|
+
@contact.mail = @contact.mail.dup << "email2"
|
94
|
+
@contact.save
|
95
|
+
end
|
96
|
+
DataMapper.repository(:ldap) do
|
97
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
98
|
+
@contact.mail.should == ["email1", "email2"]
|
99
|
+
|
100
|
+
mail = @contact.mail.dup
|
101
|
+
mail.delete("email1")
|
102
|
+
@contact.mail = mail
|
103
|
+
@contact.save
|
104
|
+
end
|
105
|
+
DataMapper.repository(:ldap) do
|
106
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
107
|
+
@contact.mail.should == ["email2"]
|
108
|
+
|
109
|
+
mail = @contact.mail.dup
|
110
|
+
mail.delete("email2")
|
111
|
+
@contact.mail = mail
|
112
|
+
@contact.save
|
113
|
+
end
|
114
|
+
DataMapper.repository(:ldap) do
|
115
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
116
|
+
@contact.mail.should == []
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should allow to replace the LdapArray' do
|
121
|
+
DataMapper.repository(:ldap) do
|
122
|
+
@contact = TestContact.get(@contact.id)
|
123
|
+
@contact.mail.should == []
|
124
|
+
@contact.mail = ['foo', 'bar']
|
125
|
+
@contact.save
|
126
|
+
end
|
127
|
+
DataMapper.repository(:ldap) do
|
128
|
+
@contact = TestContact.get(@contact.id)
|
129
|
+
@contact.mail.should == ['foo', 'bar']
|
130
|
+
end
|
131
|
+
end
|
132
|
+
it 'should create resource with the LdapArray' do
|
133
|
+
DataMapper.repository(:ldap) do
|
134
|
+
@contact = TestContact.new(:login => "black", :name => 'Black')
|
135
|
+
@contact.password = "asd123"
|
136
|
+
@contact.mail = ['foo', 'bar']
|
137
|
+
@contact.save
|
138
|
+
end
|
139
|
+
DataMapper.repository(:ldap) do
|
140
|
+
@contact = TestContact.get(@contact.id)
|
141
|
+
@contact.mail.should == ['foo', 'bar']
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should be able to search properties with LdapArray' do
|
146
|
+
DataMapper.repository(:ldap) do
|
147
|
+
@contact.mail = ["email1"]
|
148
|
+
@contact.save
|
149
|
+
TestContact.all(:mail => "email1").first.should == @contact
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should be able to use multilines with LdapArray' do
|
154
|
+
DataMapper.repository(:ldap) do
|
155
|
+
@contact.mail = ["email1\nmail2\nmail2\nmail4", "email1"]
|
156
|
+
@contact.save
|
157
|
+
TestContact.get(@contact.id).mail.should == ["email1\nmail2\nmail2\nmail4", "email1"]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'contact'
|
4
|
+
|
5
|
+
require 'dm-core/version'
|
6
|
+
p DataMapper::VERSION
|
7
|
+
describe DataMapper.repository(:ldap).adapter do
|
8
|
+
|
9
|
+
describe 'sorting of big list' do
|
10
|
+
|
11
|
+
before do
|
12
|
+
DataMapper.repository(:ldap) do
|
13
|
+
#User.all.destroy!
|
14
|
+
first = 1501
|
15
|
+
len = 1500
|
16
|
+
(first..len).each do |i|
|
17
|
+
p i
|
18
|
+
Contact.create(:id => "login#{i}", :sn => "name#{Kernel.rand}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should load all and sort in timely manner' do
|
24
|
+
expected = nil
|
25
|
+
all = nil
|
26
|
+
|
27
|
+
DataMapper.repository(:ldap) do
|
28
|
+
#puts User.all.collect {|u| u.name }.join("\n")
|
29
|
+
#p User.all.size
|
30
|
+
fields = Contact.properties.defaults.dup.<<(Contact.properties[:mobile])
|
31
|
+
start = Time.new
|
32
|
+
all = Contact.all(:fields => fields)
|
33
|
+
intermediate = Time.new
|
34
|
+
all.each { |a| a.mobile }
|
35
|
+
finished = Time.new
|
36
|
+
|
37
|
+
p intermediate - start
|
38
|
+
p finished - intermediate
|
39
|
+
p finished - start
|
40
|
+
|
41
|
+
end
|
42
|
+
puts
|
43
|
+
DataMapper.repository(:ldap) do
|
44
|
+
#puts User.all.collect {|u| u.name }.join("\n")
|
45
|
+
#p User.all.size
|
46
|
+
fields = Contact.properties.defaults.dup.<<(Contact.properties[:mobile])
|
47
|
+
start = Time.new
|
48
|
+
all = Contact.all(:order => [:sn], :fields => fields)
|
49
|
+
intermediate = Time.new
|
50
|
+
all.each { |a| a.inspect }
|
51
|
+
finished = Time.new
|
52
|
+
expected = all.dup.sort do |u1, u2|
|
53
|
+
u1.sn.upcase <=> u2.sn.upcase
|
54
|
+
end
|
55
|
+
|
56
|
+
p intermediate - start
|
57
|
+
p finished - intermediate
|
58
|
+
p finished - start
|
59
|
+
|
60
|
+
# all.should == expected
|
61
|
+
end
|
62
|
+
#p all#.collect {|u| u.name }.join("\n")
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper.repository(:ldap).adapter do
|
5
|
+
|
6
|
+
describe 'belongs_to association' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
DataMapper.repository(:ldap) do
|
10
|
+
User.all.destroy!
|
11
|
+
@user1 = User.create(:login => "black", :name => 'Black', :mail => ["blackmail@example.com"], :age => 100)
|
12
|
+
@user2 = User.create(:login => "brown", :name => 'brown', :mail => ["brownmail@example.com"], :age => 25)
|
13
|
+
@user3 = User.create(:login => "blue", :name => 'Yellow')
|
14
|
+
@user4 = User.create(:login => "baluh", :name => 'Hmm')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should sort descending without order option' do
|
19
|
+
DataMapper.repository(:ldap) do
|
20
|
+
expected = User.all().sort do |u1, u2|
|
21
|
+
u1.id <=> u2.id
|
22
|
+
end
|
23
|
+
User.all.should == expected
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should sort descending with order option' do
|
28
|
+
DataMapper.repository(:ldap) do
|
29
|
+
expected = User.all().sort do |u1, u2|
|
30
|
+
u1.login <=> u2.login
|
31
|
+
end
|
32
|
+
User.all(:order => [:login]).should == expected
|
33
|
+
end
|
34
|
+
DataMapper.repository(:ldap) do
|
35
|
+
expected = User.all().sort do |u1, u2|
|
36
|
+
-1 * (u1.login <=> u2.login)
|
37
|
+
end
|
38
|
+
User.all(:order => [:login]).reverse.should == expected
|
39
|
+
end
|
40
|
+
end
|
41
|
+
it 'should sort case insensitive with order option' do
|
42
|
+
DataMapper.repository(:ldap) do
|
43
|
+
expected = User.all().sort do |u1, u2|
|
44
|
+
u1.name.upcase <=> u2.name.upcase
|
45
|
+
end
|
46
|
+
User.all(:order => [:name]).should == expected
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should sort with nil values' do
|
51
|
+
DataMapper.repository(:ldap) do
|
52
|
+
users = User.all(:order => [:name]).select { |u| !u.mail.nil? }
|
53
|
+
users.should == [@user1, @user2]
|
54
|
+
end
|
55
|
+
DataMapper.repository(:ldap) do
|
56
|
+
users = User.all(:order => [:name]).reverse.select { |u| !u.mail.nil? }
|
57
|
+
users.should == [@user2, @user1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|