OpenLDAPService

This RDMLX form provides an example of how to use the OpenLDAPService. The form allows a user to add the details of a new entry to the IBM Directory Server (IBMTelDir) using the ADD command. It also allows the user to view a list of all current entries using the using the SEARCH command. So, if a new entry is successfully added, this will be reflected in the list.

To run this example you will need to do the following:

1. Configure and start the IBM Directory Server on the IBM i. For more information on the IBM Directory Server please refer to the relevant IBM Manuals.

2. Define two fields in the LANSA Repository:

3. Set the #JSMSRV field to the correct JSM server value

4. Set the #LDPSRV field to the correct LDAP server value

***************************************************

*

* Description:

* This RDMLX form provides an example of how to use the OpenLDAPService. The form allows a user to add the details of a new entry to the IBM Directory Server (IBMTelDir) using the ADD command. It also allows the user to view a list of all current entries using the using the SEARCH command. So, if a new entry is succesfully added, this will be reflected in the list.

*

* To run this example you will need to do the following:

*   1. Configure and start the IBM Directory Server on the IBM i. For more information on the IBM Directory Server please refer to the relevant IBM Manuals;

*   2. Define two fields in the LANSA Repository:

*       - #JSMSTS, Char, Length 20

*       - #JSMMSG, Char, Length 255

*   3. Set the #JSMSRV field to the correct JSM server value

*   4. Set the #LDPSRV field to the correct LDAP server value

*

* Disclaimer : The following material is supplied as sample material only. No warranty concerning this material or its use in any way whatsoever is expressed or implied.

*

***************************************************

FUNCTION OPTIONS(*DIRECT)

Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(313) Clientwidth(514) Left(360) Top(135) Width(522)

Define_Com Class(#GIVENAME.Visual) Name(#CN_FNAME) Caption('First Name') Displayposition(1) Height(19) Labeltype(Caption) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Usepicklist(False) Width(324)

Define_Com Class(#SURNAME.Visual) Name(#SN_LNAME) Caption('Last Name') Displayposition(2) Height(19) Labeltype(Caption) Left(8) Parent(#COM_OWNER) Tabposition(2) Top(32) Usepicklist(False) Width(324)

Define_Com Class(#STD_DESCL.Visual) Name(#EMAIL) Caption('Email') Displayposition(3) Height(19) Labeltype(Caption) Left(8) Parent(#COM_OWNER) Tabposition(3) Top(56) Usepicklist(False) Width(495)

Define_Com Class(#STD_TEXTS.Visual) Name(#PASSWORD) Caption('Password') Displayposition(4) Height(19) Labeltype(Caption) Left(8) Parent(#COM_OWNER) Tabposition(4) Top(80) Usepicklist(False) Width(401)

Define_Com Class(#PRIM_STBR) Name(#STBR_1) Displayposition(5) Height(24) Left(0) Messageposition(1) Parent(#COM_OWNER) Tabposition(5) Tabstop(False) Top(289) Width(514)

Define_Com Class(#PRIM_PHBN) Name(#ADD_RECORD) Caption('Add User') Displayposition(6) Left(160) Parent(#COM_OWNER) Tabposition(6) Top(104)

Define_Com Class(#PRIM_LTVW) Name(#LTVW_1) Componentversion(2) Displayposition(7) Fullrowselect(True) Height(131) Left(12) Parent(#COM_OWNER) Showsortarrow(True) Tabposition(7) Top(142) Width(493)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Caption('Current Directory Entries') Captiontype(Caption) Displayposition(1) Parent(#LTVW_1) Sortonclick(True) Source(#STD_DESCL) Widthtype(Remainder)

 

* The following locally defined fields are used to hold the parameters required by the JSM Built-in Functions.

Define Field(#JSMCMD) Type(*Char) Length(255)

Define Field(#JSMSRV) Type(*Char) Length(050)

Define Field(#JSMPRT) Type(*Char) Length(005)

Define Field(#JSMHND) Type(*Char) Length(4)

Define Field(#LDPSRV) Type(*Char) Length(050)

 

 

* The following fields and working list are required for the Add command.

Define Field(#ATNAME) Type(*Char) Length(050)

Define Field(#ATVALUE) Type(*Char) Length(050)

Def_List Name(#WRKLST) Fields(#ATNAME #ATVALUE) Type(*working)

 

* The following fields and list are used to display the values currently in the directory. They are required for the Search command.

Define Field(#DN) Type(*Char) Length(050)

Def_List Name(#WRKLST2) Fields(#DN) Type(*Working)

 

EVTROUTINE handling(#com_owner.Initialize)

SET #COM_OWNER caption(*component_desc)

 

* Set up the JSM and LDAP server settings

#JSMSRV := '<system-name.:<port>'

#LDPSRV := '<ldap-server-name>'

 

* Execute the method to connect to the LDAPServer.

#COM_OWNER.Connect

 

* Execute the method to populate the list view.

#COM_OWNER.Refresh

 

ENDROUTINE

 

* Add the record to the directory

EVTROUTINE HANDLING(#ADD_RECORD.Click)

 

* Execute the Add Method

#COM_OWNER.Add

 

* Refresh the list view

#COM_OWNER.Refresh

 

ENDROUTINE

 

* Add the new entry to the LDAP server

Mthroutine Name(Add)

 

* The working list that contains the information pertaining to the new record is prepared for the Add command

#ATNAME := cn

#ATVALUE := #CN_FNAME

Add_Entry To_list(#WRKLST)

 

#ATNAME := sn

#ATVALUE := #SN_LNAME

Add_Entry To_list(#WRKLST)

 

#ATNAME := mail

#ATVALUE := #EMAIL

Add_Entry To_list(#WRKLST)

 

#ATNAME := userPassword

#ATVALUE := #PASSWORD

Add_Entry To_list(#WRKLST)

 

#ATNAME := objectClass

#ATVALUE := top

Add_Entry To_list(#WRKLST)

#ATVALUE := person

Add_Entry To_list(#WRKLST)

#ATVALUE := inetOrgPerson

Add_Entry To_list(#WRKLST)

#ATVALUE := organizationalPerson

Add_Entry To_list(#WRKLST)

 

* The Add command is prepared and executed

#JSMCMD := 'Add DN(cn=' + #CN_FNAME + ', cn=users, o=ibmteldir) Service_List(ATNAME,ATVALUE)'

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG #WRKLST)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

ENDROUTINE

 

* Refresh the list view

Mthroutine Name(Refresh)

 

* 'Search LDAP Server'

* The SEARCH command is responsible for the actual search of the LDAP directory. The results will be placed into a working list

#JSMCMD := 'Search Dn(o=ibmteldir) Filter(objectclass=person) Scope(*SUB) Service_List(DN)'

Use Builtin(Jsmx_command) With_args(#jsmhnd #jsmcmd) To_Get(#JSMSTS #JSMMSG #WRKLST2)

 

* The resultant list is then placed into the list view

Clr_List #Ltvw_1

Selectlist Named(#WRKLST2)

 

#STD_DESCL := #DN

 

Add_Entry To_List(#Ltvw_1)

 

ENDSELECT

 

ENDROUTINE

 

* The following method routine is used by all the JSMX commands to handle any errors that are encountered.

Mthroutine name(check)

define_map for(*input) class(#JSMSTS) name(#I_STATUS)

define_map for(*input) class(#JSMMSG) name(#I_MESSAGE)

 

message msgtxt(#JSMSTS.trim + ': ' + #JSMMSG)

 

endroutine

 

* Connect to the JSM system then the LDAP server

Mthroutine Name(Connect)

 

* 'Open service'

* The JSMX_OPEN Builtin Function is used to connect this JSMX client to the Java Services Manager, and to start a thread for the service.

Use Builtin(JSMX_OPEN) With_Args(#JSMSRV) To_Get(#JSMSTS #JSMMSG #JSMHND)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

* 'Load service'

* The Service_Load(OpenLDAPService) command loads and initializes the service using the values defined in the OpenLDAPService.properties file.

#JSMCMD := 'Service_Load Service (OpenLDAPService)'

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

* 'Bind to LDAP Server'

* The BIND command is used to establish a connection to the LDAP server. In this scenario we are passing an authentication name (DN) and password, but these are not mandatory for this command

#JSMCMD := 'Bind Host(' + #Ldpsrv + ') DN(cn=Administrator) Password(password)'

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

Endroutine

 

*Disconnect from the LDAP server then the JSM system

Mthroutine Name(Disconnect)

 

* 'Unbind from LDAP Server'

* This command is used to disconnect from the LDAP Server when we have completed.

#JSMCMD := UnBind

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

* 'Unload service'

* This command is required to unload the service and to remove the temporary directory. If you needed to send out multiple messages then you would not issue this command until after you had finished sending all the messages.

#JSMCMD := 'Service_Unload'

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

* 'Close service'

* The final step in the process is to close the service.

Use Builtin(JSMX_CLOSE) With_Args(#JSMHND) To_Get(#JSMSTS #JSMMSG)

#COM_OWNER.check(#JSMSTS #JSMMSG)

 

Endroutine

 

* When the form is closed we want to disconnect from the LDAP Server

EVTROUTINE HANDLING(#COM_OWNER.Closing) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

 

#COM_OWNER.Disconnect

 

ENDROUTINE

 

END_COM