Asynchronous Web Service & WS Security With Axis2 & Rampart

Introduction

Apache Axis2 is designed to support the easy addition of plug in “modules” that extend the functionality such as security. The addressing module is the one that provide the asynchrony to the web services and Rampart is the security module for Axis2.

Getting Started

We will start with a simple service that has an operation called “TestMethod” which will return a String. To test the asynchronous behavior, the current thread was delayed for ten seconds. Service class implementation is given below.

The service descriptor for the above method as follows (service.xml)

Engage addressing and Rampart at the service

To get the asynchronous behavior, first we have to make the server side asynchronous, for that we have to engage the “addressing” module of axis2. This was done by adding element to the service descriptor as follows.

Next task is to add security to our web service, for that we are using Apache Rampart. Rampart is also a module in Axis2, and we can engage this module to our web service the same manner as we have engaged the addressing module. The following is how we have engaged the Rampart module and the security policy for the web service.


////////////////////////////////////////////service.xml///////////////////////////////////////////////////

  1. Service.XML

Note : Please Remove the underscore (_) from the abovve tags

SSL Confutation and Web Service Deployment

Our security policy was based on transport level security, for that we use https transport in jboss server. But first we have configured the SSL in jboss server and modify the server.xml, which can be found in JBOSS_HOME\server\default\deploy\jboss-web.deployer directory. In server.xml we have to mention the key store file location its password. Your SSL configuration should be look like the one given below.

"<

maxThreads="150" scheme="https" secure="true"

clientAuth="false"

strategy="ms"

address="${jboss.bind.address}"

keystoreFile="path to the key store file”

keystorePass="password"

sslProtocol="TLS"/>"

Next we have to deploy our web service in the Axis2 server, for that we have to create a service archive named AsySecuService.aar and copy to JBOSS_HOME\server\default\deploy\axis2.war\WEB-INF\services directory.

Write the client code

Now that the service has been deployed, we need to write a client that accesses the service. First we have to create the stubs by using the Java2WSDL tool provided by Axis2. If you want asynchronous only stubs to be generated use –a option.

Next we well write the client for the Web Service using code generated by stubs and callback class. First we have to create the client repository, by copying the addressing.mar, rampart.mar and, rahas.mar to modules directory. Make sure the all the dependency .jar files are available in the class path. Place the key store file in keys directory. Your directory structure should be similar to one that given below.


Engage addressing and Rampart at the Client

The rampart module and addressing module have to engage at client side as well. Note that the object of a callback class is given to invoke the service. The following is the source code for the client.


try {
System.setProperty("javax.net.ssl.trustStore", "keys/dmsssl.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "asiripass");
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("client-repo", null);
AsyPersonServiceStub stub = new AsyPersonServiceStub(ctx,"https://localhost:8443/axis2/services/AsyPersonService");
ServiceClient sc = stub._getServiceClient();
sc.engageModule("rampart");
sc.engageModule("addressing");
Options options = sc.getOptions();
options.setUserName("don");
options.setPassword("don");
int a = 2;
MyCallBack mcb = new MyCallBack();
stub.startgetPerson(a, mcb);
while(!mcb.isComplete()){
System.out.println("Do Something");
}


} catch (Exception e) {
System.out.println(e);
}

Note :

Correct or comment me If iam wrong

Comments

Popular posts from this blog

How to unlock 2Degrees Fritzbox to be used in any other Fibre Network

How to use Hibernate 5 to insert Postgresql auto incrementing primary key

Postgresql , Hibernate and issues with Schemas