How can I use dynamic user credentials with Axis2 and Rampart?

618 views Asked by At

I'm attempting to fix a client app that uses Axis2 and Rampart. The app will be accessing the same API using multiple sets of credentials. Currently, the password callback class relies on the user in the axis2.xml file to determine which credentials to use. This obviously won't work because it only allows for a single user. Can someone please explain to me the right way to do it?

1

There are 1 answers

0
mrog On BEST ANSWER

I found a useful example at http://www.ibm.com/developerworks/java/library/j-jws4/. I got rid of the OutflowSecurity parameter in axis2.xml. I also got rid of the password callback class. I added a policy.xml file and some code to load it. I use this code to provide the username and password:

// Prepare the client
PartnerAPIStub stub = stubProvider.getStub();
ServiceClient client = stub._getServiceClient();
client.engageModule("rampart");
org.apache.axis2.client.Options options = client.getOptions();
options.setProperty(RampartMessageData.KEY_RAMPART_OUT_POLICY, policy);
options.setUserName(account.getApiUser());
options.setPassword(account.getApiPassword());

// Send the request
RetrieveResponseMsg response = stub.retrieve(requestDoc).getRetrieveResponseMsg();