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" />
Related
In Enterprise integrator (WSO2) server, How should I know, which application send me the requests?
I need to have application "username" and send the username in body to Endpoint.
There are different ways to identify the client calling a service.
By looking at the user agent Header.
By looking at the Origin IP.
Make the user add a unique identifier to the request.
If an Auth header is sent by the client, by looking at the Auth information(e.g: If an OAuth token is sent you can do an introspect call to the Token server to get user details etc.)
I have wso2 apim 2.1 and I have request to connect to SOAP endpoint which is secured with username and password.
During add procedure of SOAP endpoint I dont have possibility to enter such credentials nor possiblity to use mediation(eg like for rest api) as I get not authorized before enetring next phase. is there a way how to do this without using ESB ?
how to connect to secured SOAP backend using just apim ?
or Do I have to use ESB and follow similar way as LINK
thank you for any advice
We were not able to parse the backend wsdl from some reason and we have done workaround by donwloading wsdl and manualy pushing it to registry, after that we were able to follow next steps.
I am using WSO2 API Gateway to service API calls. The backend requires custom user attributes (username, e-mail, etc.) to be sent as part of the query string in the URL. The values for the query string pairs will be provided in the SAML2 token embedded in the API call.
How can a mediator access these custom SAML2 attributes?
You can create a custom mediator or custom handler to parse the saml token and set it to a header or something . see Writing Custom+Handlers for sample handler which reads a header .
I'm trying to publish the WSO2 Message Broker services using the WSO2 API Manager.
If I enter the Message Broker URL containing https:// in the Publisher and validate the endpoint, it returns 'Invalid'. I can save the API however. Specifying http:// results in a valid endpoint.
Using SoapUI to test the EventBrokerService gives a valid response (status 202) accessing the Message Broker directly. Via the API Manager I get a soap:Fault:
<soapenv:Fault>
<faultcode xmlns:axis2ns6="http://schemas.xmlsoap.org/soap/envelope/">axis2ns6:Server</faultcode>
<faultstring>Error in Sender</faultstring>
</soapenv:Fault>
Any pointers?
This seems to be a hostname verification failure. So when you publish an API through API Manager you need to set the HostnameVerifier parameter in
<APIM_HOME>/repository/conf/axis2/axis2.xml.
<parameter name="HostnameVerifier">AllowAll</parameter>
Please refer https://docs.wso2.org/display/AM140/Creating+an+API for more information.
I am using wso2 ESB to secure my service. service is available through wsdl, and this service is insecured. My scenario is as follows: A system expose some apis or services, and they are insecured. I want to create proxy services to these services. If client invokes the proxy service, ESB should first check if the request contains the session ID, if yes, client can invoke the backend service. if no, client is redirect to a log in page. I think ESB can do this by adding a session ID or user ID header to the request, but I am lack of docs. can someone help?
and I have read [1], and conclude ESB will meet my demand.
[1] http://www.ws02.net/library/knowledge-base/convert-http-basic-authentication-ws-security-username-token/
I think you are expecting a custom header field from user request. Since you are creating proxies with the associated WSDL, you can add SOAP Header requirement in your wsdl and associate that WSDL to the proxy (using publishWSDL option). So, when user send request to your proxy he might need to add that particular header.
Other routing logic you can handle within proxy configuration