How to set tenant to header in mediator with WSO2 API Manager

余生颓废 提交于 2019-12-05 05:13:29
Marcos Sánchez

After checking the debug output from ApiManager, I noticed that custom sequences are being executed right after handlers. Luckily, the OAuthAuthenticator class (used by APIAuthenticationHandler) sets some handy properties like END_USER_NAME and APPLICATION_NAME.

END_USER_NAME contains the name and tenant of the caller (user@tenant.com).

This custom sequence worked for me:

<sequence name="add_service_header" trace="enable" statistics="enable" xmlns="http://ws.apache.org/ns/synapse">
    <log/>
    <property name="tenant" expression="fn:substring-after(get-property('END_USER_NAME'), '@')" />
    <header name="X-Tenant" scope="transport" expression="get-property('tenant')"/>
    <header name="X-AppName" scope="transport" expression="get-property('APPLICATION_NAME')"/>
</sequence>

I could not find documentation for the property other than source code and this other question

As the code suggests these are set to synapse MessageContext. You can retrieve these properties using following expressions.

get-property('tenant.info.domain')

get-property('tenant.info.id')

Thanks

Tishan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!