OpenLDAPServiceの例
この例では、RDMLファンクションでのOpenLDAPServiceの使用について実証します。これは、ユーザーにユーザー名('cn'値)の指定を要求し、IBM i 上のIBM Directory Server (IBMTelDir)からレコードを取得します。最初に、属性*ALLを使用する場合に返される内容を示し、次に、選択した属性のみを返す方法を示します。
この例を実行するには、以下の操作を行う必要があります。
1. IBM i 上のIBM Directory Serverを構成して開始します。IBM Directory Serverの詳細については、関連するIBMマニュアルを参照してください。
2. LANSAリポジトリで以下の2つのフィールドを定義します。
· #JSMSTS, Char, 桁数 20
· #JSMMSG, Char, 桁数 255
3. #JSMSRVフィールドを正しいJSMサーバーの値に設定します。
4. #LDPSRVフィールドを正しいLDAPサーバーの値に設定します。
* =======================================================
* Description:
* This example demonstrates the use of the
* OpenLDAPService in an RDML function. It requests the
* user to provide a user name (a 'cn' value) and then
* GETs a record from the IBM Directory Server (IBMTelDir)
* on the IBM
i
. Two screens are returned. The first one
* shows what is returned when you use the attribute *ALL,
* while the second shows you how to return only selected
* attributes.
* To run this example you will need to do the following:
* Step 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
* Step 2
* Define two fields in the LANSA Repository:
* - #JSMSTS, Char, Length 20
* - #JSMMSG, Char, Length 255
* Step 3
* Set the #JSMSRV field to the correct JSM server value
* Step 4
* Set the #LDPSRV field to the correct LDAP server value
* Disclaimer: The following material is supplied as
* sample material only. No warranty concerning the
* material or its use in any way whatsoever is
* expressed or implied.
* =======================================================
FUNCTION OPTIONS(*DIRECT)
* The following locally defined fields are used to hold
* the parameters required within the JSM Built-in
* functions.
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(255)
DEFINE FIELD(#JSMSRV) TYPE(*CHAR) LENGTH(050)
DEFINE FIELD(#LDPSRV) TYPE(*CHAR) LENGTH(050)
* The following fields are used in the working list
* required for the GET commands.
DEFINE FIELD(#ATNAME) TYPE(*CHAR) LENGTH(035)
DEFINE FIELD(#ATVALUE) TYPE(*CHAR) LENGTH(035)
DEF_LIST NAME(#WRKLST) FIELDS(#ATNAME #ATVALUE) TYPE(*WORKING)
DEF_LIST NAME(#GET_LIST) FIELDS(#ATNAME #ATVALUE)
DEF_LIST NAME(#GET_LIST2) FIELDS(#ATNAME #ATVALUE)
* Define the field used to capture the 'cn' value (that
* is, the user name).
DEFINE FIELD(#CN_FNAME) TYPE(*CHAR) LENGTH(050) DESC('Name to Retrieve') INPUT_ATR(LC)
* 'Open service'
* The JSM_OPEN Builtin Function is used to connect this
* JSM client to the Java Services Manager, and to start
* a thread for the service.
CHANGE FIELD(#JSMSRV) TO('<system-name>:<port>')
USE BUILTIN(JSM_OPEN) WITH_ARGS(#JSMSRV) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
* 'Load service'
* The Service_Load(OpenLDAPService) command loads and
* initializes the service.
CHANGE FIELD(#JSMCMD) TO('SERVICE_LOAD SERVICE(OPENLDAPSERVICE) TRACE(*NO)')
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#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
CHANGE FIELD(#LDPSRV) TO('<LDAP-server-name>')
CHANGE FIELD(#JSMCMD) TO('''BIND HOST(''')
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #LDPSRV ') DN(cn=Administrator) PASSWORD(password)') TO_GET(#JSMCMD)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
* Execute a subroutine to REQUEST the User details to be
* retrieved, then run the GET command. Keep looping until
* user Cancels or Exits. Notice that the Exit and Menu
* keys are controlled to ensure that the UNLOAD and CLOSE
* commands are always executed.
DOUNTIL COND('(#IO$KEY *EQ ''12'') *OR (#IO$KEY *EQ ''03'')')
EXECUTE SUBROUTINE(REQ_USER)
ENDUNTIL
CHANGE FIELD(#JSMCMD) TO(UNBIND)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#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.
USE BUILTIN(JSM_COMMAND) WITH_ARGS('SERVICE_UNLOAD') TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
* 'Close service'
* The final step in the process is to close the service.
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
* SUBROUTINES
* This subroutine asks the user to provide the CN name
* they wish to retrieve
SUBROUTINE NAME(REQ_USER)
REQUEST FIELDS(#CN_FNAME) EXIT_KEY(*YES *RETURN) MENU_KEY(*YES *RETURN)
* 'GET Command'
* This command is used to get the record of with the user
* that has been selected.
* Two screens are returned. The first one shows what is
* returned when you use the attribute *ALL, while the
* second shows you how to return only selected attributes
* Populate the first screen using ATTRIBUTES(*ALL)
CLR_LIST NAMED(#WRKLST)
CHANGE FIELD(#JSMCMD) TO('GET DN(cn=')
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #CN_FNAME ', cn=users' ', o=ibmteldir)') TO_GET(#JSMCMD)
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD ' ATTRIBUTES(*ALL)' ' SERVICE_LIST(ATNAME,ATVALUE)') TO_GET(#JSMCMD)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #WRKLST)
CLR_LIST NAMED(#GET_LIST)
SELECTLIST NAMED(#WRKLST)
ADD_ENTRY TO_LIST(#GET_LIST)
ENDSELECT
DISPLAY BROWSELIST(#GET_LIST) EXIT_KEY(*YES *RETURN) MENU_KEY(*YES *RETURN)
* Populate the second screen using ATTRIBUTES(cn,sn,mail)
CLR_LIST NAMED(#WRKLST)
CHANGE FIELD(#JSMCMD) TO('GET DN(cn=')
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #CN_FNAME ', cn=users' ', o=ibmteldir)') TO_GET(#JSMCMD)
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD ' ATTRIBUTES(cn,sn,mail)' ' SERVICE_LIST(ATNAME,ATVALUE)') TO_GET(#JSMCMD)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #WRKLST)
CLR_LIST NAMED(#GET_LIST2)
SELECTLIST NAMED(#WRKLST)
ADD_ENTRY TO_LIST(#GET_LIST2)
ENDSELECT
DISPLAY BROWSELIST(#GET_LIST2) EXIT_KEY(*YES *RETURN) MENU_KEY(*YES *RETURN)
ENDROUTINE
SUBROUTINE NAME(CHECK) PARMS((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVED))
IF COND('#JSMSTS *NE OK')
DISPLAY FIELDS(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)
MENU MSGTXT('Java service error has occurred')
ENDIF
ENDROUTINE