Amazon

Saturday, May 17, 2014

AXIS 2 - SOAP Webservice - Adding Security layer to webservice using Rampart

Tools and Libraries used 

  1. apache-tomcat-7.0.53
  2. axis2-1.6.2
  3. rampart-1.6.2
  4. jdk 1.6
Exploring ram.war - The war file name is ram.war. The directory structure of the war file is below.

D:\APACHE-TOMCAT-7.0.53\WEBAPPS\RAM
├───META-INF
└───WEB-INF
    ├───classes
    │   ├───com
    │   │   └───polaris
    │   │       └───iph
    │   │           └───ws
    │   └───crishantha
    │       └───rampart
    ├───conf
    ├───lib
    ├───modules
    └───services
        └───TemperatureConversionService
            └───META-INF

Below folders contain classes for webservice.
- classes/com.polaris.iph.ws 
- classes/crishantha.rampart

Integrating rampart with Axis 2 webservice
WEB-INF/conf - contains axis2.xml
WEB-INF/lib - contains all jars from  Axis2_HOME/lib/ and RAMPART_HOME/lib directory. 

Very important Note 
- The version of Axis2 and Rampart should be same. I faced issues because previously I was using axis2-1.6.2 and rampart-1.3.2. Then I changed the version of rampart to rampart-1.6.2 and it worked. This is very important point.
- The axis2 libs should not be mixed with various versions of other libs of Rampart and other extensions. It creates compatibility issues.

WEB-INF/modules - copy rahas-1.6.2.mar and rampart-1.6.2.mar files from  rampart-1.6.2\modules folder  in  WEB-INF/modules folder.

Declare webservice and engaging Rampart 

Adding Webservice in WAR file  and engaging Rampart with Axis2. Follow this link to see the META-INF/services/TemperatureConversionService/META-INF/services.xml.
http://java-application-programming.blogspot.in/2014/05/axis2-servicesxml-engaging-rampart.html

Making server ready for HTTPS
Creating SSL Key to make tomcat server HTTPS /SSL Enabled. Execute below command from Tomcat_home\bin folder
keytool -genkey -alias tomcat -keyalg RSA -keystore  c:\sslkey\sslkey.jks

c:\sslkey\sslkey.jks will be created with the key. This key will be used to enable SSL.

Open the server.xml of tomcat from TOMCAT_HOME\conf\server.xml and enable /change/add below lines  around tags.

     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
      keystoreFile="C:\sslkey\sslkey.jks"
      keystorePass="password" />
     
Note: keystorePass="password", "password" value is entered while creating sslkey.jks using keytool (see few lines above)

Open WEB-INF/conf/axis2.xml and add below lines below tag  <transportReceiver>
 
<transportReceiver name="https" class="org.apache.axis2.transport.http.AxisServletListener">

<parameter name="port">8443</parameter>
</transportReceiver>
Note : The port in axis2.xml and server.xml should be same, here its kept 8443.

Generating Client Code - Stub to call this service.

Save the WSDL  -TemperatureConversionService.xml
Execute below command


D:\AXIS2_DUMP\axis2-1.6.2\bin\clientcode>..\WSDL2Java.bat -uri D:\2010SANT\27_0_0\WS-POC\RAMPART\WebContent\WEB-INF\wsdl\TemperatureConversionService.xml -p ramp.client -d adb -s


NOTE: Get the jar from http://repo1.maven.org/maven2/org/apache/axis2/axis2-adb-codegen/1.6.2/axis2-adb-codegen-1.6.2.jar, before executing above command of WSDL2Java.bat. Issues will come without this jar.

Follow below link to develop Webservice Client for secured Webservice
 http://java-application-programming.blogspot.in/2014/05/axis-2-client-and-password-call-back.html

No comments:

Post a Comment

Amazon Best Sellors

Weblogic - Server Creation - Issues

Datasource creation using python script.  Python Script was failing after creating Datasource. From UI Admin Console, if I try to activat...