[英]Adding custom handler to specific API wso2 API-Manager
I need to add a custom handler and APIAuthenticationHandler to a specific API and it needs to be added below the 我需要将一个自定义处理程序和APIAuthenticationHandler添加到特定的API,它需要添加到下面
handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/> handler class =“org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler”/>
(Note that APIAuthenticationHandler is called twice here, it's a custom requirement) (注意,APIAuthenticationHandler在这里被调用两次,这是一个自定义要求)
How can I do this programmatically by editing the velocity_template.xml 如何通过编辑velocity_template.xml以编程方式执行此操作
I'm using API-Manager 2.00 我正在使用API-Manager 2.00
Thank you 谢谢
You can use API custom properties for this. 您可以为此使用API自定义属性 。 Add a custom property (eg auth_mode=Inhouse
) to the API and then based on that, update the handler section in the velocity template like this. 将自定义属性(例如auth_mode=Inhouse
)添加到API,然后基于此,更新速度模板中的处理程序部分,如下所示。
<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>
If you can't use custom properties, you can use $!apiName
variable. 如果您不能使用自定义属性,则可以使用$!apiName
变量。
if($!apiName.toLowerCase()。endsWith(“basic”))#else
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.