Hi Tim,
I have been reading through some website that tells me how to apply security Axis2 server with rampart framework. I have created service and clients as shown below. Could you please tell me why I am getting an error and the program fails
Service :-
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPFactory;
public class CMSService {
public OMElement getNumberOfArticles(OMElement element) throws XMLStreamException {
element.build();
element.detach();
String categoryValue = element.getFirstElement().getText();
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
OMElement resultElem = factory.createOMElement("numberOfArcticles", factory.createOMNamespace("http://daily-moon.com/cms/", "resp"));
resultElem.setText(articleCount(categoryValue).toString());
System.out.println("Service method getNumberOfArticles done");
return resultElem;
}
private Integer articleCount(String catId) {
return new Integer(42);
}
}
callback class
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
public class PWCallback implements CallbackHandler {
public void handle(Callback[] callbackArr) throws IOException, UnsupportedCallbackException {
int i = 0;
while (i < callbackArr.length) {
if (callbackArr[i] instanceof WSPasswordCallback) {
WSPasswordCallback wSPasswordCallback = (WSPasswordCallback) callbackArr[i];
if (wSPasswordCallback.getIdentifer().equals("bob")) {
wSPasswordCallback.setPassword("password");
} else if (wSPasswordCallback.getIdentifer().equals("alice")) {
wSPasswordCallback.setPassword("password");
} else {
throw new UnsupportedCallbackException(callbackArr[i], "Unknown user");
}
i++;
} else {
throw new UnsupportedCallbackException(callbackArr[i], "Unrecognized Callback");
}
}
}
}
services.xml
<service name="CMSService">
<description>
This is a sample Web Service for the newspaper's Content Managment System.
</description>
<parameter name="ServiceClass" locked="false">CMSService</parameter>
<parameter name="InflowSecurity">
<action>
<items>Timestamp Signature</items>
<passwordCallbackClass>PWCallback</passwordCallbackClass>
<signaturePropFile>security.properties</signaturePropFile>
</action>
</parameter>
<parameter name="OutflowSecurity">
<action>
<items>Timestamp Signature Encrypt</items>
<user>alice</user>
<passwordCallbackClass>PWCallback</passwordCallbackClass>
<signaturePropFile>security.properties</signaturePropFile>
<signatureKeyIdentifier>SKIKeyIdentifier</signatureKeyIdentifier>
<encryptionKeyIdentifier>SKIKeyIdentifier</encryptionKeyIdentifier>
<encryptionUser>bob</encryptionUser>
<signatureParts>{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body</signatureParts>
<optimizeParts>//xenc:EncryptedData/xenc:CipherValue/xenc:CipherData</optimizeParts>
</action>
</parameter>
<operation name="getNumberOfArticles">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>
security.properties
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=password
org.apache.ws.security.crypto.merlin.file=sec.jks
Client side :--
axis2.xml
client class
callback class
security.properties
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=password
org.apache.ws.security.crypto.merlin.file=sec.jks
start.bat
I deployed CMSService.aar in axis2 server in the axis2-1.7.3\repository\services folder
I was expecting to execute the start.bat file to get a response from the axis2 server.
But instead I got an error on the command prompt
C:\Users\humpa\Desktop\softcol\security-code-files\WSSecurityCodeFiles\ClientAFTER>start.bat
C:\Users\humpa\Desktop\softcol\security-code-files\WSSecurityCodeFiles\ClientAFTER>echo off
org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.tcp.TCPTransportSender
C:\Users\humpa\Desktop\softcol\security-code-files\WSSecurityCodeFiles\ClientAFTER>
Could you please figure what is creating this Error is ?
Regards
Emerson