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_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 .
-
#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, _passdn, _rootdn = 'cn=root', _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.
-
#valid? ⇒ Boolean
return true if the must attributes is completed in record before commit!.
Constructor Details
#initialize(_dn, _passdn, _rootdn = 'cn=root', _host = 'localhost', _port = 389) ⇒ LdapMapper
constructor with dn_ldap initialisation
_dn and _passdn are required, _rootdn, _host and _port are optionals
return a boolean
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ldapmapper.rb', line 165 def initialize(_dn,_passdn, _rootdn='cn=root',_host = 'localhost', _port = 389) _scope = LDAP::LDAP_SCOPE_SUBTREE _filter = '(objectClass=*)' super(_passdn, _rootdn, _host, _filter, _port, _scope ) @dn_ldap = _dn @list_objectclass = Array::new @list_attributs_type = Hash::new @list_attributs = Hash::new add_objectclass! end |
Instance Attribute Details
#dn_ldap ⇒ Object
DN binding point attribut
152 153 154 |
# File 'lib/ldapmapper.rb', line 152 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
158 159 160 |
# File 'lib/ldapmapper.rb', line 158 def list_attributs @list_attributs end |
#list_attributs_type ⇒ Object
Hash of attributes with optional or mandatory aspects in value
154 155 156 |
# File 'lib/ldapmapper.rb', line 154 def list_attributs_type @list_attributs_type end |
#list_objectclass ⇒ Object
Array of objectclass for the current record
156 157 158 |
# File 'lib/ldapmapper.rb', line 156 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
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ldapmapper.rb', line 181 def add_objectclass!(_objectclass = 'top') @list_objectclass = @list_objectclass.concat(get_objectclass_list(self.dn_ldap,self.host_ldap,self.port_ldap)) @list_objectclass.push(_objectclass).uniq! @list_attributs_type = get_attributs_list(self.list_objectclass,self.host_ldap,self.port_ldap) @list_attributs = map_record(self.dn_ldap,self.host_ldap,self.port_ldap) if not @list_attributs.nil? or @list_attributs.empty? then @list_attributs.each{|_key,_value| @list_attributs_type.each{|_attr,_trash| @list_prov = self.get_alias(_key) if @list_prov then if self.get_alias(_key).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
238 239 240 241 242 243 244 245 |
# File 'lib/ldapmapper.rb', line 238 def can_create? return false if self.is_base? if list_arbitrary_node(self.get_previous,self.host_ldap,self.port_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
319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/ldapmapper.rb', line 319 def commit! if self.exist? and self.valid? then # case modifying an LDAP object mod_object(self.dn_ldap, self.list_attributs, self.rootdn_ldap, self.basedn_ldap, self.passdn_ldap, self.host_ldap, self.port_ldap) return true elsif self.can_create? and self.valid? then # case creating new object add_object(self.dn_ldap, self.list_attributs, self.rootdn_ldap, self.basedn_ldap, self.passdn_ldap, self.host_ldap, self.port_ldap) return true else return false # case can't commit end end |
#exist? ⇒ Boolean
existance of an LDAP instance test method
return a boolean
216 217 218 219 220 221 222 |
# File 'lib/ldapmapper.rb', line 216 def exist? if list_arbitrary_node(self.dn_ldap,self.host_ldap,self.port_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
295 296 297 298 299 300 301 302 303 304 |
# File 'lib/ldapmapper.rb', line 295 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
250 251 252 253 254 255 256 |
# File 'lib/ldapmapper.rb', line 250 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
227 228 229 230 231 232 233 |
# File 'lib/ldapmapper.rb', line 227 def is_node? if list_arbitrary_node(self.dn_ldap,self.host_ldap,self.port_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
309 310 311 312 313 314 |
# File 'lib/ldapmapper.rb', line 309 def list_node _my_res = Array::new _my_res = list_arbitrary_node(self.dn_ldap,self.host_ldap,self.port_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
273 274 275 276 277 278 279 |
# File 'lib/ldapmapper.rb', line 273 def may _must_list = Array::new self.list_attributs_type.each{|_key,_value| _must_list.push(_key) if _value == 'MAY' } return _must_list end |
#must ⇒ Object
return the list of the attributes how must be present for add a record
return an Array
261 262 263 264 265 266 267 268 |
# File 'lib/ldapmapper.rb', line 261 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 |
#valid? ⇒ Boolean
return true if the must attributes is completed in record before commit!
return a boolean
284 285 286 287 288 289 290 |
# File 'lib/ldapmapper.rb', line 284 def valid? _result = true self.must.each{|attribute| _result = false if not self.list_attributs.include?(attribute) } return _result end |