Home > Class Reference > ENSLIB namespace > %Net.LDAP.Client.Session

%Net.LDAP.Client.Session

class %Net.LDAP.Client.Session extends %Library.RegisteredObject

WARNING: This Class and its methods has been deprecated, please use the %SYS.LDAP class.


LDAP session.

The following shows an example on creating, deleting, and searching for entries:

      Set err=""
      Set session=##class(%Net.LDAP.Client.Session).%New()
      If (testnum) {
          Set DC="CN=Users,DC=kerberos,DC=iscinternal,DC=com"
          Set c=session.Connect("kerbad",0,"CN=administrator,"_DC,"password", 0)
      } else {
          Set DC="DC=testldap,DC=com"
          Set c=session.Connect("lx2",0,"CN=admin,"_DC,"password", 0)
      }
      If ($$$ISERR(c)) {
          Do DecomposeStatus^%apiOBJ(c,.err)
          Write "Failed to connect : err : ", err(err),!
          Quit
      }
      Write "Connected to (",DC,")",!
      
      ;; Build attributes to be added to the entry
      Set p=session.GetPropList()
      Set c=p.Insert("objectclass","organizationalRole") w:(c'=$$$OK) "objclass attrib insert failed!!",!
      Set cn="test4"
      Set c=p.Insert("cn",cn) w:(c'=$$$OK) "cn attrib insert failed!!",!
      Set DN="cn="_cn_","_DC
      Set c=session.AddNewEntry(DN,p)
      If ($$$ISERR(c)) {
          Do DecomposeStatus^%apiOBJ(c,.err)
          Write "Failed to add/create a new entry(",DN,") : err : ", err(err),!
      } else {
          Write "Entry added (",DN,")",!
      }
      ;; Rename an Entry
      s c=session.RenameEntry(DN,"cn=testxx","",1)
      if ($$$ISERR(c)) {
          d DecomposeStatus^%apiOBJ(c,.err)
          W "Failed to Rename the new entry(",DN,") to(","testxx",") : err : ", err(err),!
      } else {
          w "Rename 'testxx' back to '",cn,"'",!
          s c=session.RenameEntry("cn=testxx,"_DC,"cn="_cn,"",1)
          if ($$$ISERR(c)) d DecomposeStatus^%apiOBJ(c,.err) W "Failed to restore the name(",DN,") : err : ", err(err),!
      }
      ;; Get all "ObjectClass" and "cn" in DC
      ;; build a list of desired attributes 
      Set sl=session.GetStringList()
      Do sl.InsertStr(