I have a WSO2 ESB WSDL based proxy service which is secured with UsernameToken scenario. This wrapper service is for an Axis2 back-end web service deployed as an .aar file in the WSO2 Application Server. What I want is to retrieve the username used for the authentication in the back-end service.
I tried to get the username using the below Java code, but it always comes back NULL
:
MessageContext msgContext = MessageContext.getCurrentMessageContext();
String username = (String)msgContext.getProperty(RampartMessageData.USERNAME);
It seems that the MessageContext
does not store the Rampart message data. Is there anything I can set in the WSO2 ESB to have that username be passed to the back-end service in the message context?
Thank you!
I guess, You have written a class mediator to retrieve the username from message context. Please note that, username is not in the synapse message context. It is in the axis2 message context. Please try with following code.. inside the your mediator. It has been worked for me.
Axis2MessageContext axis2Msgcontext = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext msgContext = axis2Msgcontext.getAxis2MessageContext();
String userName = (String) msgContext.getProperty("username");
Or else, do you want to retrieve username in BE service (inside AS)? Then, you need to send the user name to BE services. You can use HTTP header, or any other method to send the user name to the BE service. Then you can retrieve it by using Axis2 handler. As an example you can set the user name in to HTTP header as following using synapse configuration in the WSO2ESB. Then header value would be passed to BE service
<header name="UserName" value="Test" />