Saturday, November 15, 2008

Security Policy with Rampart - UserNameToken

This post explains security policy basics with an example in Rampart.

Here the service expects clients to authenticate themselves with username/password credentials.

Usually non-functional descriptions and QoS aspects are covered by WS-Policy - and assertions related to security are covered under WS-SecurityPolicy.

You can read more about WS-SecurityPolicy from here.

Let's see how the above requirements being expressed in service policy.

<service name="SimpleService">
<module ref="rampart" />

<operation name="echo">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

<parameter name="ServiceClass" locked="false">>

<wsp:Policy wsu:Id="UTOverTransport"

<ramp:RampartConfig xmlns:ramp="">
Lets start with the most inner part.

The above requests to include username/password credentials in all the messages sent from initiator to recipient.

Supporting tokens are included in the security header and in our case UsernameToken will be expected in the header.

<ramp:RampartConfig xmlns:ramp="">
This is not policy specific - but Rampart specific - it simply says Rampart to where to find the password callback class at the service end to verify client credentials.

That's it with policy, you need to write the service class and the password callback handler for the service. This may help you in doing that.

Now, lets look at the client.

Use wsdl2java tool to generate service stubs.

wsdl2java -uri http://localhost:8080/axis2/services/SimpleService?wsdl -ns2p -uw


import java.rmi.RemoteException;

import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;

public class Client {

private static final String SERVICE_EPR = "http://localhost:8080/axis2/services/SimpleService";

public static void main(String[] args) throws RemoteException {
SimpleServiceStub service = null;
Options options = null;
ConfigurationContext configContext = null;

configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repo", null);

service = new SimpleServiceStub(configContext, SERVICE_EPR);

// engage rampart module

options = service._getServiceClient().getOptions();
// add username/password credentials



Prezesik said...

I have tried your solution but I get org.apache.axis2.AxisFault: UsernameToken missing in request exception every time I've made a request.

faisal sk said...

I have requirement bit different i get normal header request with username&password need to validate with wso2 esb user-store like username-token done.But username-token has its own message format where as my client is not sending me in that format how would i change header before the proxy.
please refer this

1111141414 said...

kobe shoes
pandora bracelet
adidas stan smith
yeezy boost
michael jordan shoes
michael kors outlet store
michael kors outlet store
jordan shoes
adidas yeezy
yeezy boost