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" />