From 15a14d2cfe0c49ed470f6678456a164dffe3ef06 Mon Sep 17 00:00:00 2001 From: Prasanna Dangalla Date: Tue, 31 Jan 2023 17:52:25 +0530 Subject: [PATCH] Fixed issue - Request always directed to production endpoint when using API Key Only. --- .../v1/common/template/APIConfigContext.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/template/APIConfigContext.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/template/APIConfigContext.java index e72daf72573f..c2de31b11dc2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/template/APIConfigContext.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/template/APIConfigContext.java @@ -86,6 +86,18 @@ private void setApiVelocityContext(API api, VelocityContext context) { } else { context.put("apiIsOauthProtected", Boolean.FALSE); } + //if API is secured with api_Key + if (apiSecurity != null && apiSecurity.contains(APIConstants.API_SECURITY_API_KEY)) { + context.put("apiIsApiKeyProtected", Boolean.TRUE); + } else { + context.put("apiIsApiKeyProtected", Boolean.FALSE); + } + //if API is secured with basic_auth + if (apiSecurity != null && apiSecurity.contains(APIConstants.API_SECURITY_BASIC_AUTH)) { + context.put("apiIsBasicAuthProtected", Boolean.TRUE); + } else { + context.put("apiIsBasicAuthProtected", Boolean.FALSE); + } if (api.isEnabledSchemaValidation()) { context.put("enableSchemaValidation", Boolean.TRUE); } else {