Hi,
Try please following code to extract the username:
List recv = (List)context.getMessageContext().get("RECV_RESULTS");
for (Object obj : recv) {
WSHandlerResult wsResult = (WSHandlerResult)obj;
WSSecurityEngineResult wsseResult =
(WSSecurityEngineResult)wsResult.getResults().get(0);
System.out.println(((Principal)
wsseResult.get(WSSecurityEngineResult.TAG_PRINCIPAL)).getName());
}
I guess the message context principle was initialized with X509 certificate
subject DN used for Encryption.
Regards,
Andrei.
From: Paul Avijit [mailto:[email protected]]
Sent: Mittwoch, 7. Mai 2014 13:53
To: Andrei Shakirin; [email protected]
Subject: Re: Getting UserId from WS-Security UsernameToken
Thanks Andrei.
I tired the code you provided but I get NULL AuthorizationPolicy. I found the
following code which worked.
@Resource
WebServiceContext context;
LOG.debug("UserName: [" + context.getUserPrincipal().getName() + "]");
But this works only when WSS4JInInterceptor has action="UsernameToken".
When action="UsernameToken Timestamp Signature Encrypt", the same code gives CN
of the X.509 certificate.
Can you please help to get the username in the UsernameToken in this case.
Regards
Paul
On Wednesday, May 7, 2014 3:03 AM, Andrei Shakirin <[email protected]> wrote:
Hi Paul,
CXF packs username and password into AuthorizationPolicy.
The code could look like:
@Resource
WebServiceContext context;
AuthorizationPolicy policy = (AuthorizationPolicy) context
.getMessageContext().get(AuthorizationPolicy.class.getName());
System.out.println("User name: " + policy.getUserName());
System.out.println("Password: " + policy.getPassword());
Regards,
Andrei.
> -----Original Message-----
> From: Paul Avijit [mailto:[email protected]]
> Sent: Dienstag, 6. Mai 2014 19:54
> To: [email protected]
> Subject: Getting UserId from WS-Security UsernameToken
>
> Hi,
>
> How can I get the UserId from WS-Security UsernameToken in the
> implementation class.
>
>
> Thanks in advance.
>
> Regards
> Paul