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 Chad DeBauch <cd...@gmail.com> on 2007/06/21 16:57:19 UTC

Get the username from UsernameTokens in Skeleton class

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

Re: Get the username from UsernameTokens in Skeleton class

Posted by Bryan Carpenter <db...@ecs.soton.ac.uk>.
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 `<UsernameToken/>' 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* <cdebauch@gmail.com
 > <ma...@gmail.com>> 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 Carpenter                        Phone: +44 (0) 23 8059 8814
OMII, University of Southampton                 FAX  : +44 (0) 23 8059 8870
6005 Faraday Building, Highfield Campus         Email: dbc@ecs.soton.ac.uk
Southampton SO17 1BJ, UK                        URL  : www.hpjava.org
_____________________________________________________________________________



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


Re: Get the username from UsernameTokens in Skeleton class

Posted by Chad DeBauch <cd...@gmail.com>.
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 <cd...@gmail.com> 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
>