users@glassfish.java.net

Re: RE: Re: UserPrinciple is null when utilizing Username Authentication w

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Nov 2007 22:41:59 PST

Hi Marco,

   Just to add... i had replied to a similar post earlier :

http://forums.java.net/jive/thread.jspa?messageID=243322
    
>Has anybody successfully retrieved a UserPrinciple from the WebServiceContext
> when doing Username Authentication with Symmetric Keys?
>Everytime I retrieve the UserPrinciple it is null.

Currently we have a proprietary way of retrieving the principal (the getUserPrinciple() on the WebServiceContext is not supported)

 @Resource
 private WebServiceContext wsContext;

  //inside your webservice method do the following.
     try {
            Subject subj = com.sun.xml.wss.SubjectAccessor.getRequesterSubject(wsContext);
            Iterator<Principal> it = subj.getPrincipals().iterator();
            if (it.hasNext()) {
                Principal usernamePassword = it.next();
            }
        } catch (XWSSecurityException ex) {
            //rethrow appropriately
        }
 
   Note : The code above assumes that the first principal is that of the UsernamePassword. In a general case when using Message Security there might be several principals in the Message (and hence the Subject).

We are working towards a better integration of WebServices SOAP Message security with Java EE authentication and authorization mechanisms. Will keep you posted.

Thanks.
[Message sent by forum member 'kumarjayanti' (kumarjayanti)]

http://forums.java.net/jive/thread.jspa?messageID=245154