Petals-BC-SOAP

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (4)

View Page History
h3. Client side

The SOAP header must contains the required security elements like in the following SOAP message snippet :
todo {code:lang=xml}
<soapenv:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
soapenv:mustUnderstand="1">
<wsu:Timestamp
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="Timestamp-26598747">
<wsu:Created>2007-07-30T14:59:34.944Z</wsu:Created>
<wsu:Expires>2007-07-30T15:04:34.944Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="UsernameToken-6427893">
<wsse:Username>bob</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-
1.0#PasswordDigest">
0ziDIJ4Gd0XHbbbB/rgasDpOZJY=
</wsse:Password>
<wsse:Nonce>
fqgz0lkb7/ezFiY7Km4qvg==
</wsse:Nonce>
<wsu:Created>
2007-07-30T14:59:34.944Z
</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
{code}

The following code snippet shows how to engage the rampaet module on the client side and how to call the Web Service :
{code}
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2ConfPath, null);

ServiceClient client = new ServiceClient(ctx, null);
OMElement payload = getSayHelloOMElement(sayHelloStr);

Options options = new Options();
options.setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, getOutflowConfiguration("bob"));
client.engageModule(new QName("rampart"));
options.setTo(targetEPR);
options.setAction("sayHello");

client.setOptions(options);
result = client.sendReceive(payload);
{code}

The {{axis2ConfPath}} directory must point to a directory in which a {{modules}} directory contains the {{rampart-1.2.mar}} module used by the client. The code also uses a Class handler which is similar to the service's one, and will provide the required user and password :
{code}
package org.ow2.petals.security.client.handler;

import org.apache.ws.security.WSPasswordCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;

public class MyExampleClientHandler implements CallbackHandler {

public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i];
String id = pwcb.getIdentifer();
if ("bob".equals(id)) {
pwcb.setPassword("bobPW");
}
}
}
}
{code}

In this example, the user name is sent in {{plain clear text}} in the request. Depending on your security needs, you should use a secured transport layer (such as HTTPS), or another Rampart configuration to encrypt the information (and even the body content if required). For more Rampart configuration examples, you should have a look at the samples provided by Apache in the rampart distribution at : [http://www.apache.org/dyn/closer.cgi/ws/rampart/1_3|http://www.apache.org/dyn/closer.cgi/ws/rampart/1_3].

h2. Using WS-Policy