Hi,
There's another way to achieve your requirements without specifying the
RampartConfig assertion in the policy.xml file at the client.
You can create an org.apache.neethi.Policy instance with a policy.xml
that only contains standard WS-SecurityPolicy assertions. Then you can
create an instance of the RampartConfig assertion within the client code
and add that assertion in to the policy instance.
Please see this client code from one of the WSO2 WSAS[1] samples for an
example [1]. Here the loadPolicy() method reads in the policy file which
doesn't contain any rampart specific policy and then adds the configured
RampartConfig assertion into it. Also note that the Client also
implements the javax.security.auth.callback.CallbackHandler interface
and to provide the password.
Hope this helps!
Thanks,
Ruchith
[1] http://www.wso2.org/projects/wsas/java
[2]
http://wso2.org/repos/wso2/trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java
Bernd Huber wrote:
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