Module: Ldapmapper
- Defined in:
- lib/ldapmapper.rb
Overview
General module for LDAP CRUD Ojects
Defined Under Namespace
Classes: LdapMapper, LdapTemplate
Constant Summary collapse
- LIB_VERSION =
identity lib version of the library
'1.2'
- AUTHOR =
name of the author
'Romain GEORGES'
- DATE =
date of creation
'30/07/2005'
- OBS =
valuable observations
'Generic LDAP class'
Instance Method Summary collapse
-
#add_object(_dn, _record, _rootdn, _basedn, _passdn, _host = 'localhost', _port = 389) ⇒ Object
add an ldap object .
-
#get_alias(_attribute, _host = 'localhost', _port = 389) ⇒ Object
get the alias list of an attribute in Schema .
-
#get_attributs_list(_list_objectclass, _host = 'localhost', _port = 389) ⇒ Object
get the attributs list of an objectclass list .
-
#get_basedn(_host = 'localhost', _port = 389) ⇒ Object
get the base dn of an LDAP tree.
-
#get_objectclass_list(_dn, _host = 'localhost', _port = 389, _scope = LDAP::LDAP_SCOPE_BASE, _filter = '(objectClass=*)') ⇒ Object
global method that list objectclass for a speficique dn .
-
#list_arbitrary_node(_dn, _host = localhost, _port = 389, _scope = LDAP::LDAP_SCOPE_SUBTREE, _filter = '(objectClass=*)') ⇒ Object
global method that list dn after the precised dn in the LDAP tree.
-
#map_record(_dn, _host = 'localhost', _port = 389, _scope = LDAP::LDAP_SCOPE_SUBTREE, _filter = '(objectClass=*)') ⇒ Object
map the attributs of class at run time for the current LDAP Object at precise DN.
-
#mod_object(_dn, _record, _rootdn, _basedn, _passdn, _host = 'localhost', _port = 389) ⇒ Object
modify an ldap object.
Instance Method Details
#add_object(_dn, _record, _rootdn, _basedn, _passdn, _host = 'localhost', _port = 389) ⇒ Object
add an ldap object
_dn, _record, _rootdn, _basedn and _passdn are required, _host and _port are optional
return a boolean
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/ldapmapper.rb', line 471 def add_object(_dn, _record, _rootdn, _basedn, _passdn, _host='localhost',_port=389) _conn = LDAP::Conn.new(_host, _port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _record.delete('dn') _conn.bind("#{_rootdn}", "#{_passdn}"){ begin _data = self.list_attributs _data.each{|_key,_value| _data[_key] = _value.to_a } _conn.add("#{_dn}", _data) return true rescue LDAP::ResultError return false end } end |
#get_alias(_attribute, _host = 'localhost', _port = 389) ⇒ Object
get the alias list of an attribute in Schema
_attribute is required, _host and _port are optionals
return an Array
382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/ldapmapper.rb', line 382 def get_alias(_attribute,_host='localhost',_port=389) _my_list_attributs = Array::new begin _conn = LDAP::Conn.new(_host, _port) _conn.bind{ _schema = _conn.schema() _my_list_attributs = _schema.alias(_attribute) } ensure return _my_list_attributs end end |
#get_attributs_list(_list_objectclass, _host = 'localhost', _port = 389) ⇒ Object
get the attributs list of an objectclass list
server free method
_list_objectclass is required, _host and _port are optionals
return an Hash
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/ldapmapper.rb', line 426 def get_attributs_list(_list_objectclass,_host='localhost',_port=389) _my_list_attributs = Hash::new begin _conn = LDAP::Conn.new(_host, _port) _conn.bind{ _schema = _conn.schema() _list_objectclass.each{|objectclass| if objectclass != 'top' then _schema.must(objectclass).each{|attributs| _my_list_attributs[attributs] = 'MUST'} _schema.may(objectclass).each{|attributs| _my_list_attributs[attributs] = 'MAY'} end } } ensure _my_list_attributs["dn"] = "MUST" _my_list_attributs["objectClass"] = "MUST" return _my_list_attributs end end |
#get_basedn(_host = 'localhost', _port = 389) ⇒ Object
get the base dn of an LDAP tree
_host and _port are optionals
return a String
364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/ldapmapper.rb', line 364 def get_basedn(_host='localhost',_port=389) _my_basedn = String::new('') begin _conn = LDAP::Conn.new(_host,_port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _conn.bind { _my_basedn = _conn.root_dse[0]["namingContexts"].to_s } ensure return _my_basedn end end |
#get_objectclass_list(_dn, _host = 'localhost', _port = 389, _scope = LDAP::LDAP_SCOPE_BASE, _filter = '(objectClass=*)') ⇒ Object
global method that list objectclass for a speficique dn
server free methode
_dn is required, _host, _port, _scope and _filter are optionals
return an Array
344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/ldapmapper.rb', line 344 def get_objectclass_list(_dn,_host='localhost',_port=389,_scope=LDAP::LDAP_SCOPE_BASE,_filter='(objectClass=*)') _table_res = Array::new begin _conn = LDAP::Conn.new(_host,_port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _conn.bind { _conn.search(_dn,_scope,_filter){|_e| _table_res = _e.to_hash()['objectClass'] } } ensure return _table_res end end |
#list_arbitrary_node(_dn, _host = localhost, _port = 389, _scope = LDAP::LDAP_SCOPE_SUBTREE, _filter = '(objectClass=*)') ⇒ Object
global method that list dn after the precised dn in the LDAP tree
server free methode
_dn id required, _host, _port, _scope, _filter are optionals
return an Array
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/ldapmapper.rb', line 403 def list_arbitrary_node(_dn,_host=localhost,_port=389,_scope=LDAP::LDAP_SCOPE_SUBTREE,_filter='(objectClass=*)') _table_res = Array::new begin _conn = LDAP::Conn.new(_host,_port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _conn.bind { _conn.search(_dn,_scope,_filter){|_e| _table_res.push(_e.dn) } } ensure return _table_res end end |
#map_record(_dn, _host = 'localhost', _port = 389, _scope = LDAP::LDAP_SCOPE_SUBTREE, _filter = '(objectClass=*)') ⇒ Object
map the attributs of class at run time for the current LDAP Object at precise DN
_dn is required, _host, _port, _scope and _filter are optionals
return an Hash
452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/ldapmapper.rb', line 452 def map_record(_dn,_host='localhost',_port=389,_scope=LDAP::LDAP_SCOPE_SUBTREE,_filter='(objectClass=*)') begin _conn = LDAP::Conn.new(_host,_port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _conn.bind { _conn.search(_dn,_scope,_filter){|_e| return _e.to_hash() } } rescue return Hash::new end end |
#mod_object(_dn, _record, _rootdn, _basedn, _passdn, _host = 'localhost', _port = 389) ⇒ Object
modify an ldap object
_dn, _record, _rootdn, _basedn and _passdn are required, _host and _port are optional
return a boolean
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/ldapmapper.rb', line 494 def mod_object(_dn, _record, _rootdn, _basedn, _passdn, _host='localhost',_port=389) _conn = LDAP::Conn.new(_host, _port) _conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) _record.delete('dn') _conn.bind("#{_rootdn}", "#{_passdn}"){ begin _conn.delete("#{_dn}") _data = self.list_attributs _data.each{|_key,_value| _data[_key] = _value.to_a } _conn.add("#{_dn}", _data) return true rescue LDAP::ResultError return false end } end |