将自定义处理程序添加到特定 API wso2 API-Manager [英] Adding custom handler to specific API wso2 API-Manager
问题描述
我需要将自定义处理程序和 APIAuthenticationHandler 添加到特定 API,并且需要将其添加到
I need to add a custom handler and APIAuthenticationHandler to a specific API and it needs to be added below the
handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
(注意这里APIAuthenticationHandler被调用了两次,是自定义要求)
(Note that APIAuthenticationHandler is called twice here, it's a custom requirement)
如何通过编辑velocity_template.xml 以编程方式执行此操作
How can I do this programmatically by editing the velocity_template.xml
我使用的是 API-Manager 2.00
I'm using API-Manager 2.00
谢谢
推荐答案
您可以使用 API 自定义属性.向 API 添加自定义属性(例如 auth_mode=Inhouse
),然后基于此更新速度模板中的处理程序部分,如下所示.
You can use API custom properties for this. Add a custom property (e.g. auth_mode=Inhouse
) to the API and then based on that, update the handler section in the velocity template like this.
<Handlers>
#foreach($handler in $handlers)
#if(($handler.className ==
"org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler") &&
($apiObj.additionalProperties.get('auth_mode') == "Inhouse"))
<handler xmlns="http://ws.apache.org/ns/synapse" class="$handler.className">
#if($handler.hasProperties())
#set ($map = $handler.getProperties())
#foreach($property in $map.entrySet())
<property name="$!property.key" value="$!property.value"/>
#end
#end
</handler>
<handler class="org.wso2.apim.custom.extensions.CustomAuthHandler"/>
<Handlers>
如果您不能使用自定义属性,您可以使用 $!apiName
变量.
If you can't use custom properties, you can use $!apiName
variable.
这篇关于将自定义处理程序添加到特定 API wso2 API-Manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!