Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Axis2 username/password Authentication

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

Does anyone know how to set up handlers and apply a username/password header to a SOAP message using an Axis2 based client?

For instance in Axis 1 I can do the following:



Is it possible to do something similar with the Axis2 / Rampart API? I can only find examples that retrieve the username/password information from XML based descriptors.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that there is a way to use Rampart programmatically instead of declaratively, but I've never felt the need to do that. Is there a particular reason you'd like to avoid using deployment descriptors?
[ May 18, 2007: Message edited by: Ulf Dittmer ]
 
Alan Richardson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a front-end website which consumes the services so when a user inputs a username and password it is saved in a session bean and bundled with each request. Hence the 'user.getUserName()' from the snippet of code above.

Might there be a way of using descriptors for multiple users?
 
Alan Richardson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm attempting to use the following (based on the example 11 provided with Rampart 1.1), with no joy.






I receive the following error:
java.lang.NullPointerException at com.ctc.wstx.sw.BaseNsStreamWriter.doWriteDefaultNs(BaseNsStreamWriter.java:528)

I can't find much information about this, although I'm actually receiving the same error when sending non-authenticated messages, so the problem may not be related directly to Rampart. (I originally had Axis2-1.2 running but I had to roll back to Axis2-1.1.1 due to Rampart compatibility).

Any ideas?

[ May 21, 2007: Message edited by: Alan Sunley ]
[ May 21, 2007: Message edited by: Alan Sunley ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find the answer from the following 2 links.

HTTP Transport


Re: AXIS2 1.1.1 problem with BASIC AUTH
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chih-Chieh Huang:
You can find the answer from the following 2 links.

HTTP Transport


Re: AXIS2 1.1.1 problem with BASIC AUTH



These links are about HTTP authentication, not WS-Security authentication (which is really the preferred way, considering the easy availability of Rampart).
 
Alan Richardson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been experimenting with the RPCServiceClient above and find that I can successfully invoke the service from a java application, but not from within a Tomcat webapp.

It doesn't like that I pass a filled Object array containing the webservice method arguments.



However I can pass an empty Object array ( Object[] operationArguments = new Object[] { }; ) without problem. Not particularly useful since I do need to pass arguments.

Are there any know issues invoking a service this way?


Full error trace:

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spent three days trying to figure this out, and this was the top google result so figured i'd put my solution in here for future searchers.

To get this to work, i had to ensure that rampart WASN'T enabled, otherwise I got all sorts of ClassCastExceptions.


import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.types.NonNegativeInteger;
import org.apache.axis2.databinding.types.PositiveInteger;

...


String username, password;

...


ServiceClient client = stub._getServiceClient();
SOAP11Factory factory = new SOAP11Factory();
OMNamespace SecurityElementNamespace = factory.createOMNamespace("http://schemas.xmlsoap.org/ws/2002/04/secext", "wlm");

OMElement usernameTokenEl = factory.createOMElement("UsernameToken", SecurityElementNamespace);
OMElement usernameEl = factory.createOMElement("Username", SecurityElementNamespace);
OMElement passwordEl = factory.createOMElement("Password", SecurityElementNamespace);
usernameEl.setText(username);
passwordEl.setText(password);
usernameTokenEl.addChild(usernameEl);
usernameTokenEl.addChild(passwordEl);

SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl("Security", SecurityElementNamespace, factory);
block.addChild(usernameTokenEl);

client.addHeader(block);
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic