dm-ldap-adapter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/README.txt +21 -1
- data/Rakefile +2 -1
- data/example/identity_map.rb +2 -3
- data/example/posix.rb +2 -2
- data/lib/adapters/ldap_adapter.rb +76 -28
- data/lib/dummy_ldap_resource.rb +3 -3
- data/lib/ldap/ldap_facade.rb +26 -4
- data/lib/ldap/version.rb +1 -1
- data/lib/ldap_resource.rb +2 -0
- data/spec/authentication_ldap_adapter_spec.rb +1 -1
- data/spec/ldap_adapter_spec.rb +44 -27
- data/spec/spec_helper.rb +17 -27
- metadata +20 -8
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
version 0.3.0
|
2
|
+
=============
|
3
|
+
|
4
|
+
* fixed bug where Serial and Integer,:serial=>true were handled differently. the Integer values are handle with all types which have an Integer as primitive
|
5
|
+
|
6
|
+
* added dm-core gem dependency with version below 0.10.0
|
7
|
+
|
8
|
+
* added LdapArray type for resources which allow the use of the multivalue ldap attriutes
|
9
|
+
|
10
|
+
* allow conditions in queries, but only of the form "<property_name> <comparator> <value> [or <property_name> <comparator> <value>]*" where comparator is one of "=", "like"
|
11
|
+
|
1
12
|
version 0.2.0
|
2
13
|
=============
|
3
14
|
|
data/README.txt
CHANGED
@@ -22,7 +22,7 @@ the ldap library which does the actual ldap protocol stuff is [http://rubyforge.
|
|
22
22
|
|
23
23
|
see 'example/posix.rb' for user/group setup works with default installation of openldap on ubuntu (just change your password as needed in the code)
|
24
24
|
|
25
|
-
the 'example/
|
25
|
+
the 'example/identity_map.rb' shows the usage of identity maps, see also below.
|
26
26
|
|
27
27
|
== FEATURES/PROBLEMS:
|
28
28
|
|
@@ -88,6 +88,8 @@ and
|
|
88
88
|
|
89
89
|
gives the same result when *all* names are `NULL` !!!
|
90
90
|
|
91
|
+
OR conditions can be done with :conditions option but only of the form "<property_name> <comparator> <value> [or <property_name> <comparator> <value>]*" where the comparator is one of "=", "like"
|
92
|
+
|
91
93
|
=== multiple repositories
|
92
94
|
|
93
95
|
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:
|
@@ -151,6 +153,24 @@ staying with posix example there the groups has a memberuid attribute BUT unlike
|
|
151
153
|
|
152
154
|
end
|
153
155
|
|
156
|
+
=== ldap attributes with many values
|
157
|
+
|
158
|
+
let's say your LDAP has multiple email values for a users then you can define your resource class like that using the type LdapArray for such multivalue fields
|
159
|
+
|
160
|
+
class User
|
161
|
+
include DataMapper::Resource
|
162
|
+
property :id, Serial, :field => "uidnumber"
|
163
|
+
property :login, String, :field => "uid", :unique_index => true
|
164
|
+
property :mail, LdapArray
|
165
|
+
|
166
|
+
dn_prefix { |user| "uid=#{user.login}"}
|
167
|
+
treebase "ou=people"
|
168
|
+
ldap_properties do |user|
|
169
|
+
properties = { :objectclass => ["inetOrgPerson", "posixAccount", "shadowAccount"], :loginshell => "/bin/bash", :gidnumber => "10000" }
|
170
|
+
properties
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
154
174
|
== REQUIREMENTS:
|
155
175
|
|
156
176
|
* slf4r the logging facade
|
data/Rakefile
CHANGED
@@ -10,7 +10,8 @@ require 'pathname'
|
|
10
10
|
|
11
11
|
Hoe.new('dm-ldap-adapter', Ldap::VERSION) do |p|
|
12
12
|
p.developer('mkristian', 'm.kristian@web.de')
|
13
|
-
p.
|
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
15
|
p.remote_rdoc_dir = '' # Release to root
|
15
16
|
end
|
16
17
|
|
data/example/identity_map.rb
CHANGED
@@ -55,9 +55,8 @@ end
|
|
55
55
|
DataMapper.repository(USER_REPO) do |repository|
|
56
56
|
repository.adapter.open_ldap_connection do
|
57
57
|
DataMapper.repository(DATA_REPO) do
|
58
|
-
|
59
|
-
|
60
|
-
admin = Group.create(:name => :admin)
|
58
|
+
root = User.first(:login => 'root') || User.create(:id => 0, :login => :root, :name => 'root', :password => 'none') if root.nil?
|
59
|
+
admin = Group.first(:name => 'admin') || Group.create(:name => 'admin')
|
61
60
|
root.groups << admin
|
62
61
|
|
63
62
|
p DataMapper.repository(USER_REPO).identity_map(User)
|
data/example/posix.rb
CHANGED
@@ -45,7 +45,7 @@ end
|
|
45
45
|
class User
|
46
46
|
include DataMapper::Resource
|
47
47
|
|
48
|
-
property :id,
|
48
|
+
property :id, Serial, :field => "uidnumber"
|
49
49
|
property :login, String, :field => "uid"
|
50
50
|
property :hashed_password, String, :field => "userpassword", :access => :private
|
51
51
|
property :name, String, :field => "cn"
|
@@ -95,7 +95,7 @@ end
|
|
95
95
|
class Group
|
96
96
|
include DataMapper::Resource
|
97
97
|
include Slf4r::Logger
|
98
|
-
property :id,
|
98
|
+
property :id, Serial, :field => "gidnumber"
|
99
99
|
property :name, String, :field => "cn"
|
100
100
|
|
101
101
|
dn_prefix { |group| "cn=#{group.name}" }
|
@@ -70,15 +70,32 @@ module DataMapper
|
|
70
70
|
resource.send(:key_properties).first
|
71
71
|
end
|
72
72
|
|
73
|
+
COMPARATORS = { "=" => :eql, ">=" => :gte, "<=" => :lte, "like" => :like }
|
74
|
+
|
73
75
|
# helper to remove datamapper specific classes from the conditions
|
74
76
|
# @param [Array] conditions
|
75
77
|
# array of tuples: (action, property, new value)
|
76
78
|
# @return [Array]
|
77
79
|
# tuples: (action, attribute name, new value)
|
78
|
-
def to_ldap_conditions(
|
80
|
+
def to_ldap_conditions(query)
|
81
|
+
conditions = query.conditions
|
79
82
|
ldap_conditions = []
|
80
83
|
conditions.each do |c|
|
81
|
-
|
84
|
+
if c[0] == :raw
|
85
|
+
props = {}
|
86
|
+
query.fields.each{ |f| props[f.name] = f.field}
|
87
|
+
or_conditions = []
|
88
|
+
c[1].split('or').each do |e|
|
89
|
+
e.strip!
|
90
|
+
match = e.match("=|<=|>=|like")
|
91
|
+
or_conditions << [COMPARATORS[match.values_at(0)[0]],
|
92
|
+
props[match.pre_match.strip.to_sym],
|
93
|
+
match.post_match.strip.gsub(/'/, '')]
|
94
|
+
end
|
95
|
+
ldap_conditions << [:or_operator, or_conditions, nil]
|
96
|
+
else
|
97
|
+
ldap_conditions << [c[0], c[1].field, c[2]]
|
98
|
+
end
|
82
99
|
end
|
83
100
|
ldap_conditions
|
84
101
|
end
|
@@ -102,21 +119,23 @@ module DataMapper
|
|
102
119
|
key = nil
|
103
120
|
resource.send(:properties).each do |prop|
|
104
121
|
value = prop.get!(resource)
|
105
|
-
|
122
|
+
if prop.type == ::DataMapper::Types::LdapArray
|
123
|
+
props[prop.field.to_sym] = value.to_s unless value.nil? or value.size == 0
|
124
|
+
else
|
125
|
+
props[prop.field.to_sym] = value.to_s unless value.nil?
|
126
|
+
end
|
106
127
|
key = prop if prop.serial?
|
107
128
|
end
|
108
129
|
key_value = ldap.create_object(resource.model.dn_prefix(resource),
|
109
130
|
resource.model.treebase,
|
110
131
|
key_properties(resource).field,
|
111
132
|
props, resource.model.multivalue_field)
|
112
|
-
logger.debug { "key value: #{key_value.inspect}" }
|
113
|
-
if key_value
|
114
|
-
key.set!(resource, key_value.to_i)
|
133
|
+
logger.debug { "resource #{resource.inspect} key value: #{key_value.inspect}" + ", multivalue_field: " + resource.model.multivalue_field.to_s }
|
134
|
+
if key_value and !key.nil?
|
135
|
+
key.set!(resource, key_value.to_i)
|
115
136
|
resource
|
116
137
|
elsif resource.model.multivalue_field
|
117
|
-
multivalue_prop = resource.send(:properties).
|
118
|
-
prop.field.to_sym == resource.model.multivalue_field
|
119
|
-
end
|
138
|
+
multivalue_prop = resource.send(:properties)[resource.model.multivalue_field]
|
120
139
|
update_resource(resource,
|
121
140
|
{ multivalue_prop =>
|
122
141
|
resource.send(resource.model.multivalue_field)})
|
@@ -131,24 +150,44 @@ module DataMapper
|
|
131
150
|
# new attributes for the resource
|
132
151
|
# @see SimpleAdapter#update_resource
|
133
152
|
def update_resource(resource, attributes)
|
134
|
-
actions =
|
153
|
+
actions = []
|
154
|
+
attributes.each do |property, value|
|
135
155
|
field = property.field.to_sym #TODO sym needed or string ???
|
136
|
-
if
|
137
|
-
if
|
138
|
-
[:
|
156
|
+
if property.type == ::DataMapper::Types::LdapArray
|
157
|
+
if resource.original_values[property.name].nil?
|
158
|
+
actions << [:add, field, value.to_s]
|
139
159
|
else
|
140
|
-
|
160
|
+
array_actions = []
|
161
|
+
resource.original_values[property.name].each do |ov|
|
162
|
+
unless value.member? ov
|
163
|
+
actions << [:delete, field, ov.to_s]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
value.each do |v|
|
167
|
+
unless resource.original_values[property.name].member? v
|
168
|
+
actions << [:add, field, v.to_s]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
array_actions
|
141
172
|
end
|
142
|
-
elsif value.nil?
|
143
|
-
[:delete, field, []]
|
144
|
-
elsif resource.original_values[property.name].nil?
|
145
|
-
[:add, field, value.to_s]
|
146
173
|
else
|
147
|
-
|
174
|
+
if resource.model.multivalue_field == property.name
|
175
|
+
if value.nil?
|
176
|
+
actions << [:delete, field, resource.original_values[property.name].to_s]
|
177
|
+
else
|
178
|
+
actions << [:add, field, value.to_s]
|
179
|
+
end
|
180
|
+
elsif value.nil?
|
181
|
+
actions << [:delete, field, []]
|
182
|
+
elsif resource.original_values[property.name].nil?
|
183
|
+
actions << [:add, field, value.to_s]
|
184
|
+
else
|
185
|
+
actions << [:replace, field, value.to_s]
|
186
|
+
end
|
148
187
|
end
|
149
188
|
end
|
150
|
-
#puts "actions"
|
151
|
-
#p actions
|
189
|
+
# puts "actions"
|
190
|
+
# p actions
|
152
191
|
#puts
|
153
192
|
ldap.update_object(resource.model.dn_prefix(resource),
|
154
193
|
resource.model.treebase,
|
@@ -176,10 +215,9 @@ module DataMapper
|
|
176
215
|
# the found resource or nil
|
177
216
|
# @see SimpleAdapter#read_resource
|
178
217
|
def read_resource(query)
|
179
|
-
|
180
218
|
result = ldap.read_objects(query.model.treebase,
|
181
219
|
query.model.key.collect { |k| k.field},
|
182
|
-
to_ldap_conditions(query
|
220
|
+
to_ldap_conditions(query))
|
183
221
|
if query.model.multivalue_field
|
184
222
|
resource = result.detect do |item|
|
185
223
|
# run over all values of the multivalue field
|
@@ -188,7 +226,8 @@ module DataMapper
|
|
188
226
|
if query.model.multivalue_field == f.field.to_sym
|
189
227
|
value
|
190
228
|
else
|
191
|
-
item[f.field.to_sym].first
|
229
|
+
val = item[f.field.to_sym].first
|
230
|
+
f.primitive == Integer ? val.to_i : val
|
192
231
|
end
|
193
232
|
end
|
194
233
|
resource = query.model.load(values, query)
|
@@ -199,7 +238,12 @@ module DataMapper
|
|
199
238
|
values = result.first
|
200
239
|
if values
|
201
240
|
query.fields.collect do |f|
|
202
|
-
values[f.field.to_sym]
|
241
|
+
val = values[f.field.to_sym]
|
242
|
+
if f.type == DataMapper::Types::LdapArray
|
243
|
+
val if val
|
244
|
+
elsif val
|
245
|
+
f.primitive == Integer ? val.first.to_i : val.first
|
246
|
+
end
|
203
247
|
end
|
204
248
|
end
|
205
249
|
end
|
@@ -213,7 +257,7 @@ module DataMapper
|
|
213
257
|
def read_resources(query)
|
214
258
|
result = ldap.read_objects(query.model.treebase,
|
215
259
|
query.model.key.collect { |k| k.field },
|
216
|
-
to_ldap_conditions(query
|
260
|
+
to_ldap_conditions(query))
|
217
261
|
if query.model.multivalue_field
|
218
262
|
props_result = []
|
219
263
|
result.each do |props|
|
@@ -223,7 +267,8 @@ module DataMapper
|
|
223
267
|
if query.model.multivalue_field == f.field.to_sym
|
224
268
|
value
|
225
269
|
else
|
226
|
-
props[f.field.to_sym].first
|
270
|
+
prop = props[f.field.to_sym].first
|
271
|
+
f.primitive == Integer ? prop.to_i : prop
|
227
272
|
end
|
228
273
|
end
|
229
274
|
resource = query.model.load(values, query)
|
@@ -234,7 +279,10 @@ module DataMapper
|
|
234
279
|
else # no multivalue field
|
235
280
|
result.collect do |props|
|
236
281
|
query.fields.collect do |f|
|
237
|
-
props[f.field.to_sym]
|
282
|
+
prop = props[f.field.to_sym]
|
283
|
+
if prop
|
284
|
+
f.primitive == Integer ? prop.first.to_i : prop.first
|
285
|
+
end
|
238
286
|
end
|
239
287
|
end
|
240
288
|
end
|
data/lib/dummy_ldap_resource.rb
CHANGED
@@ -22,16 +22,16 @@ module DataMapper
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def treebase(resource = nil)
|
25
|
+
def treebase(resource = nil, &block)
|
26
26
|
if block
|
27
27
|
@treebase = block
|
28
|
-
elsif resource.instance_of?
|
28
|
+
elsif resource.instance_of? String
|
29
29
|
@treebase = resource
|
30
30
|
logger.debug { "treebase=#{@treebase.inspect}" }
|
31
31
|
elsif resource
|
32
32
|
logger.debug { "treebase=#{@treebase.call(resource).inspect}" }
|
33
33
|
else
|
34
|
-
logger.debug { "treebase=#{treebase}" }
|
34
|
+
logger.debug { "treebase=#{@treebase}" }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/ldap/ldap_facade.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'net/ldap'
|
2
|
+
|
2
3
|
module Ldap
|
3
4
|
class LdapFacade
|
4
5
|
|
@@ -38,14 +39,14 @@ module Ldap
|
|
38
39
|
id = max + 1
|
39
40
|
props[id_sym] = "#{id}"
|
40
41
|
if @ldap.add( :dn => dn(dn_prefix, treebase),
|
41
|
-
:attributes => props)
|
42
|
+
:attributes => props) and @ldap.get_operation_result.code.to_s == "0"
|
42
43
|
id
|
43
44
|
else
|
44
45
|
unless silence
|
45
46
|
msg = ldap_error("create",
|
46
47
|
dn(dn_prefix, treebase)) + "\n\t#{props.inspect}"
|
47
48
|
# TODO maybe raise always an error
|
48
|
-
if @ldap.get_operation_result.code == 68
|
49
|
+
if @ldap.get_operation_result.code.to_s == "68"
|
49
50
|
raise ::DataMapper::PersistenceError.new(msg)
|
50
51
|
else
|
51
52
|
logger.warn(msg)
|
@@ -64,6 +65,27 @@ module Ldap
|
|
64
65
|
conditions.each do |cond|
|
65
66
|
c = cond[2]
|
66
67
|
case cond[0]
|
68
|
+
when :or_operator
|
69
|
+
f = nil
|
70
|
+
cond[1].each do |cc|
|
71
|
+
ff = case cc[0]
|
72
|
+
when :eql
|
73
|
+
Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s )
|
74
|
+
when :gte
|
75
|
+
f = Net::LDAP::Filter.ge( cc[1].to_s, cc[2].to_s )
|
76
|
+
when :lte
|
77
|
+
f = Net::LDAP::Filter.le( cc[1].to_s, cc[2].to_s )
|
78
|
+
when :like
|
79
|
+
f = Net::LDAP::Filter.eq( cc[1].to_s, cc[2].to_s.gsub(/%/, "*").gsub(/_/, "*").gsub(/\*\*/, "*") )
|
80
|
+
else
|
81
|
+
logger.error(cc[0].to_s + " needs coding")
|
82
|
+
end
|
83
|
+
if f
|
84
|
+
f = f | ff
|
85
|
+
else
|
86
|
+
f = ff
|
87
|
+
end
|
88
|
+
end
|
67
89
|
when :eql
|
68
90
|
if c.nil?
|
69
91
|
f = ~ Net::LDAP::Filter.pres( cond[1].to_s )
|
@@ -107,7 +129,7 @@ module Ldap
|
|
107
129
|
else
|
108
130
|
logger.error(cond[0].to_s + " needs coding")
|
109
131
|
end
|
110
|
-
filters << f
|
132
|
+
filters << f if f
|
111
133
|
end
|
112
134
|
|
113
135
|
filter = nil
|
data/lib/ldap/version.rb
CHANGED
data/lib/ldap_resource.rb
CHANGED
data/spec/ldap_adapter_spec.rb
CHANGED
@@ -11,7 +11,7 @@ require 'spec_helper'
|
|
11
11
|
|
12
12
|
describe "A #{DataMapper.repository(adapter).adapter.class.name}" do
|
13
13
|
|
14
|
-
before do
|
14
|
+
before(:each) do
|
15
15
|
DataMapper.repository(adapter) do
|
16
16
|
@user1 = User.create(:login => "black", :name => 'Black', :age => 0)
|
17
17
|
@user2 = User.create(:login => "brown", :name => 'Brown', :age => 25)
|
@@ -19,7 +19,7 @@ require 'spec_helper'
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
after do
|
22
|
+
after(:each) do
|
23
23
|
DataMapper.repository(adapter) do
|
24
24
|
@user1.destroy
|
25
25
|
@user2.destroy
|
@@ -36,7 +36,7 @@ require 'spec_helper'
|
|
36
36
|
|
37
37
|
it 'should log when trying to create an entity with already used key' do
|
38
38
|
DataMapper.repository(adapter) do
|
39
|
-
#p User.
|
39
|
+
#p User.first(:login => "black")
|
40
40
|
lambda { User.create(:login => "black", :name => 'Black', :age => 0) }.should raise_error
|
41
41
|
#p User.all
|
42
42
|
end
|
@@ -104,6 +104,23 @@ require 'spec_helper'
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
it 'should search objects with or conditions' do
|
108
|
+
if adapter == :ldap
|
109
|
+
DataMapper.repository(adapter) do
|
110
|
+
User.all(:age.not => nil, :conditions => ["name='Black' or name='Blue'"]).should == [@user1]
|
111
|
+
User.all(:age.not => nil, :conditions => ["name='Black' or name='Brown'"]).should == [@user1, @user2]
|
112
|
+
User.all(:age => nil, :conditions => ["name='Black' or name='Brown'"]).should == []
|
113
|
+
User.all(:age => nil, :conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user3]
|
114
|
+
User.all(:conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user1, @user2, @user3]
|
115
|
+
User.all(:conditions => ["name='Black'"]).should == [@user1]
|
116
|
+
User.all(:conditions => ["name like 'Bl%'"]).should == [@user1, @user3]
|
117
|
+
User.all(:conditions => ["name like 'B%'"]).should == [@user1, @user2, @user3]
|
118
|
+
User.all(:conditions => ["name like 'X%X_X'"]).should == []
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
107
124
|
# it 'should be able to search for objects not included in a range of values' do
|
108
125
|
# User.all(:age.not => 25..100).should == [@user1, @user3]
|
109
126
|
# end
|
@@ -178,36 +195,36 @@ require 'spec_helper'
|
|
178
195
|
end
|
179
196
|
|
180
197
|
if DataMapper.repository(adapter).adapter.respond_to? :open_ldap_connection
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
198
|
+
|
199
|
+
it 'should use one connection for several actions' do
|
200
|
+
DataMapper.repository(adapter) do
|
201
|
+
DataMapper.repository.adapter.open_ldap_connection do
|
202
|
+
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
203
|
+
User.all
|
204
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
205
|
+
user = User.get(@user3.id)
|
206
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
207
|
+
user.name = "another name"
|
208
|
+
user.save
|
209
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
210
|
+
end
|
211
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should use new connection for each action' do
|
216
|
+
DataMapper.repository(adapter) do
|
185
217
|
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
186
218
|
User.all
|
187
|
-
|
219
|
+
|
220
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
188
221
|
user = User.get(@user3.id)
|
189
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.
|
190
|
-
user.name = "another name"
|
222
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
223
|
+
user.name = "yet another name"
|
191
224
|
user.save
|
192
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.
|
225
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
193
226
|
end
|
194
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should use new connection for each action' do
|
199
|
-
DataMapper.repository(adapter) do
|
200
|
-
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
201
|
-
User.all
|
202
|
-
|
203
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
204
|
-
user = User.get(@user3.id)
|
205
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
206
|
-
user.name = "yet another name"
|
207
|
-
user.save
|
208
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
209
227
|
end
|
210
228
|
end
|
211
|
-
end
|
212
229
|
end
|
213
230
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
require 'slf4r/ruby_logger'
|
4
|
-
|
4
|
+
Slf4r::LoggerFacade4RubyLogger.level = ::Logger::DEBUG
|
5
|
+
require 'do_sqlite3'
|
5
6
|
require 'pathname'
|
6
7
|
$LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
|
7
8
|
|
@@ -23,7 +24,7 @@ DataMapper.setup(:memory, {:adapter => 'memory'})
|
|
23
24
|
|
24
25
|
class User
|
25
26
|
include DataMapper::Resource
|
26
|
-
property :id,
|
27
|
+
property :id, Serial, :field => "uidnumber"
|
27
28
|
property :login, String, :field => "uid", :unique_index => true
|
28
29
|
property :hashed_password, String, :field => "userpassword", :access => :private
|
29
30
|
property :name, String, :field => "cn"
|
@@ -31,10 +32,9 @@ class User
|
|
31
32
|
property :age, Integer, :field => "postalcode"
|
32
33
|
property :alive, Boolean, :field => "gecos"
|
33
34
|
|
34
|
-
has n, :roles
|
35
|
+
has n, :roles
|
35
36
|
|
36
|
-
has n, :group_users
|
37
|
-
# has n, :groups, :through => :group_users, :mutable => true#, :child_key => [:gidnumber], :parent_key => [:memberuid]
|
37
|
+
has n, :group_users
|
38
38
|
|
39
39
|
def groups
|
40
40
|
groups = GroupUser.all(:memberuid => id).collect{ |gu| gu.group }
|
@@ -78,35 +78,30 @@ end
|
|
78
78
|
|
79
79
|
class Role
|
80
80
|
include DataMapper::Resource
|
81
|
-
property :id,
|
81
|
+
property :id, Serial, :field => "gidnumber"
|
82
82
|
property :name, String, :field => "cn"
|
83
83
|
|
84
|
-
# multivalue_field "memberuid"
|
85
|
-
|
86
84
|
dn_prefix { |role| "cn=#{role.name}" }
|
87
85
|
|
88
86
|
treebase "ou=groups"
|
89
87
|
|
90
|
-
ldap_properties {
|
88
|
+
ldap_properties {:objectclass => "posixGroup"}
|
91
89
|
|
92
|
-
belongs_to :user
|
90
|
+
belongs_to :user
|
93
91
|
end
|
94
92
|
|
95
93
|
class Group
|
96
94
|
include DataMapper::Resource
|
97
|
-
property :id,
|
95
|
+
property :id, Serial, :field => "gidnumber"
|
98
96
|
property :name, String, :field => "cn"
|
99
97
|
|
100
98
|
dn_prefix { |group| "cn=#{group.name}" }
|
101
99
|
|
102
100
|
treebase "ou=groups"
|
103
101
|
|
104
|
-
ldap_properties {
|
105
|
-
|
106
|
-
has n, :users, :child_key => [:gidnumber]
|
107
|
-
# has n, :users, :through => :group_users
|
102
|
+
ldap_properties {:objectclass => "posixGroup"}
|
108
103
|
end
|
109
|
-
|
104
|
+
|
110
105
|
class GroupUser
|
111
106
|
include DataMapper::Resource
|
112
107
|
|
@@ -120,28 +115,23 @@ class GroupUser
|
|
120
115
|
{:cn=>"#{group_user.group.name}", :objectclass => "posixGroup"}
|
121
116
|
end
|
122
117
|
|
123
|
-
|
124
|
-
|
125
|
-
#property :group_id, Integer, :key => true#, :field => "gidnumber"
|
126
|
-
property :memberuid, Integer, :key => true#, :field => "memberuid"
|
127
|
-
property :gidnumber, Integer, :key => true#, :field => "gidnumber"
|
128
|
-
# belongs_to :group, :child_key => [:gidnumber]
|
118
|
+
property :user_id, Integer, :key => true, :field => "memberuid"
|
119
|
+
property :group_id, Integer, :key => true, :field => "gidnumber"
|
129
120
|
|
130
121
|
def group
|
131
|
-
Group.get!(
|
122
|
+
Group.get!(group_id)
|
132
123
|
end
|
133
124
|
|
134
125
|
def group=(group)
|
135
|
-
|
126
|
+
group_id = group.id
|
136
127
|
end
|
137
128
|
|
138
129
|
def user
|
139
|
-
User.get!(
|
130
|
+
User.get!(user_id)
|
140
131
|
end
|
141
132
|
|
142
133
|
def user=(user)
|
143
|
-
|
134
|
+
user_id = user.id
|
144
135
|
end
|
145
|
-
# belongs_to :user, :child_key => [:memberuid]
|
146
136
|
end
|
147
137
|
DataMapper.auto_migrate!(:default)
|
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.
|
4
|
+
version: 0.3.0
|
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-06-15 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 0.0.4
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: slf4r
|
@@ -32,6 +32,16 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: dm-core
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - <
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.10.0
|
44
|
+
version:
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: hoe
|
37
47
|
type: :development
|
@@ -40,7 +50,7 @@ dependencies:
|
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.8.
|
53
|
+
version: 1.8.3
|
44
54
|
version:
|
45
55
|
description: ""
|
46
56
|
email:
|
@@ -80,7 +90,9 @@ files:
|
|
80
90
|
- spec/spec_helper.rb
|
81
91
|
- test.ldif
|
82
92
|
has_rdoc: true
|
83
|
-
homepage:
|
93
|
+
homepage: http://dm-ldap-adapter.rubyforge.org
|
94
|
+
licenses: []
|
95
|
+
|
84
96
|
post_install_message:
|
85
97
|
rdoc_options:
|
86
98
|
- --main
|
@@ -102,9 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
114
|
requirements: []
|
103
115
|
|
104
116
|
rubyforge_project: dm-ldap-adapter
|
105
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 1.3.4
|
106
118
|
signing_key:
|
107
|
-
specification_version:
|
119
|
+
specification_version: 3
|
108
120
|
summary: ""
|
109
121
|
test_files: []
|
110
122
|
|