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 Herman D'costa <hd...@digev.com> on 2003/09/23 01:34:00 UTC

getUsername

Hello

I am writing axis request and response handlers for a web service application. If I want the real username of the user of the request, how do I get it? Should I get it from the Message Context, thru a call to msgContext.getUsername or should I retrieve the Servlet Request object and get its remote user? How does the msg context get the user name from?

Any pointers to documentation with related information, for related questions that might come up, will be greatly appreciated.

Thanks, regds
Herman D'Costa


Re: getUsername

Posted by Stephen Gordon <st...@student.usyd.edu.au>.
I think the username is only set in the MessageContext if the client has 
passed one explicitly.

The only way I could figure out to set the MessageContext username in 
the client is to obtain the service stub as a java.xml.rpc.Stub (you 
probably need to cast it) and call 
_setProperty(javax.xml.rpc.Call.USERNAME_PROPERTY, strUsername) on it.

This was inspired by the following code in MessageContext:

--------------------SNIP--------------------
     public void setProperty(String name, Object value) {
	if (name == null || value == null) {
		return;
	}
	else if (name.equals(Call.USERNAME_PROPERTY)) {
		...
		setUsername((String)value)
	}
	....
     }
--------------------SNIP--------------------

Note that java.xml.rpc.Stub also has a static USERNAME_PROPERTY member 
but for some reason axis doesn't check it. (I wonder why??)

If there's a better way to do this I'd love to know!!

stephen


Herman D'costa wrote:

> Hello
> 
> I am writing axis request and response handlers for a web service 
> application. If I want the real username of the user of the request, how 
> do I get it? Should I get it from the Message Context, thru a call to 
> msgContext.getUsername or should I retrieve the Servlet Request object 
> and get its remote user? How does the msg context get the user name from?
> 
> Any pointers to documentation with related information, for related 
> questions that might come up, will be greatly appreciated.
> 
> Thanks, regds
> Herman D'Costa
>