From 9e2210514ad0b54b1f66832241e4c1dcf224c90f Mon Sep 17 00:00:00 2001 From: BLasan Date: Tue, 26 Mar 2024 17:13:46 +0530 Subject: [PATCH] fixes: https://github.com/wso2/api-manager/issues/2663 --- .../main/java/org/wso2/carbon/apimgt/impl/APIConstants.java | 1 + .../publisher/v1/impl/OperationPoliciesApiServiceImpl.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java index 0c72139c244c..caf07552d5e1 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java @@ -3102,6 +3102,7 @@ public enum ConfigType { public static final String SYNAPSE_POLICY_DEFINITION_EXTENSION_XML = ".xml"; public static final String CC_POLICY_DEFINITION_EXTENSION = ".gotmpl"; public static final String YAML_CONTENT_TYPE = "yaml"; + public static final String J2_CONTENT_TYPE = "j2"; public static final String COMMON_OPERATION_POLICY_SPECIFICATIONS_LOCATION = "repository" + File.separator + "resources" + File.separator + "operation_policies" + File.separator + "specifications"; public static final String COMMON_OPERATION_POLICY_DEFINITIONS_LOCATION = "repository" + File.separator diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/OperationPoliciesApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/OperationPoliciesApiServiceImpl.java index 5f07203c071b..d8838bfc53c2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/OperationPoliciesApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/OperationPoliciesApiServiceImpl.java @@ -98,6 +98,12 @@ public Response addCommonOperationPolicy(InputStream policySpecFileInputStream, if (org.apache.commons.lang3.StringUtils.isBlank(fileContentType)) { fileContentType = policySpecFileDetail.getContentType().toString(); } + + if (!(APIConstants.YAML_CONTENT_TYPE.equals(fileContentType) || APIConstants.J2_CONTENT_TYPE.equals( + fileContentType))) { + throw new APIManagementException("Unsupported file type for Operation Policy"); + } + if (APIConstants.YAML_CONTENT_TYPE.equals(fileContentType)) { jsonContent = CommonUtil.yamlToJson(jsonContent); }