简体   繁体   中英

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

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

(Note that APIAuthenticationHandler is called twice here, it's a custom requirement)

How can I do this programmatically by editing the velocity_template.xml

I'm using API-Manager 2.00

Thank you

You can use API custom properties for this. 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.

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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