You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by Sanjay Vivek <Sa...@newcastle.ac.uk> on 2008/01/18 14:24:07 UTC

Setting the username/password programatically using the policy based configuration.

Hi everyone,

I'm attempting to programatically set the username/password at the
client side using the policy based configuration. The code snippet below
explains how I'm going about this. Is this the right way to
programatically set the username/password?

        ConfigurationContext ctx = ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(axis2ConfPath,
null);
        
        ServiceClient client = new ServiceClient(ctx, null);

        Options options = new Options();
        options.setTo(targetEPR);
        options.setAction("urn:echo");
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy(confPath + "/conf/axis2.xml"));

        //set username/password
        options.setUserName("bob");
        options.setPassword("wspwd");
        client.setOptions(options);
        
        
        client.engageModule("addressing");
        client.engageModule("rampart");
        
        OMElement response = client.sendReceive(getPayload("Hello
world"));

I also have a question regarding the policy.xml file. Within the
<RampartConfig>, there's a <user> element as shown below. Do I edit this
out when attempting to programatically set the username? Thanks again.

<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
			<ramp:user>alice</ramp:user>
			<ramp:passwordCallbackClass>
org.apache.rampart.samples.policy.sample01.PWCBHandler</ramp:passwordCal
lbackClass>
</ramp:RampartConfig>


Regards
--------------
Sanjay Vivek
Web Analyst
Middleware Team
ISS
University of Newcastle Upon Tyne

Re: Setting the username/password programatically using the policy based configuration.

Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi Sanjay,

I also have a question regarding the policy.xml file. Within the
> <RampartConfig>, there's a <user> element as shown below. Do I edit this
> out when attempting to programatically set the username? Thanks again.
>
> <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
>                        <ramp:user>alice</ramp:user>
>


No, you don't have to. If the Username Builder finds the username/password
in
the options, it won't look in the configuration.

Thanks,
Nandana

RE: Setting the username/password programatically using the policy based configuration.

Posted by Sanjay Vivek <Sa...@newcastle.ac.uk>.
Hi everyone,

Well I just tested that out and it seems to be working :). Cheers.

Regards
Sanjay 

>-----Original Message-----
>From: Sanjay Vivek [mailto:Sanjay.Vivek@newcastle.ac.uk] 
>Sent: 18 January 2008 13:24
>To: rampart-dev@ws.apache.org
>Subject: Setting the username/password programatically using 
>the policy based configuration.
>
>Hi everyone,
>
>I'm attempting to programatically set the username/password at 
>the client side using the policy based configuration. The code 
>snippet below explains how I'm going about this. Is this the 
>right way to programatically set the username/password?
>
>        ConfigurationContext ctx = ConfigurationContextFactory
>                
>.createConfigurationContextFromFileSystem(axis2ConfPath,
>null);
>        
>        ServiceClient client = new ServiceClient(ctx, null);
>
>        Options options = new Options();
>        options.setTo(targetEPR);
>        options.setAction("urn:echo");
>        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
>loadPolicy(confPath + "/conf/axis2.xml"));
>
>        //set username/password
>        options.setUserName("bob");
>        options.setPassword("wspwd");
>        client.setOptions(options);
>        
>        
>        client.engageModule("addressing");
>        client.engageModule("rampart");
>        
>        OMElement response = client.sendReceive(getPayload("Hello
>world"));
>
>I also have a question regarding the policy.xml file. Within 
>the <RampartConfig>, there's a <user> element as shown below. 
>Do I edit this out when attempting to programatically set the 
>username? Thanks again.
>
><ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
>			<ramp:user>alice</ramp:user>
>			<ramp:passwordCallbackClass>
>org.apache.rampart.samples.policy.sample01.PWCBHandler</ramp:pa
>sswordCal
>lbackClass>
></ramp:RampartConfig>
>
>
>Regards
>--------------
>Sanjay Vivek
>Web Analyst
>Middleware Team
>ISS
>University of Newcastle Upon Tyne
>