You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ericcho <er...@kryos.com> on 2009/04/24 21:35:19 UTC

username token using codegen stub

Hi all,

I have created a web service
client using the axis 2 codegen wizard plugin for eclipse.

The web service that is being
consumed requires a time sensitive username token.

I have looked at the rampart
samples but I'm receiving the following exception when performing the call:

4/24/09 12:27:30:321 MDT]
00000061 SystemErr &nbsp; &nbsp; R org.apache.axis2.AxisFault:
WSDoAllReceiver:
Incoming message does not contain required Security header
[4/24/09 12:27:30:321 MDT]
00000061 SystemErr &nbsp; &nbsp; R &nbsp; &nbsp; &nbsp; &nbsp; at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
[4/24/09 12:27:30:321 MDT]
00000061 SystemErr &nbsp; &nbsp; R &nbsp; &nbsp; &nbsp; &nbsp; at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
[4/24/09 12:27:30:321 MDT]
00000061 SystemErr &nbsp; &nbsp; R &nbsp; &nbsp; &nbsp; &nbsp; at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
[4/24/09 12:27:30:321 MDT]
00000061 SystemErr &nbsp; &nbsp; R &nbsp; &nbsp; &nbsp; &nbsp; at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)


I have the following in my
axis2.xml

&lt;parameter
name=&quot;OutflowSecurity&quot;&gt;
&nbsp; &nbsp; &nbsp; &lt;action&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;items&gt;UsernameToken&lt;/items&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;user&gt;bob&lt;/user&gt;
&nbsp; &nbsp; &nbsp; &nbsp;
&lt;passwordCallbackClass&gt;ca.ab.abc.def.handlers.PasswordHandler&lt;/passwordCallbackClass&gt;
&nbsp; &nbsp; &nbsp; &nbsp;
&lt;passwordType&gt;PasswordText&lt;/passwordType&gt;
&nbsp; &nbsp; &nbsp; &lt;/action&gt;
&nbsp; &nbsp; &lt;/parameter&gt;


And the code that performs
the request is as follows....

1 ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(&quot;C:\\workspaces\\abc\\myabcCommon\\&quot;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
2 UserProfileServiceStub.GetUserAccessAssignmentsByUserId
userId = new
UserProfileServiceStub.GetUserAccessAssignmentsByUserId();
3 userId.setUserId(&quot;aUserId&quot;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
4 UserProfileServiceStub stub = new
UserProfileServiceStub(ctx);

5 GetUserAccessAssignmentsByUserIdResponse
response = &nbsp;stub.getUserAccessAssignmentsByUserId(userId);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
6 AccessAssignment[] accessAssignments
= &nbsp; response.get_return();



And the exception occurs at
line 5 &nbsp;I've also verified through a packet sniffer that the request
doesn't have the username token in the soap header and a debug point in
the PasswordHandler is never hit.

Note: &nbsp;Rampart 1.3 with
Axis2 - 1.4.1

Any help is appreciated.

Thanks,
Eric









-- 
View this message in context: http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23223433.html
Sent from the Axis - User mailing list archive at Nabble.com.

Re: username token using codegen stub

Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi Eric,

How does your policy look like and are you sure that the security is added
to your soap header, could use tcpmon to look at the messages on the wire.

What I normally do for a simple secured ws is
1.Construct the wsdl and add some policy to a operation/porttype etc
2.Generate the code with axis2 wsdl2code
3.Add the policy to the services.xml usually in a operation element  and
engaging rampart as a module for the service.
4. make the client program, using the stub created. This client will then
also have the policy from the wsdl embedded in the generated code, you can
see this I you have access to the source code of the stub you are using. And
add username/password and explaned in a earlier mail.

I'm not an expert, but have made some mistakes and hopefully learned from
them.

Hope it helps

cheers, Håkon
2009/4/27 ericcho <er...@kryos.com>

>
> Thanks again Hakon....
>
> My code is as follows:
>
>
> String userid = "aUserId";
> ConfigurationContext ctx =
>
> ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:\\dir1\\dir2\\dir3\\");
> UserProfileStub stub = new UserProfileStub (ctx );
> ServiceClient serviceClient = stub._getServiceClient();
> serviceClient.engageModule("rampart");
>
> Options options = serviceClient.getOptions();
> options.setUserName("myUserName");
> options.setPassword("myPassword");
>
> serviceClient.setOptions(options);
>
> AccessAssignment[] aa =
> stub.getUserAccessAssignmentsByUserId(userId).get_return();
>
>
> The following exception is thrown on the last line of code.   I'm guessing
> it is because the web service being consumed is time sensitive.  Are there
> any other options i should be setting for this?   Or something else I have
> to add to the axis2.xml?
>
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R
> org.apache.axis2.AxisFault: WSDoAllReceiver: Incoming message does not
> contain required Security header
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R     at
>
> org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R     at
>
> org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R     at
>
> org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R     at
>
> org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R     at
> org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
>
> Thanks,
> Eric
> --
> View this message in context:
> http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23265276.html
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>


-- 
Håkon Sagehaug, Scientific Programmer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)

Re: username token using codegen stub

Posted by Ed Komp <ko...@ittc.ku.edu>.
Eric,

In a slightly later response to your email,
Hakon Sagehaug provides additional details to check.

> What I normally do for a simple secured ws is
> 1.Construct the wsdl and add some policy to a operation/porttype etc
> 2.Generate the code with axis2 wsdl2code
> 3.Add the policy to the services.xml usually in a operation element   
> and engaging rampart as a module for the service.
> 4. make the client program, using the stub created. This client will  
> then also have the policy from the wsdl embedded in the generated  
> code, you can see this I you have access to the source code of the  
> stub you are using. And add username/password and explaned in a  
> earlier mail.

One detail he did not mention, however, is that these steps work ONLY  
IF you are using WSDL 1.1
to describe your service.
IF you use WSDL 2.0, then the WSDL2Java utility does NOT embed the  
policy into the generated stub.
There is a JIRA about this:  AXIS2-4272 Service stub missing WS-Policy  
information when codegen with WSDL20


Ed Komp

>
> Thanks again Hakon....
>
> My code is as follows:
>
>
> String userid = "aUserId";
> ConfigurationContext ctx =
> ConfigurationContextFactory 
> .createConfigurationContextFromFileSystem("C:\\dir1\\dir2\\dir3\\");
> UserProfileStub stub = new UserProfileStub (ctx );
> ServiceClient serviceClient = stub._getServiceClient();	
> serviceClient.engageModule("rampart");
> 		
> Options options = serviceClient.getOptions();
> options.setUserName("myUserName");
> options.setPassword("myPassword");
> 		
> serviceClient.setOptions(options);
> 		
> AccessAssignment[] aa =
> stub.getUserAccessAssignmentsByUserId(userId).get_return();
>
>
> The following exception is thrown on the last line of code.   I'm  
> guessing
> it is because the web service being consumed is time sensitive.  Are  
> there
> any other options i should be setting for this?   Or something else  
> I have
> to add to the axis2.xml?
>
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R
> org.apache.axis2.AxisFault: WSDoAllReceiver: Incoming message does not
> contain required Security header
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
> org 
> .apache 
> .axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
> org 
> .apache 
> .axis2 
> .description 
> .OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
> org 
> .apache 
> .axis2 
> .description.OutInAxisOperationClient.send(OutInAxisOperation.java: 
> 416)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
> org 
> .apache 
> .axis2 
> .description 
> .OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
> [4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
> org.apache.axis2.client.OperationClient.execute(OperationClient.java: 
> 163)
>
> Thanks,
> Eric

Re: username token using codegen stub

Posted by ericcho <er...@kryos.com>.
Thanks again Hakon....

My code is as follows:


String userid = "aUserId";
ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:\\dir1\\dir2\\dir3\\");
UserProfileStub stub = new UserProfileStub (ctx );
ServiceClient serviceClient = stub._getServiceClient();	
serviceClient.engageModule("rampart");
		
Options options = serviceClient.getOptions();
options.setUserName("myUserName");
options.setPassword("myPassword");
		
serviceClient.setOptions(options);
		
AccessAssignment[] aa = 
stub.getUserAccessAssignmentsByUserId(userId).get_return();


The following exception is thrown on the last line of code.   I'm guessing
it is because the web service being consumed is time sensitive.  Are there
any other options i should be setting for this?   Or something else I have
to add to the axis2.xml?

[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R
org.apache.axis2.AxisFault: WSDoAllReceiver: Incoming message does not
contain required Security header
[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
[4/27/09 14:49:00:515 MDT] 00000063 SystemErr     R 	at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

Thanks,
Eric
-- 
View this message in context: http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23265276.html
Sent from the Axis - User mailing list archive at Nabble.com.


Re: username token using codegen stub

Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi

Can do the call from the stub

cheers, håkon

2009/4/27 ericcho <er...@kryos.com>

>
> Thanks for your response Hakon.
>
> So... once I've done the following:
>
> ServiceClient serviceClient = stub._getServiceClient();
> serviceClient.engageModule("rampart");
>
> Options options = serviceClient.getOptions();
>
> options.setUserName("testunser");
> options.setPassword("pass");
>
> serviceClient.setOptions(options);
>
> Do I have to make the call from the serviceClient?
>
> Or I can simply call the methods in the stub?
>
> ie:   stub.getMeThisStuff(....);
> This method would be preferable, but I don't see how the stub would have
> context to the options.... or does it?
>
> Thanks,
> Eric
> --
> View this message in context:
> http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23257657.html
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>


-- 
Håkon Sagehaug, Scientific Programmer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)

Re: username token using codegen stub

Posted by ericcho <er...@kryos.com>.
Thanks for your response Hakon.

So... once I've done the following:

ServiceClient serviceClient = stub._getServiceClient();
serviceClient.engageModule("rampart");

Options options = serviceClient.getOptions();

options.setUserName("testunser");
options.setPassword("pass");

serviceClient.setOptions(options);

Do I have to make the call from the serviceClient? 

Or I can simply call the methods in the stub?

ie:   stub.getMeThisStuff(....);
This method would be preferable, but I don't see how the stub would have
context to the options.... or does it?

Thanks,
Eric
-- 
View this message in context: http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23257657.html
Sent from the Axis - User mailing list archive at Nabble.com.


Re: username token using codegen stub

Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi

You have to engaged the rampart module one way is to do it like this

ServiceClient serviceClient = stub._getServiceClient();
            serviceClient.engageModule("rampart");


Where stubis the generated client stub from the WSDL
Then you can set your username and password like this

            Options options = serviceClient.getOptions();

            options.setUserName("testunser");
            options.setPassword("pass");

             serviceClient.setOptions(options);

Hope this helps quickstart[1] for rampart aslo can help you, and the samples

hope this helps

cheers. Håkon

[1] http://ws.apache.org/rampart/quick-start.html





2009/4/24 ericcho <er...@kryos.com>

> Hi all,
>
> I have created a web service client using the axis 2 codegen wizard plugin
> for eclipse.
>
> The web service that is being consumed requires a time sensitive username
> token.
>
> I have looked at the rampart samples but I'm receiving the following
> exception when performing the call:
>
> 4/24/09 12:27:30:321 MDT] 00000061 SystemErr     R
> org.apache.axis2.AxisFault: WSDoAllReceiver: Incoming message does not
> contain required Security header
> [4/24/09 12:27:30:321 MDT] 00000061 SystemErr     R         at
> org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(*
> Utils.java:512*)
> [4/24/09 12:27:30:321 MDT] 00000061 SystemErr     R         at
> org.apache.axis2.description.OutInAxisOperationClient.handleResponse(*
> OutInAxisOperation.java:370*)
> [4/24/09 12:27:30:321 MDT] 00000061 SystemErr     R         at
> org.apache.axis2.description.OutInAxisOperationClient.send(*
> OutInAxisOperation.java:416*)
> [4/24/09 12:27:30:321 MDT] 00000061 SystemErr     R         at
> org.apache.axis2.description.OutInAxisOperationClient.executeImpl(*
> OutInAxisOperation.java:228*)
>
>
> I have the following in my axis2.xml
>
> <parameter name=*"OutflowSecurity"*>
>       <action>
>         <items>UsernameToken</items>
>         <user>bob</user>
>         <passwordCallbackClass>*ca*.*ab*.abc.def.handlers.PasswordHandler
> </passwordCallbackClass>
>         <passwordType>PasswordText</passwordType>
>       </action>
>     </parameter>
>
>
> And the code that performs the request is as follows....
>
> 1 ConfigurationContext ctx = ConfigurationContextFactory.*
> createConfigurationContextFromFileSystem*(
> "C:\\workspaces\\abc\\myabcCommon\\");
>
> 2 UserProfileServiceStub.GetUserAccessAssignmentsByUserId userId = *new*UserProfileServiceStub.GetUserAccessAssignmentsByUserId();
> 3 userId.setUserId("aUserId");
>
> 4 UserProfileServiceStub stub = *new* UserProfileServiceStub(ctx);
>
> 5 GetUserAccessAssignmentsByUserIdResponse response =
>  stub.getUserAccessAssignmentsByUserId(userId);
>
> 6 AccessAssignment[] *accessAssignments* =   response.get_return();
>
>
> And the exception occurs at line 5  I've also verified through a packet
> sniffer that the request doesn't have the username token in the soap header
> and a debug point in the PasswordHandler is never hit.
>
> Note:  Rampart 1.3 with Axis2 - 1.4.1
>
> Any help is appreciated.
>
> Thanks,
> Eric
>
>
>
>
>
>
>
>
>
> ------------------------------
> View this message in context: username token using codegen stub<http://www.nabble.com/username-token-using-codegen-stub-tp23223433p23223433.html>
> Sent from the Axis - User mailing list archive<http://www.nabble.com/Axis---User-f232.html>at Nabble.com.
>



-- 
Håkon Sagehaug, Scientific Programmer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)