Implement loginServiceManaged Web Service in Java
This information is provided to show detailed steps complete with code that leverages CA Service Desk’s ability to generate Certificates and then use these generated Certificates to access the CA Service Desk web services.
nimsm32
Implement loginServiceManaged Web Service in Java
Introduction
This information is provided to show detailed steps complete with code that leverages CA Service Desk’s ability to generate Certificates and then use these generated Certificates to access the CA Service Desk web services.
In the example shown below we complete the login process using the CA Service Desk Certificate and then conduct a couple of common web services calls. The first web service call is loginServiceManaged, but the more interesting of the two is the getBopsid web services method call—which allows us to obtain a token that is linked to a specific user. This token can be used to login to the CA Service Desk web interface as the linked user without being prompted for a password. This allows seamless integration to be enabled between different applications. It should be noted that the generated BOPSID token does expire after around 10 seconds, meaning that it must be used promptly.
This example is built entirely using Java code in a JSP page, however the code that is in this page was originally taken from a Java class file called USDWSUtil.java which that is also provided in the %INSTALL_DIR%\samples\sdk\websvc\java\ test1_pki director
Implementation
Prerequisites:
Ensure to use the AXIS Tool known as WSDL2Java to generate the required stub classes. To perform this step, see the section
Generating Stub Classes with AXIS Tool WSDL2Java
mentioned on this page, for a sample script along with the steps for generating the stub classes.- Start Service Desk services.
- Open the DOS prompt and runpdm_pki -p DEFAULT.This command creates theDEFAULT.p12file in the current directory. This policy will have the password equal to the policy name (In this case DEFAULT). This command will also add the Certificate’s public key to thefield pub_key field(public_key attribute) in thesapolicy table/object.
- Open Service Desk web interface and go toAdministration > Web Services Policies > Policies.
- In Policy “DEFAULT” insert the Proxy Contact. (In this case ServiceDesk) and confirm that the DEFAULT policy record hasKey = YES
- CopyDEFAULT.p12file (from the directory where commandpdm_pkiis executed) to<Service Desk install>\bopcfg\www\CATALINA_BASE\webapps\axisdirectory
- Copy the filespkilogin.htmandpkilogin.jsp(from the$NX_ROOT/samples/sdk/websvc/java/test1_pkidirectory) into<Service Desk install>\bopcfg\www\CATALINA_BASE\webapps\axisdirectory.
- Open HTML form page at (http://localhost:8080/axis/pkilogin.htm), fill in the fields and click "Log me in!" button (this will launch the JSP page to run the login process).The “Directory” field is the directory location where the Certificate file can be found.
The URL that is embedded in the results page is a hyperlink to the Service Desk web interface that will provide a seamless login (no login/password required) using the BOPSID functionality that was called after the login process completed. Since the BOPSID is a limited life token that is linked to a specific user, you need to click on the URL within a few seconds in order for the login process to complete successfully. The format of a URL using a BOPSID is as follows:
http://<server name>:<port>/CAisd/pdmweb.exe?BOPSID=<BOPSID value>
Generating Stub Classes with AXIS Tool WSDL2Java
To generate the stub classes for the CA Service Desk web services:
1.Open a command prompt and cd to the “
<drive>:\program files\CA
” directory, then run the dir /x
command to see what the short form of the Service Desk directory is “SERVIC~1
”…note what your Service Desk directory is as this information will be required later.2. Build a bat file called
build_wsdl.bat
and place it in the <Service Desk install>\bopcfg\www\CATALINA_BASE\webapps\axis\ directory
. Add the following code build_wsdl.bat
in this bat file and update the highlighted items as appropriate (or use the template text file below):@echo off::#############################################################################::# Simple bat file to Build r12 USD Stub classes.::# Use it to create the required USD r12 Java Web Services classes.::#::# Usage: build_wsdl::#############################################################################@REM Update this with the PATH to USD NX_ROOT location.@SET USD_SHORT_PATH=C:\PROGRA~1\CA\SERVIC~1@REM Update this to the path to the USD NX_ROOT/java/lib location.@SET USD_TOMCAT=%USD_SHORT_PATH%\java\lib@SET CP=%USD_TOMCAT%/axis.jar;%USD_TOMCAT%/commons-discovery.jar;%USD_TOMCAT%/commons-logging.jar;%USD_TOMCAT%/jaxrpc.jar;%USD_TOMCAT%/saaj.jar;%USD_TOMCAT%/log4j-1.2.8.jar;%USD_TOMCAT%/xml-apis.jar;%USD_TOMCAT%/xercesImpl.jar;%USD_TOMCAT%/wsdl4j.jar;%USD_TOMCAT%/axis-ant.jar@REM Please specify the path to java.exe file below.@REM You can obtain this by reviewing the NX.env file.@REM Use the @NX_JRE_INSTALL_DIR variable to derive this information.@SET JAVA_PATH="C:/Program Files/CA/SC/JRE/1.6.0_00"@SET JAVA_EXE=%JAVA_PATH%\bin\java.exe@REM Update this with the PATH to the JDK javac.exe compiler (this is used in the 2nd part of this file)@SET JAVAC_EXE=%JAVA_PATH%\bin\javac.exe::#############################################################################::# WSDL2Java command.::# -w parameter required when using Axis 1.4 that comes with r12.::# Remove this flag if using Axis 1.1.::#############################################################################@cd WEB-INF\classes%JAVA_EXE% -cp %CP% org.apache.axis.wsdl.WSDL2Java -w http://localhost:8080/axis/services/USD_R11_WebService?wsdl@cd ..\..::#############################################################################::# This next section compiles the Service Desk stub code.::# Once complete, you should recycle tomcat with the following::# commands or by recycling Service Desk:::# pdm_tomcat_nxd -c STOP::# pdm_tomcat_nxd -c START::#############################################################################@SET CP=".\classes;%CP%"@SET STUBS_DIR=classes\com\ca\www\UnicenterServicePlus\ServiceDesk@cd WEB-INF%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\ArrayOfInt.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\ArrayOfString.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\ListResult.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\USD_WebService.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\USD_WebServiceLocator.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\USD_WebServiceSoap.java%JAVAC_EXE% -classpath %CP% -deprecation -d classes %STUBS_DIR%\USD_WebServiceSoapSoapBindingStub.java@cd ..
There is a copy of this file (
build_wsdl.txt
) in the %INSTALL_DIR%\samples\sdk\websvc\java\test1_pki
directory to use as a template.
3. After running this batch file from the command prompt you should now have the stub classes in place and compiled.
4. Run the following commands to recycle Tomcat (or you can simply recycle Service Desk):
pdm_tomcat_nxd –c STOPpdm_tomcat_nxd –c START