Class: Ldapmapper::LdapMapper
- Inherits:
-
LdapTemplate
- Object
- LdapTemplate
- Ldapmapper::LdapMapper
- Defined in:
- lib/ldapmapper.rb
Overview
Mapping LDAP object class
This is the real CRUD Class
contructor arguments :
_dn and _passdn are required, _rootdn, _host and _port are optionals
Instance Attribute Summary collapse
-
#dn_ldap ⇒ Object
DN binding point attribut.
-
#list_attributs ⇒ Object
Hash of attributes in LDIF mapping, value should be an array in case of multivalue data.
-
#list_attributs_rollback ⇒ Object
Returns the value of attribute list_attributs_rollback.
-
#list_attributs_type ⇒ Object
Hash of attributes with optional or mandatory aspects in value.
-
#list_objectclass ⇒ Object
Array of objectclass for the current record.
Attributes inherited from LdapTemplate
#basedn_ldap, #filter_ldap, #host_ldap, #passdn_ldap, #port_ldap, #rootdn_ldap, #scope_ldap
Instance Method Summary collapse
-
#add_objectclass!(_objectclass = 'top') ⇒ Object
add an objectclass in the list and map attribut .
-
#can_create? ⇒ Boolean
test methode to check the ability to create the instance, already exist or not bindable.
-
#commit! ⇒ Object
commit the modification or the adding of the object in LDAP server .
-
#delete! ⇒ Object
delete the dn object in LDAP server.
-
#exist? ⇒ Boolean
existance of an LDAP instance test method.
-
#get_previous ⇒ Object
get the previous record if exist and if the record is not the basedn.
-
#initialize(_dn, _rootdn = '', _passdn = '', _host = 'localhost', _port = 389) ⇒ LdapMapper
constructor
constructor with dn_ldap initialisation.
-
#is_base? ⇒ Boolean
return true if the dn to search is the basedn of the tree.
-
#is_node? ⇒ Boolean
test methode for LDAP instance situation node or termination .
-
#list_node ⇒ Object
method to list dn after the node in the the LDAP tree for the first level, .
-
#may ⇒ Object
return the attributes list how may be present in the record .
-
#must ⇒ Object
return the list of the attributes how must be present for add a record.
-
#rollback! ⇒ Object
rollback to beggining of transaction.
-
#valid? ⇒ Boolean
return true if the must attributes is completed in record before commit!.
Constructor Details
#initialize(_dn, _rootdn = '', _passdn = '', _host = 'localhost', _port = 389) ⇒ LdapMapper
constructor with dn_ldap initialisation
_dn and _passdn are required, _rootdn, _host and _port are optionals
return a boolean
259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/ldapmapper.rb', line 259 def initialize(_dn, _rootdn='', _passdn='', _host = 'localhost', _port = 389) _scope = LDAP::LDAP_SCOPE_SUBTREE _filter = '(objectClass=*)' super( _host, _port, _rootdn, _passdn, _filter, _scope ) @dn_ldap = _dn @list_objectclass = Array::new @list_attributs_type = Hash::new @list_attributs = Hash::new add_objectclass! @list_attributs_rollback = @list_attributs end |
Instance Attribute Details
#dn_ldap ⇒ Object
DN binding point attribut
245 246 247 |
# File 'lib/ldapmapper.rb', line 245 def dn_ldap @dn_ldap end |
#list_attributs ⇒ Object
Hash of attributes in LDIF mapping, value should be an array in case of multivalue data
251 252 253 |
# File 'lib/ldapmapper.rb', line 251 def list_attributs @list_attributs end |
#list_attributs_rollback ⇒ Object
Returns the value of attribute list_attributs_rollback.
252 253 254 |
# File 'lib/ldapmapper.rb', line 252 def list_attributs_rollback @list_attributs_rollback end |
#list_attributs_type ⇒ Object
Hash of attributes with optional or mandatory aspects in value
247 248 249 |
# File 'lib/ldapmapper.rb', line 247 def list_attributs_type @list_attributs_type end |
#list_objectclass ⇒ Object
Array of objectclass for the current record
249 250 251 |
# File 'lib/ldapmapper.rb', line 249 def list_objectclass @list_objectclass end |
Instance Method Details
#add_objectclass!(_objectclass = 'top') ⇒ Object
add an objectclass in the list and map attribut
_objectclass is optional
return an Hash
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/ldapmapper.rb', line 278 def add_objectclass!(_objectclass = 'top') @list_objectclass = @list_objectclass.concat(get_objectclass_list(self.dn_ldap, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap)) @list_objectclass.push(_objectclass).uniq! @list_attributs_type = get_attributs_list(self.list_objectclass, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) @list_attributs = map_record(self.dn_ldap, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) if not @list_attributs.nil? or @list_attributs.empty? then @list_attributs.each{|_key,_value| @list_attributs_type.each{|_attr,_trash| @list_prov = get_alias(_key,self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) if @list_prov then if @list_prov.include?(_attr) then @list_attributs.delete(_key) @list_attributs[_attr] = _value end end } } end @list_attributs["objectClass"] = @list_objectclass @list_attributs_type.each_key {|_key| eval(" def #{_key.downcase} return @list_attributs['#{_key}'] end def #{_key.downcase}=(_value) @list_attributs['#{_key}'] = _value end ") } end |
#can_create? ⇒ Boolean
test methode to check the ability to create the instance, already exist or not bindable
return a boolean
341 342 343 344 345 346 347 348 |
# File 'lib/ldapmapper.rb', line 341 def can_create? return false if self.is_base? if list_arbitrary_node(self.get_previous,self.host_ldap,self.port_ldap, self.rootdn_ldap, self.passdn_ldap).length >= 1 and not self.exist? then return true else return false end end |
#commit! ⇒ Object
commit the modification or the adding of the object in LDAP server
return a boolean
433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/ldapmapper.rb', line 433 def commit! if self.exist? and self.valid? then # case modifying an LDAP object return mod_object(self.dn_ldap, self.list_attributs.merge(self.list_attributs_rollback), self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) elsif self.can_create? and self.valid? then # case creating new object return add_object(self.dn_ldap, self.list_attributs, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) else return false # case can't commit end end |
#delete! ⇒ Object
delete the dn object in LDAP server
return a boolean
422 423 424 425 426 427 428 |
# File 'lib/ldapmapper.rb', line 422 def delete! if self.exist? and not self.is_node? then return delete_object(self.dn_ldap, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap) else return false end end |
#exist? ⇒ Boolean
existance of an LDAP instance test method
return a boolean
312 313 314 315 316 317 318 |
# File 'lib/ldapmapper.rb', line 312 def exist? if list_arbitrary_node(self.dn_ldap, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap).empty? then return false else return true end end |
#get_previous ⇒ Object
get the previous record if exist and if the record is not the basedn
return a String
398 399 400 401 402 403 404 405 406 407 |
# File 'lib/ldapmapper.rb', line 398 def get_previous _rec_res = String::new('') if not self.is_base? then _rdn = String::new('') _dn_table = Array::new _rdn,*_dn_table = self.dn_ldap.split(',') _rec_res = _dn_table.join(',') end return _rec_res end |
#is_base? ⇒ Boolean
return true if the dn to search is the basedn of the tree
return a boolean
353 354 355 356 357 358 359 |
# File 'lib/ldapmapper.rb', line 353 def is_base? if self.dn_ldap == self.basedn_ldap then return true else return false end end |
#is_node? ⇒ Boolean
test methode for LDAP instance situation node or termination
return a boolean
330 331 332 333 334 335 336 |
# File 'lib/ldapmapper.rb', line 330 def is_node? if list_arbitrary_node(self.dn_ldap, self.host_ldap, self.port_ldap, self.rootdn_ldap, self.passdn_ldap).length > 1 then return true else return false end end |
#list_node ⇒ Object
method to list dn after the node in the the LDAP tree for the first level,
return an Array
412 413 414 415 416 417 |
# File 'lib/ldapmapper.rb', line 412 def list_node _my_res = Array::new _my_res = list_arbitrary_node(self.dn_ldap,self.host_ldap,self.port_ldap, self.rootdn_ldap, self.passdn_ldap, LDAP::LDAP_SCOPE_ONELEVEL) _my_res.delete(self.dn_ldap) if _my_res.include?(self.dn_ldap) return _my_res end |
#may ⇒ Object
return the attributes list how may be present in the record
return an Array
376 377 378 379 380 381 382 |
# File 'lib/ldapmapper.rb', line 376 def may _may_list = Array::new self.list_attributs_type.each{|_key,_value| _may_list.push(_key) if _value == 'MAY' } return _may_list end |
#must ⇒ Object
return the list of the attributes how must be present for add a record
return an Array
364 365 366 367 368 369 370 371 |
# File 'lib/ldapmapper.rb', line 364 def must _must_list = Array::new self.list_attributs_type.each{|_key,_value| _must_list.push(_key) if _value == 'MUST' } _must_list.delete('dn') if _must_list.include?('dn') return _must_list end |
#rollback! ⇒ Object
rollback to beggining of transaction
return a boolean
323 324 325 |
# File 'lib/ldapmapper.rb', line 323 def rollback! @list_attributs = @list_attributs_rollback end |
#valid? ⇒ Boolean
return true if the must attributes is completed in record before commit!
return a boolean
387 388 389 390 391 392 393 |
# File 'lib/ldapmapper.rb', line 387 def valid? _result = true self.must.each{|attribute| _result = false if not self.list_attributs.include?(attribute) } return _result end |