I wrote a custom authentication handler based on the instructions in the user guide.
I placed my jar /repository/components/lib and tried to add it to a specific API from admin console -> Service bus -> Service view, but received class not found error in the log.
The only way I was able to make it work was a workaround of "pushing" it to one of WSO2's deployment jars (org.wso2.carbon.apimgt.gateway_5.0.3.jar). When added to this jar and re-starting WSo2, I got the handler working all right.
But I guess this workaround is not the proper way to do it... Is this a CLASSPATH issue or something that I'm missing in the process to make it work?
After further checking, turns out my JAR had been corrupted for some reason. I built it again and it works now.
For the benefit of anyone from the community who attempt to try this, I'll post the steps I did (working with APIM 1.10.0)
1) The JAR file:
$ cd /home/olahav/wso2/wso2am-1.10.0/repository/components/lib
$ jar tf extensions.jar
...
org/wso2/carbon/test/OferAPIAuthenticationHandler_1.class
2) The API template:
<handlers xmlns="http://ws.apache.org/ns/synapse">
<handler class="org.wso2.carbon.test.OferAPIAuthenticationHandler_1"/>
#foreach($handler in $handlers)
<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>
#end
</handlers>
3) Since this is a template, need to re-create the API. Then checking in the service view (via https://localhost:9443/carbon ) you can see the handler added to the list of handlers:
<handlers>
<handler class="org.wso2.carbon.test.OferAPIAuthenticationHandler_1"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
<property name="id" value="A"/>
<property name="policyKeyResource" value="gov:/apimgt/applicationdata/res-tiers.xml"/>
<property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
<property name="policyKeyApplication" value="gov:/apimgt/applicationdata/app-tiers.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
<property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
</handlers>
That's it!
Thanks for anyone who helped me through.
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.