Hello all,

i am new to apache rampart and i want to use rampart, to send a SOAP-Header with
a UsernameToken to a server using the policy mechanism.

In my case, a client needs to specify a username and a password always different, because i have a GUI with a popup window asking for username and password. So i wonder how
i can set username and password before sending it to the server.

The "policy.xml" always has a fixed username.
In the clients callback handler class it seems that i can only set the password to a existing username from the policy.xml using the WSPasswordCallback class.

WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[0]; pwcb.setPassword(password);

i finally got it working to set usernames dynamically by parsing the policy file as xml. But it seems to me like a workaround. Is there no way to set the username in the callbackhandler class with a java function instead of reading it out from the policy file ? What is the philosophy behind this way to allow a username definition only in the policy.xml ?

This is the code i use to set the username:

      // set the username in the policyfile
OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement document = rampartpolicy.getDocumentElement(); OMElement exactlyone = document.getFirstElement();
      OMElement all = exactlyone.getFirstElement();
OMElement rampConfig = all.getFirstChildWithName(new QName("http://ws.apache.org/rampart/policy";, "RampartConfig")); OMElement user = rampConfig.getFirstChildWithName(new QName("http://ws.apache.org/rampart/policy";, "user")); if (user != null)
        user.detach();

OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/rampart/policy";, "ramp");
      user = factory.createOMElement("user", ns);
user.setText(username); rampConfig.addChild(user);

// set the rampart policyfile as option for the registry stub registry._getServiceClient().getOptions().setProperty(RampartMessageData.KEY_RAMPART_POLICY,
      PolicyEngine.getPolicy(rampartpolicy.getDocumentElement()));

// set the password callbackhandler along with the password handler.setPassword(password); registry._getServiceClient().getOptions().setProperty("passwordCallbackRef", handler);
thanks,
B. Huber


Reply via email to