Adding custom handler to specific API wso2 API-Manager

旧时模样 提交于 2019-12-05 19:47:00

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>

If you can't use custom properties, you can use $!apiName variable.

if ($!apiName.toLowerCase().endsWith("basic")) #else

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