Another way is outlined at:
http://wiki.apache.org/ws/FrontPage/WsFx/wss4jFAQ#usernme
An interpretation of this I've been using is:
import org.apache.axis2.context.MessageContext ;
import java.util.Vector ;
import org.apache.ws.security.handler.WSHandlerResult ;
import org.apache.ws.security.handler.WSHandlerConstants ;
import org.apache.ws.security.WSSecurityEngineResult ;
import org.apache.ws.security.util.WSSecurityUtil ;
import org.apache.ws.security.WSConstants ;
import org.apache.ws.security.WSUsernameTokenPrincipal ;
import java.security.Principal;
[...]
public String helloUsername() throws Exception {
MessageContext msgCtx = MessageContext.getCurrentMessageContext() ;
Vector results =
(Vector)
msgCtx.getProperty(WSHandlerConstants.RECV_RESULTS) ;
// Results for all chained `RampartReceiver' etc handlers.
WSHandlerResult rResult = (WSHandlerResult) results.get(0) ;
// Result object for final handler.
Vector wsResult = rResult.getResults() ;
// Results for all actions by this handler.
WSSecurityEngineResult actionResult =
WSSecurityUtil.fetchActionResult(wsResult, WSConstants.UT) ;
// Result for `UsernameToken' action.
Principal principal = actionResult.getPrincipal() ;
// Principal extracted from `' element.
WSUsernameTokenPrincipal wsPrincipal =
(WSUsernameTokenPrincipal) principal ;
return "Hello " + wsPrincipal.getName() + "!" ;
}
Bryan
Chad DeBauch wrote:
> I figured out how to do this. I got the SOAP Envelope from the
> MessageContext by calling getEnvelope() and parsing the SOAP Header for
> the username. I was hoping there were some helper methods that would do
> that for you but now it is done.
>
> Chad
>
> On 6/21/07, *Chad DeBauch* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> How do I get the username that was in the SOAP UsernameToken from my
> skeleton class? Is there a way to retrieve it from the
> MessageContext? I am using Rampart to validate the UsernameTokens
> using a PWCallback class.
>
> Thanks,
>
> Chad
>
>
--
_
Dr David Bryan CarpenterPhone: +44 (0) 23 8059 8814
OMII, University of Southampton FAX : +44 (0) 23 8059 8870
6005 Faraday Building, Highfield Campus Email: [EMAIL PROTECTED]
Southampton SO17 1BJ, UKURL : www.hpjava.org
_
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]