You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ma...@nordea.com on 2008/03/31 13:29:21 UTC

How to add WS-Security header in Axis2 client

Hi all,

We need to develop an Axis2 web service client towards our partner. I've
generate client stub and everything works fine except that I couldn't
find a way to programatically set username and password in WS-Security
header. 

Besides manipulate the XML request, is there a way to set username and
password programatically when invoking a web service that requires
WS-Security header?

Any suggestion is appreciated.

Best wishes,
Mai Sun

Re: How to add WS-Security header in Axis2 client

Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi,
  Do you know the security configuration of the server ? Inflow
security parameter to be exact.

   <parameter name="InflowSecurity">
      <action>
        <items>....</items>
      </action>
    </parameter>

thanks,
/nandana

On Mon, Mar 31, 2008 at 6:32 PM,  <ma...@nordea.com> wrote:
> Hi Nandana,
>
>  I checked the WSDL provided by the server and it doesn't contain
>  security policy.
>  Is there any way to get the client work without security policy?
>
>  Thanks a lot in advance.
>
>
>  Regards,
>  Mai Sun
>
>  -----Original Message-----
>  From: Nandana Mihindukulasooriya [mailto:nandana.cse@gmail.com]
>
>
> Sent: 31 March 2008 14:59
>  To: axis-user@ws.apache.org; Sun, Mai
>  Subject: Re: How to add WS-Security header in Axis2 client
>
>  Hi Mai,
>        It seems that you are using parameter based configuration is the
>  server side. Please check the WSDL against which you generated code to
>  check whether it contains any security policies. The code snippet you
>  have given should work, if the WSDL is policy annotated ( So Axis2 code
>  generator must have attached those policies to the Stub). But as you are
>  using parameter based configuration of Rampart in server side, I doubt
>  whether the WSDL contain any policy information.
>
>  thanks,
>  /nandana
>
>  P.S. : I think this discussion should happen in the user list, so
>  replying to the user list.
>
>  On Mon, Mar 31, 2008 at 5:56 PM,  <ma...@nordea.com> wrote:
>  > Dear Nandana,
>  >
>  >  Thank you very much for your reply. I've read through the tutorial
>  > you  sent me and I'm able to engage Rampart in my Axis2 client.
>  > However, when  I sent the request I got the error "WSDoAllReceiver:
>  > Incoming message  does not contain required Security header". It seems
>
>  > to me that the WSS  header was not added to the SOAP request. Below is
>  my client side code:
>  >
>  >                         ConfigurationContext ctx =
>  > ConfigurationContextFactory
>  >
>  >  .createConfigurationContextFromFileSystem(
>  >                                                         "repository",
>
>  > null);
>  >                         TradeRetrieverServiceStub stub = new
>  > TradeRetrieverServiceStub(
>  >                                         ctx,
>  >
>  >  ConfigReader.getInstance().readConfig().getEndPoint());
>  >                         ServiceClient sc = stub._getServiceClient();
>  >                         sc.engageModule("rampart");
>  >                         ServiceClient client =
>  stub._getServiceClient();
>  >                         Options options = client.getOptions();
>  >
>  >  options.setUserName(ConfigReader.getInstance().readConfig()
>  >                                         .getUsername());
>  >
>  >  options.setPassword(ConfigReader.getInstance().readConfig()
>  >                                         .getPassword());
>  >                         GetTrades request = new GetTrades();
>  >                         TradeFilterDTO filter = new TradeFilterDTO();
>  >                         Calendar cal = Calendar.getInstance();
>  >                         cal.set(cal.DATE, cal.get(cal.DATE) - 1);
>  >                         filter.setFromModifyTime(cal);
>  >                         request.setFilter(filter);
>  >                         GetTradesResponse resp =
>  > stub.getTrades(request);
>  >
>  >  System.out.println(resp.get_return().getDepositTrades());
>  >
>  >  The server side is also based on Axis2 and it uses Rampart to check
>  > the  username and password.
>  >
>  >  Please let me know if my code is correct, thanks a lot!
>  >
>  >  Regards,
>  >  Mai Sun
>  >
>  >
>  >
>  >  -----Original Message-----
>  >  From: Nandana Mihindukulasooriya [mailto:nandana.cse@gmail.com]
>  >  Sent: 31 March 2008 13:38
>  >  To: axis-dev@ws.apache.org
>  >  Subject: Re: How to add WS-Security header in Axis2 client
>  >
>  >  Hi Mai Sun,
>  >
>  >  >  is there a way to set username and  > password programatically
>  > when invoking a web service that requires  > WS-Security header?
>  >
>  >  use
>  >     ServiceClient sc = stub._getServiceClient();
>  >     Options options = sc.getOptions();
>  >     options.setUserName("username");
>  >     options.setPassword("password");
>  >
>  >  take a look at this tutorial [1] for more information.
>  >
>  >  thanks,
>  >  /nandana
>  >
>  >  [1] - http://wso2.org/library/3190
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>  >  For additional commands, e-mail: axis-dev-help@ws.apache.org
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>  >  For additional commands, e-mail: axis-dev-help@ws.apache.org
>  >
>  >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to add WS-Security header in Axis2 client

Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi Mai,
       It seems that you are using parameter based configuration is
the server side. Please check the WSDL against which you generated
code to check whether it contains any security policies. The code
snippet you have given should work, if the WSDL is policy annotated (
So Axis2 code generator must have attached those policies to the
Stub). But as you are using parameter based configuration of Rampart
in server side, I doubt whether the WSDL contain any policy
information.

thanks,
/nandana

P.S. : I think this discussion should happen in the user list, so
replying to the user list.

On Mon, Mar 31, 2008 at 5:56 PM,  <ma...@nordea.com> wrote:
> Dear Nandana,
>
>  Thank you very much for your reply. I've read through the tutorial you
>  sent me and I'm able to engage Rampart in my Axis2 client. However, when
>  I sent the request I got the error "WSDoAllReceiver: Incoming message
>  does not contain required Security header". It seems to me that the WSS
>  header was not added to the SOAP request. Below is my client side code:
>
>                         ConfigurationContext ctx =
>  ConfigurationContextFactory
>
>  .createConfigurationContextFromFileSystem(
>                                                         "repository",
>  null);
>                         TradeRetrieverServiceStub stub = new
>  TradeRetrieverServiceStub(
>                                         ctx,
>
>  ConfigReader.getInstance().readConfig().getEndPoint());
>                         ServiceClient sc = stub._getServiceClient();
>                         sc.engageModule("rampart");
>                         ServiceClient client = stub._getServiceClient();
>                         Options options = client.getOptions();
>
>  options.setUserName(ConfigReader.getInstance().readConfig()
>                                         .getUsername());
>
>  options.setPassword(ConfigReader.getInstance().readConfig()
>                                         .getPassword());
>                         GetTrades request = new GetTrades();
>                         TradeFilterDTO filter = new TradeFilterDTO();
>                         Calendar cal = Calendar.getInstance();
>                         cal.set(cal.DATE, cal.get(cal.DATE) - 1);
>                         filter.setFromModifyTime(cal);
>                         request.setFilter(filter);
>                         GetTradesResponse resp =
>  stub.getTrades(request);
>
>  System.out.println(resp.get_return().getDepositTrades());
>
>  The server side is also based on Axis2 and it uses Rampart to check the
>  username and password.
>
>  Please let me know if my code is correct, thanks a lot!
>
>  Regards,
>  Mai Sun
>
>
>
>  -----Original Message-----
>  From: Nandana Mihindukulasooriya [mailto:nandana.cse@gmail.com]
>  Sent: 31 March 2008 13:38
>  To: axis-dev@ws.apache.org
>  Subject: Re: How to add WS-Security header in Axis2 client
>
>  Hi Mai Sun,
>
>  >  is there a way to set username and
>  > password programatically when invoking a web service that requires
>  > WS-Security header?
>
>  use
>     ServiceClient sc = stub._getServiceClient();
>     Options options = sc.getOptions();
>     options.setUserName("username");
>     options.setPassword("password");
>
>  take a look at this tutorial [1] for more information.
>
>  thanks,
>  /nandana
>
>  [1] - http://wso2.org/library/3190
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>  For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>  For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: How to add WS-Security header in Axis2 client

Posted by ma...@nordea.com.
Dear Nandana,

Thank you very much for your reply. I've read through the tutorial you
sent me and I'm able to engage Rampart in my Axis2 client. However, when
I sent the request I got the error "WSDoAllReceiver: Incoming message
does not contain required Security header". It seems to me that the WSS
header was not added to the SOAP request. Below is my client side code:

			ConfigurationContext ctx =
ConfigurationContextFactory
	
.createConfigurationContextFromFileSystem(
							"repository",
null);
			TradeRetrieverServiceStub stub = new
TradeRetrieverServiceStub(
					ctx, 		
	
ConfigReader.getInstance().readConfig().getEndPoint());
			ServiceClient sc = stub._getServiceClient();
			sc.engageModule("rampart");
			ServiceClient client = stub._getServiceClient();
			Options options = client.getOptions();
	
options.setUserName(ConfigReader.getInstance().readConfig()
					.getUsername());
	
options.setPassword(ConfigReader.getInstance().readConfig()
					.getPassword());
			GetTrades request = new GetTrades();
			TradeFilterDTO filter = new TradeFilterDTO();
			Calendar cal = Calendar.getInstance();
			cal.set(cal.DATE, cal.get(cal.DATE) - 1);
			filter.setFromModifyTime(cal);
			request.setFilter(filter);
			GetTradesResponse resp =
stub.getTrades(request);
	
System.out.println(resp.get_return().getDepositTrades());

The server side is also based on Axis2 and it uses Rampart to check the
username and password. 

Please let me know if my code is correct, thanks a lot!

Regards,
Mai Sun

-----Original Message-----
From: Nandana Mihindukulasooriya [mailto:nandana.cse@gmail.com] 
Sent: 31 March 2008 13:38
To: axis-dev@ws.apache.org
Subject: Re: How to add WS-Security header in Axis2 client

Hi Mai Sun,

>  is there a way to set username and
> password programatically when invoking a web service that requires 
> WS-Security header?

use
    ServiceClient sc = stub._getServiceClient();
    Options options = sc.getOptions();
    options.setUserName("username");
    options.setPassword("password");

take a look at this tutorial [1] for more information.

thanks,
/nandana

[1] - http://wso2.org/library/3190

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Re: How to add WS-Security header in Axis2 client

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

>  is there a way to set username and
> password programatically when invoking a web service that requires
> WS-Security header?

use
    ServiceClient sc = stub._getServiceClient();
    Options options = sc.getOptions();
    options.setUserName("username");
    options.setPassword("password");

take a look at this tutorial [1] for more information.

thanks,
/nandana

[1] - http://wso2.org/library/3190

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org