10

In my WebService I need to log the caller's id, but wsContext.getUserPrincipal() returns null even though the user was authenticated using WS-Security with password authentication. According to the JavaDocs for JAX-WS 2.1 WSContext.getUserPrincipal() should only return null if the user has not been authenticated.

Do I have to do something in the security handler to set the user principal into the WSContext? The docs seem to indicate that it is done automatically.

I'm using the metro 1.1 stack (1.1.5 I think) with jax-ws 2.1.3 stack on Tomcat.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
  • I'm wondering if this is working now. In one of my past projects we used the WSContext.getUserPrincipal() and it was working. However we were doing HTTP Basic authentication. – Udo Held Nov 19 '11 at 21:17
  • Metro 1.1 is quite old, maybe metro 1.4 solves the problem. For the other hand, could you append all your WsContext dump here? – korifey Dec 28 '11 at 12:07

1 Answers1

1

Try iterating over wsContext.getMessageContext().entrySet() and displaying the values, sometimes they are there but for some reason not retrievable by the getUserPrincipal() method.

In this case just grab you principal directly from there and leave a comment to future you that this is not very portable.

MahdeTo
  • 11,034
  • 2
  • 27
  • 28