ldapmapper 1.0.1 → 1.1
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/lib/ldapmapper.rb +18 -61
- metadata +1 -1
data/lib/ldapmapper.rb
CHANGED
@@ -9,15 +9,8 @@
|
|
9
9
|
# * Author:: Romain GEORGES
|
10
10
|
# * type:: class definition Ruby
|
11
11
|
# * obj:: Generic LDAP class
|
12
|
-
# *
|
12
|
+
# * CVS Version:: $Id: ldapmapper.rb,v 1.1.1.1 2006/09/09 10:57:45 lecid Exp $
|
13
13
|
#
|
14
|
-
# === Websites :
|
15
|
-
# * http://www.ultragreen.net
|
16
|
-
# * http://ldapmapper.rubyforge.org
|
17
|
-
#
|
18
|
-
# === Contact :
|
19
|
-
# Romain GEORGES <romain@ultragreen.net>
|
20
|
-
#
|
21
14
|
# == Exemples :
|
22
15
|
#
|
23
16
|
# #!/usr/local/bin/ruby
|
@@ -101,7 +94,7 @@ module Ldapmapper
|
|
101
94
|
|
102
95
|
# identity lib
|
103
96
|
# version of the library
|
104
|
-
LIB_VERSION='1.
|
97
|
+
LIB_VERSION='1.1'
|
105
98
|
# name of the author
|
106
99
|
AUTHOR='Romain GEORGES'
|
107
100
|
# date of creation
|
@@ -115,25 +108,18 @@ module Ldapmapper
|
|
115
108
|
# attributs for LDAP connection
|
116
109
|
|
117
110
|
# hostname of the LDAP server
|
118
|
-
# default : 'localhost'
|
119
111
|
attr_accessor :host_ldap
|
120
112
|
# TCP/IP port of the LDAP server
|
121
|
-
|
122
|
-
attr_accessor :port_ldap
|
113
|
+
attr_accessor :port_ldap
|
123
114
|
# LDAP scope for search
|
124
|
-
# dafault : LDAP::LDAP_SCOPE_SUBTREE
|
125
115
|
attr_accessor :scope_ldap
|
126
116
|
# current filter for search
|
127
|
-
# default : '(objectClass=*)'
|
128
117
|
attr_accessor :filter_ldap
|
129
118
|
# LDAP base DN for the instance
|
130
|
-
# no default get by LDAP bind for ROOT DSE record
|
131
119
|
attr_accessor :basedn_ldap
|
132
120
|
# credential for the instance
|
133
|
-
# no default get by instance initializer
|
134
121
|
attr_accessor :passdn_ldap
|
135
122
|
# LDAP rootdn for LDAP
|
136
|
-
# default 'cn=root'
|
137
123
|
attr_accessor :rootdn_ldap
|
138
124
|
|
139
125
|
# constructor for LdapTemplate
|
@@ -164,16 +150,12 @@ module Ldapmapper
|
|
164
150
|
class LdapMapper < LdapTemplate
|
165
151
|
|
166
152
|
# DN binding point attribut
|
167
|
-
# no default get by instance initializer
|
168
153
|
attr_accessor :dn_ldap
|
169
154
|
# Hash of attributes with optional or mandatory aspects in value
|
170
|
-
# no default get by LDAP query on Schema
|
171
155
|
attr_accessor :list_attributs_type
|
172
156
|
# Array of objectclass for the current record
|
173
|
-
# no default, could be empty for nonexistants mapping get by LDIF LDAP query
|
174
157
|
attr_accessor :list_objectclass
|
175
158
|
# Hash of attributes in LDIF mapping, value should be an array in case of multivalue data
|
176
|
-
# no default, could be empty for nonexistants mapping get by LDIF LDAP query
|
177
159
|
attr_accessor :list_attributs
|
178
160
|
|
179
161
|
# constructor with dn_ldap initialisation
|
@@ -202,13 +184,16 @@ module Ldapmapper
|
|
202
184
|
@list_objectclass.push(_objectclass).uniq!
|
203
185
|
@list_attributs_type = get_attributs_list(self.list_objectclass,self.host_ldap,self.port_ldap)
|
204
186
|
@list_attributs = map_record(self.dn_ldap,self.host_ldap,self.port_ldap)
|
205
|
-
if not @list_attributs.nil? then
|
187
|
+
if not @list_attributs.nil? or @list_attributs.empty? then
|
206
188
|
@list_attributs.each{|_key,_value|
|
207
189
|
@list_attributs_type.each{|_attr,_trash|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
190
|
+
@list_prov = self.get_alias(_key)
|
191
|
+
if @list_prov then
|
192
|
+
if self.get_alias(_key).include?(_attr) then
|
193
|
+
@list_attributs.delete(_key)
|
194
|
+
@list_attributs[_attr] = _value
|
195
|
+
end
|
196
|
+
end
|
212
197
|
}
|
213
198
|
}
|
214
199
|
end
|
@@ -366,10 +351,8 @@ module Ldapmapper
|
|
366
351
|
_table_res = _e.to_hash()['objectClass']
|
367
352
|
}
|
368
353
|
}
|
354
|
+
ensure
|
369
355
|
return _table_res
|
370
|
-
rescue
|
371
|
-
raise LdapmapperGetObjectclassesError
|
372
|
-
return Array::new
|
373
356
|
end
|
374
357
|
end
|
375
358
|
|
@@ -386,10 +369,8 @@ module Ldapmapper
|
|
386
369
|
_conn.bind {
|
387
370
|
_my_basedn = _conn.root_dse[0]["namingContexts"].to_s
|
388
371
|
}
|
372
|
+
ensure
|
389
373
|
return _my_basedn
|
390
|
-
rescue
|
391
|
-
raise LdapmapperGetDSEError
|
392
|
-
return Array::new
|
393
374
|
end
|
394
375
|
end
|
395
376
|
|
@@ -406,10 +387,9 @@ module Ldapmapper
|
|
406
387
|
_schema = _conn.schema()
|
407
388
|
_my_list_attributs = _schema.alias(_attribute)
|
408
389
|
}
|
390
|
+
|
391
|
+
ensure
|
409
392
|
return _my_list_attributs
|
410
|
-
rescue
|
411
|
-
raise LdapmapperGetSchemaError
|
412
|
-
return Array::new
|
413
393
|
end
|
414
394
|
end
|
415
395
|
|
@@ -430,10 +410,8 @@ module Ldapmapper
|
|
430
410
|
_table_res.push(_e.dn)
|
431
411
|
}
|
432
412
|
}
|
413
|
+
ensure
|
433
414
|
return _table_res
|
434
|
-
rescue
|
435
|
-
raise LdapmapperGetDnError
|
436
|
-
return Array::new
|
437
415
|
end
|
438
416
|
|
439
417
|
end
|
@@ -458,12 +436,10 @@ module Ldapmapper
|
|
458
436
|
end
|
459
437
|
}
|
460
438
|
}
|
439
|
+
ensure
|
461
440
|
_my_list_attributs["dn"] = "MUST"
|
462
441
|
_my_list_attributs["objectClass"] = "MUST"
|
463
442
|
return _my_list_attributs
|
464
|
-
rescue
|
465
|
-
raise LdapmapperGetSchemaError
|
466
|
-
return Hash::new
|
467
443
|
end
|
468
444
|
end
|
469
445
|
|
@@ -482,7 +458,6 @@ module Ldapmapper
|
|
482
458
|
}
|
483
459
|
}
|
484
460
|
rescue
|
485
|
-
raise LdapmapperGetLdifError
|
486
461
|
return Hash::new
|
487
462
|
end
|
488
463
|
end
|
@@ -505,7 +480,6 @@ module Ldapmapper
|
|
505
480
|
_conn.add("#{_dn}", _data)
|
506
481
|
return true
|
507
482
|
rescue LDAP::ResultError
|
508
|
-
raise LdapmapperAddLdifError
|
509
483
|
return false
|
510
484
|
end
|
511
485
|
}
|
@@ -530,7 +504,6 @@ module Ldapmapper
|
|
530
504
|
_conn.add("#{_dn}", _data)
|
531
505
|
return true
|
532
506
|
rescue LDAP::ResultError
|
533
|
-
raise LdapmapperModLdifError
|
534
507
|
return false
|
535
508
|
end
|
536
509
|
}
|
@@ -546,23 +519,7 @@ module Ldapmapper
|
|
546
519
|
puts "Date release : #{DATE}"
|
547
520
|
puts "Observation : #{OBS}"
|
548
521
|
end
|
549
|
-
|
550
|
-
# exceptions definitions
|
551
|
-
# raise when a modification of a record failed
|
552
|
-
class LdapmapperModLdifError < Exception; end
|
553
|
-
# raise when an adding of a record failed
|
554
|
-
class LdapmapperAddLdifError < Exception; end
|
555
|
-
# raise when the retrieving of a record failed
|
556
|
-
class LdapmapperGetLdifError < Exception; end
|
557
|
-
# raise when the retrieving of Schema's data failed
|
558
|
-
class LdapmapperGetSchemaError < Exception; end
|
559
|
-
# raise when the browsing of an LDAP tree failed
|
560
|
-
class LdapmapperGetDnError < Exception; end
|
561
|
-
# raise when the retrieving of root DSE record failed
|
562
|
-
class LdapmapperGetDSEError < Exception; end
|
563
|
-
# raise when the retrieving of objectclasses list failed
|
564
|
-
class LdapmapperGetObjectclassesError < Exception; end
|
565
|
-
|
522
|
+
|
566
523
|
end
|
567
524
|
|
568
525
|
#==END==#
|