You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by Benjamin Pieritz <de...@wistedter-jungs.de> on 2006/02/20 23:41:46 UTC

Retrieving username from UsernameToken at service_port

Hi,

I was wondering if there is a way to retrieve the username, used by 
UsernameToken at the actual service class.

The idea is:
Since every message already provides a valid username I don't wanna pass 
it to the service port by parameter.

There was one example which I probably could use but I'm hoping that 
there is an easier way and I'm neither sure that this is always acting 
like expected.

--- example ---
// get the message context first
MessageContext msgContext = MessageContext.getCurrentContext();
Message reqMsg = msgContext.getRequestMessage();

Vector results = null;
// get the result Vector from the property
if ((results = (Vector) 
msgContext.getProperty(WSHandlerConstants.RECV_RESULTS))
              == null) {
             System.out.println("No security results!!");
}
System.out.println("Number of results: " + results.size());Retrieving
for (int i = 0; i < results.size(); i++) {
      WSHandlerResult hResult = (WSHandlerResult)results.get(i);
      String actor = hResult.getActor();
      Vector hResults = hResult.getResults();
      for (int j = 0; j < hResults.size(); j++) {
       	WSSecurityEngineResult eResult = (WSSecurityEngineResult) 
hResults.get(j);
         // Note: an encryption action does not have an associated principal
         // only Signature and UsernameToken actions return a principal
         if (eResult.getAction() != WSConstants.ENCR) {
                    System.out.println(eResult.getPrincipal().getName());
         }
     }
}


System.out.println(eResult.getPrincipal().getName()); is returning the 
username so far.

Thanks in advance
-Benjamin

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


Re: Retrieving username from UsernameToken at service_port

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Benjamin,

You can get all the information about the UsernameToken at the service
impl with a slight modification to the code that you mentioned.

>          if (eResult.getAction() != WSConstants.ENCR) {
>                     System.out.println(eResult.getPrincipal().getName());
>          }

The above can be replaced with the following to get cast the Principal
object to a WSUsernameTokenPrincipal in the case of UsernameToken.

if(wser.getAction() == WSConstants.UT && wser.getPrincipal() != null) {
                        WSUsernameTokenPrincipal utPrincipal =
(WSUsernameTokenPrincipal) wser.getPrincipal();
                        System.out.println(utPrincipal.getPassword());
                        System.out.println(utPrincipal.getName());
                        System.out.println(utPrincipal.getCreatedTime());
                        System.out.println(utPrincipal.getNonce());
                        System.out.println(utPrincipal.getPasswordType());
}

Hope this helps.

Thanks,
Ruchith

On 2/21/06, Benjamin Pieritz <de...@wistedter-jungs.de> wrote:
> Hi,
>
> I was wondering if there is a way to retrieve the username, used by
> UsernameToken at the actual service class.
>
> The idea is:
> Since every message already provides a valid username I don't wanna pass
> it to the service port by parameter.
>
> There was one example which I probably could use but I'm hoping that
> there is an easier way and I'm neither sure that this is always acting
> like expected.
>
> --- example ---
> // get the message context first
> MessageContext msgContext = MessageContext.getCurrentContext();
> Message reqMsg = msgContext.getRequestMessage();
>
> Vector results = null;
> // get the result Vector from the property
> if ((results = (Vector)
> msgContext.getProperty(WSHandlerConstants.RECV_RESULTS))
>               == null) {
>              System.out.println("No security results!!");
> }
> System.out.println("Number of results: " + results.size());Retrieving
> for (int i = 0; i < results.size(); i++) {
>       WSHandlerResult hResult = (WSHandlerResult)results.get(i);
>       String actor = hResult.getActor();
>       Vector hResults = hResult.getResults();
>       for (int j = 0; j < hResults.size(); j++) {
>         WSSecurityEngineResult eResult = (WSSecurityEngineResult)
> hResults.get(j);
>          // Note: an encryption action does not have an associated principal
>          // only Signature and UsernameToken actions return a principal
>          if (eResult.getAction() != WSConstants.ENCR) {
>                     System.out.println(eResult.getPrincipal().getName());
>          }
>      }
> }
>
>
> System.out.println(eResult.getPrincipal().getName()); is returning the
> username so far.
>
> Thanks in advance
> -Benjamin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: wss4j-dev-help@ws.apache.org
>
>

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


Re: Retrieving username from UsernameToken at service_port

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Benjamin,

You can get all the information about the UsernameToken at the service
impl with a slight modification to the code that you mentioned.

>          if (eResult.getAction() != WSConstants.ENCR) {
>                     System.out.println(eResult.getPrincipal().getName());
>          }

The above can be replaced with the following to get cast the Principal
object to a WSUsernameTokenPrincipal in the case of UsernameToken.

if(wser.getAction() == WSConstants.UT && wser.getPrincipal() != null) {
                        WSUsernameTokenPrincipal utPrincipal =
(WSUsernameTokenPrincipal) wser.getPrincipal();
                        System.out.println(utPrincipal.getPassword());
                        System.out.println(utPrincipal.getName());
                        System.out.println(utPrincipal.getCreatedTime());
                        System.out.println(utPrincipal.getNonce());
                        System.out.println(utPrincipal.getPasswordType());
}

Hope this helps.

Thanks,
Ruchith

On 2/21/06, Benjamin Pieritz <de...@wistedter-jungs.de> wrote:
> Hi,
>
> I was wondering if there is a way to retrieve the username, used by
> UsernameToken at the actual service class.
>
> The idea is:
> Since every message already provides a valid username I don't wanna pass
> it to the service port by parameter.
>
> There was one example which I probably could use but I'm hoping that
> there is an easier way and I'm neither sure that this is always acting
> like expected.
>
> --- example ---
> // get the message context first
> MessageContext msgContext = MessageContext.getCurrentContext();
> Message reqMsg = msgContext.getRequestMessage();
>
> Vector results = null;
> // get the result Vector from the property
> if ((results = (Vector)
> msgContext.getProperty(WSHandlerConstants.RECV_RESULTS))
>               == null) {
>              System.out.println("No security results!!");
> }
> System.out.println("Number of results: " + results.size());Retrieving
> for (int i = 0; i < results.size(); i++) {
>       WSHandlerResult hResult = (WSHandlerResult)results.get(i);
>       String actor = hResult.getActor();
>       Vector hResults = hResult.getResults();
>       for (int j = 0; j < hResults.size(); j++) {
>         WSSecurityEngineResult eResult = (WSSecurityEngineResult)
> hResults.get(j);
>          // Note: an encryption action does not have an associated principal
>          // only Signature and UsernameToken actions return a principal
>          if (eResult.getAction() != WSConstants.ENCR) {
>                     System.out.println(eResult.getPrincipal().getName());
>          }
>      }
> }
>
>
> System.out.println(eResult.getPrincipal().getName()); is returning the
> username so far.
>
> Thanks in advance
> -Benjamin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: wss4j-dev-help@ws.apache.org
>
>

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