繁体   English   中英

将自定义处理程序添加到特定API wso2 API-Manager

[英]Adding custom handler to specific API wso2 API-Manager

我需要将一个自定义处理程序和APIAuthenticationHandler添加到特定的API,它需要添加到下面

handler class =“org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler”/>

(注意,APIAuthenticationHandler在这里被调用两次,这是一个自定义要求)

如何通过编辑velocity_template.xml以编程方式执行此操作

我正在使用API​​-Manager 2.00

谢谢

您可以为此使用API自定义属性 将自定义属性(例如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>

如果您不能使用自定义属性,则可以使用$!apiName变量。

if($!apiName.toLowerCase()。endsWith(“basic”))#else

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM